#include<bits/stdc++.h>
using namespace std;
long long  a[4005],b[4005];
int main ()
{
    int n;
    cin>>n;
    int arr[n][n];
    for(int i=0  ;i<n ; i++)
    {
        for(int j=0 ;j<n ; j++)
        {
            int x;
            cin>>x;

            a[i+j]+=x;
            b[i-j+n]+=x;
            arr[i][j]=x;

        }
    }
    vector<pair<long long , pair<int ,int > > >v;
    for(int i =0 ; i<n*2 ; i++)
    {
        for(int j=0 ; j<n*2 ; j++)
        {
            if (a[i]==0 || b[j]==0)continue;
            long long q=i,r=j-n;
            int x=(q+r)/2;
            int y=q-x;
           // cout<<x<<" "<<y<<endl;
            long long sum=a[i]+b[j]-arr[x][y];
            if ((q+r)%2!=0|| x<0 || y<0 || x>=n || y>=n )continue;
            //if (sum==8)cout<<x<<" "<<y<<endl;
            v.push_back({sum,{x,y}});

        }
    }
    long long Max=0;
    int maxx,maxy,maxx2,maxy2;
    for(int i=0 ; i<v.size() ; i++)
    {
        for(int j=0 ; j<v.size() ; j++)
        {
            long long sum=v[i].first+v[j].first;
            int x1=v[i].second.first;
            int y1=v[i].second.second;
            int x2=v[j].second.first;
            int y2=v[j].second.second;
            if (x1+y1==x2+y2 || x1-y1==x2-y2)continue;
            if (sum>Max)
            {
         //   cout<<v[i].first<<" "<<v[j].first<<endl;

                //cout<<sum<<" "<<x1+1<<" "<<y1+1<<endl;
                Max=sum;
                maxx=x1+1;
                maxy=y1+1;
                maxx2=x2+1;
                maxy2=y2+1;
            }

        }
    }
    cout<<Max<<endl<<maxx<<" "<<maxy<<" "<<maxx2<<" "<<maxy2;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long  a[4005],b[4005];
int main ()
{
    int n;
    cin>>n;
    int arr[n][n];
    for(int i=0  ;i<n ; i++)
    {
        for(int j=0 ;j<n ; j++)
        {
            int x;
            cin>>x;

            a[i+j]+=x;
            b[i-j+n]+=x;
            arr[i][j]=x;

        }
    }
    vector<pair<long long , pair<int ,int > > >v;
    for(int i =0 ; i<n*2 ; i++)
    {
        for(int j=0 ; j<n*2 ; j++)
        {
            if (i%2!=((j-n)%2+2)%2 || i==abs(j-n))continue;
           // cout<<i<<" "<<j<<endl;
            if (a[i]==0 || b[j]==0)continue;
            long long q=i,r=j-n;
            int x=(q+r)/2;
            int y=q-x;
           // cout<<x<<" "<<y<<endl;
            long long sum=a[i]+b[j]-arr[x][y];
            if ((q+r)%2!=0|| x<0 || y<0 || x>=n || y>=n )continue;
            //if (sum==8)cout<<x<<" "<<y<<endl;
            v.push_back({sum,{x,y}});

        }
    }
    long long Max=0;
    int maxx,maxy,maxx2,maxy2;
    for(int i=0 ; i<v.size() ; i++)
    {
        for(int j=0 ; j<v.size() ; j++)
        {
            long long sum=v[i].first+v[j].first;
            int x1=v[i].second.first;
            int y1=v[i].second.second;
            int x2=v[j].second.first;
            int y2=v[j].second.second;
            if (x1+y1==x2+y2 || x1-y1==x2-y2 )continue;
            if (sum>Max)
            {
         //   cout<<v[i].first<<" "<<v[j].first<<endl;

                //cout<<sum<<" "<<x1+1<<" "<<y1+1<<endl;
                Max=sum;
                maxx=x1+1;
                maxy=y1+1;
                maxx2=x2+1;
                maxy2=y2+1;
            }

        }
    }
    cout<<Max<<endl<<maxx<<" "<<maxy<<" "<<maxx2<<" "<<maxy2;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long  a[4005],b[4005];
int main ()
{
    int n;
    cin>>n;
    int arr[n][n];
    for(int i=0  ;i<n ; i++)
    {
        for(int j=0 ;j<n ; j++)
        {
            int x;
            cin>>x;

            a[i+j]+=x;
            b[i-j+n]+=x;
            arr[i][j]=x;

        }
    }
    vector<pair<int,int> > ij;
    vector<pair<long long , pair<int ,int > > >v;
    for(int i =0 ; i<n*2 ; i++)
    {
        for(int j=0 ; j<n*2 ; j++)
        {
           // cout<<i<<" "<<j<<endl;
            if (a[i]==0 || b[j]==0)continue;
            long long q=i,r=j-n;
            int x=(q+r)/2;
            int y=q-x;
           // if (x==1&& y==1)cout<<i<<" "<<j-n<<endl;

           // cout<<x<<" "<<y<<endl;
            long long sum=a[i]+b[j]-arr[x][y];
            if ((q+r)%2!=0|| x<0 || y<0 || x>=n || y>=n )continue;
            //if (sum==8)cout<<x<<" "<<y<<endl;
            v.push_back({sum,{x,y}});
            ij.push_back({i,j});

        }
    }
    long long Max=0;
    int maxx,maxy,maxx2,maxy2;
    for(int i=0 ; i<v.size() ; i++)
    {
        for(int j=0 ; j<v.size() ; j++)
        {
            long long sum=v[i].first+v[j].first;
            int x1=v[i].second.first;
            int y1=v[i].second.second;
            int x2=v[j].second.first;
            int y2=v[j].second.second;
            int ii1=ij[i].first,ii2=ij[j].first,jj1=ij[i].second,jj2=ij[j].second;

            if (ii1%2==((jj2-n)%2+2)%2)continue;
             if (ii2%2==((jj1-n)%2+2)%2)continue;

            if (x1+y1==x2+y2 || x1-y1==x2-y2 )continue;
            if (sum>Max)
            {
         //   cout<<v[i].first<<" "<<v[j].first<<endl;

                //cout<<sum<<" "<<x1+1<<" "<<y1+1<<endl;
                Max=sum;
                maxx=x1+1;
                maxy=y1+1;
                maxx2=x2+1;
                maxy2=y2+1;
            }

        }
    }
    cout<<Max<<endl<<maxx<<" "<<maxy<<" "<<maxx2<<" "<<maxy2;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long  a[4005],b[4005];
int main ()
{
    int n;
    cin>>n;
    int arr[n][n];
    for(int i=0  ;i<n ; i++)
    {
        for(int j=0 ;j<n ; j++)
        {
            int x;
            cin>>x;

            a[i+j]+=x;
            b[i-j+n]+=x;
            arr[i][j]=x;

        }
    }
    vector<pair<long long , pair<int ,int > > >v;
    for(int i =0 ; i<n*n ; i++)
    {
        for(int j=0 ; j<n*n ; j++)
        {
            if (a[i]==0 || b[j]==0)continue;
            long long q=i,r=j-n;
            int x=(q+r)/2;
            int y=q-x;
           // cout<<x<<" "<<y<<endl;
            long long sum=a[i]+b[j]-arr[x][y];
            if ((q+r)%2!=0|| x<0 || y<0 || x>=n || y>=n )continue;
            //if (sum==8)cout<<x<<" "<<y<<endl;
            v.push_back({sum,{x,y}});

        }
    }
    long long Max=0;
    int maxx,maxy,maxx2,maxy2;
    for(int i=0 ; i<v.size() ; i++)
    {
        for(int j=0 ; j<v.size() ; j++)
        {
            long long sum=v[i].first+v[j].first;
            int x1=v[i].second.first;
            int y1=v[i].second.second;
            int x2=v[j].second.first;
            int y2=v[j].second.second;
            if (x1+y1==x2+y2 || x1-y1==x2-y2)continue;
            if (sum>Max)
            {
         //   cout<<v[i].first<<" "<<v[j].first<<endl;

                //cout<<sum<<" "<<x1+1<<" "<<y1+1<<endl;
                Max=sum;
                maxx=x1+1;
                maxy=y1+1;
                maxx2=x2+1;
                maxy2=y2+1;
            }

        }
    }
    cout<<Max<<endl<<maxx<<" "<<maxy<<" "<<maxx2<<" "<<maxy2;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long  a[4005],b[4005];
int main ()
{
    int n;
    cin>>n;
    int arr[n][n];
    for(int i=0  ; i<n ; i++)
    {
        for(int j=0 ; j<n ; j++)
        {
            int x;
            scanf("%d",&x);

            a[i+j]+=x;
            b[i-j+n]+=x;
            arr[i][j]=x;

        }
    }
    vector<pair<int,int> > ij;
    vector<pair<long long, pair<int,int > > >v;
    long long oo=-1,ee=-1,oe=-1,eo=-1;
            int eex,eey,oex,oey,oox,ooy,eox,eoy;
    for(int i =0 ; i<n*2 ; i++)
    {
        for(int j=0 ; j<n*2 ; j++)
        {
            // cout<<i<<" "<<j<<endl;
          // if (a[i]==0 || b[j]==0)continue;
            long long q=i,r=j-n;
            int x=(q+r)/2;
            int y=q-x;
            // if (x==1&& y==1)cout<<i<<" "<<j-n<<endl;

            // cout<<x<<" "<<y<<endl;
            if ((q+r)%2!=0|| x<0 || y<0 || x>=n || y>=n )continue;
            long long sum=a[i]+b[j]-arr[x][y];
            //if (sum==8)cout<<x<<" "<<y<<endl;

            int aa=i%2;
            int bb=((j-n)%2+2)%2;
            if (aa==0 && bb==0)
            {
                if (sum>ee)
                {
                    ee=sum;
                    eex=x+1;
                    eey=y+1;
                }

            }
            else if (aa && bb)
            {
                if (sum>oo)
                {
                    oo=sum;
                    oox=x+1;
                    ooy=y+1;
                }
            }
            else if (aa==1 && bb ==0)
            {
                if (sum>oe)
                {
                    oe=sum;
                    oex=x+1;
                    oey=y+1;
                }
            }
            else
            {
                if (sum>eo)
                {
                    eo=sum;
                    eox=x+1;
                    eoy=y+1;
                }
            }

        }
    }

    if (eo+oe>ee+oo)
    {
        cout<<eo+oe<<endl;
        cout<<eox<<" "<<eoy<<" "<<oex<<" "<<oey;
    }
    else
    {
        cout<<ee+oo<<endl;
        cout<<oox<<" "<<ooy<<" "<<eex<<" "<<eey;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long  a[4005],b[4005];
int main ()
{
    int n;
    cin>>n;
    int arr[n][n];
    for(int i=0  ;i<n ; i++)
    {
        for(int j=0 ;j<n ; j++)
        {
            int x;
            cin>>x;

            a[i+j]+=x;
            b[i-j+n]+=x;
            arr[i][j]=x;

        }
    }
    vector<pair<long long , pair<int ,int > > >v;
    for(int i =0 ; i<n*2 ; i++)
    {
        for(int j=0 ; j<n*2 ; j++)
        {
            if (i%2!=((j-n)%2+2)%2 || i==abs(j-n))continue;
            cout<<i<<" "<<j<<endl;
            if (a[i]==0 || b[j]==0)continue;
            long long q=i,r=j-n;
            int x=(q+r)/2;
            int y=q-x;
           // cout<<x<<" "<<y<<endl;
            long long sum=a[i]+b[j]-arr[x][y];
            if ((q+r)%2!=0|| x<0 || y<0 || x>=n || y>=n )continue;
            //if (sum==8)cout<<x<<" "<<y<<endl;
            v.push_back({sum,{x,y}});

        }
    }
    long long Max=0;
    int maxx,maxy,maxx2,maxy2;
    for(int i=0 ; i<v.size() ; i++)
    {
        for(int j=0 ; j<v.size() ; j++)
        {
            long long sum=v[i].first+v[j].first;
            int x1=v[i].second.first;
            int y1=v[i].second.second;
            int x2=v[j].second.first;
            int y2=v[j].second.second;
            if (x1+y1==x2+y2 || x1-y1==x2-y2 )continue;
            if (sum>Max)
            {
         //   cout<<v[i].first<<" "<<v[j].first<<endl;

                //cout<<sum<<" "<<x1+1<<" "<<y1+1<<endl;
                Max=sum;
                maxx=x1+1;
                maxy=y1+1;
                maxx2=x2+1;
                maxy2=y2+1;
            }

        }
    }
    cout<<Max<<endl<<maxx<<" "<<maxy<<" "<<maxx2<<" "<<maxy2;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long  a[4005],b[4005];
int main ()
{
    int n;
    cin>>n;
    int arr[n][n];
    for(int i=0  ;i<n ; i++)
    {
        for(int j=0 ;j<n ; j++)
        {
            int x;
            cin>>x;

            a[i+j]+=x;
            b[i-j+n]+=x;
            arr[i][j]=x;

        }
    }
    vector<pair<long long , pair<int ,int > > >v;
    for(int i =0 ; i<n*2 ; i++)
    {
        for(int j=0 ; j<n*2 ; j++)
        {
            if (i%2!=((j-n)%2+2)%2)continue;
            if (a[i]==0 || b[j]==0)continue;
            long long q=i,r=j-n;
            int x=(q+r)/2;
            int y=q-x;
           // cout<<x<<" "<<y<<endl;
            long long sum=a[i]+b[j]-arr[x][y];
            if ((q+r)%2!=0|| x<0 || y<0 || x>=n || y>=n )continue;
            //if (sum==8)cout<<x<<" "<<y<<endl;
            v.push_back({sum,{x,y}});

        }
    }
    long long Max=0;
    int maxx,maxy,maxx2,maxy2;
    for(int i=0 ; i<v.size() ; i++)
    {
        for(int j=0 ; j<v.size() ; j++)
        {
            long long sum=v[i].first+v[j].first;
            int x1=v[i].second.first;
            int y1=v[i].second.second;
            int x2=v[j].second.first;
            int y2=v[j].second.second;
            if (x1+y1==x2+y2 || x1-y1==x2-y2)continue;
            if (sum>Max)
            {
         //   cout<<v[i].first<<" "<<v[j].first<<endl;

                //cout<<sum<<" "<<x1+1<<" "<<y1+1<<endl;
                Max=sum;
                maxx=x1+1;
                maxy=y1+1;
                maxx2=x2+1;
                maxy2=y2+1;
            }

        }
    }
    cout<<Max<<endl<<maxx<<" "<<maxy<<" "<<maxx2<<" "<<maxy2;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long  a[4005],b[4005];
int main ()
{
    int n;
    cin>>n;
    int arr[n][n];
    for(int i=0  ; i<n ; i++)
    {
        for(int j=0 ; j<n ; j++)
        {
            int x;
            scanf("%d",&x);

            a[i+j]+=x;
            b[i-j+n]+=x;
            arr[i][j]=x;

        }
    }
    vector<pair<int,int> > ij;
    vector<pair<long long, pair<int,int > > >v;
    long long oo=0,ee=0,oe=0,eo=0;
            int eex,eey,oex,oey,oox,ooy,eox,eoy;
    for(int i =0 ; i<n*2 ; i++)
    {
        for(int j=0 ; j<n*2 ; j++)
        {
            // cout<<i<<" "<<j<<endl;
          // if (a[i]==0 || b[j]==0)continue;
            long long q=i,r=j-n;
            int x=(q+r)/2;
            int y=q-x;
            // if (x==1&& y==1)cout<<i<<" "<<j-n<<endl;

            // cout<<x<<" "<<y<<endl;
            if ((q+r)%2!=0|| x<0 || y<0 || x>=n || y>=n )continue;
            long long sum=a[i]+b[j]-arr[x][y];
            //if (sum==8)cout<<x<<" "<<y<<endl;
            v.push_back({sum,{x,y}});
            int aa=i%2;
            int bb=((j-n)%2+2)%2;
            if (aa==0 && bb==0)
            {
                if (sum>ee)
                {
                    ee=sum;
                    eex=x+1;
                    eey=y+1;
                }

            }
            else if (aa && bb)
            {
                if (sum>oo)
                {
                    oo=sum;
                    oox=x+1;
                    ooy=y+1;
                }
            }
            else if (aa==1 && bb ==0)
            {
                if (sum>oe)
                {
                    oe=sum;
                    oex=x+1;
                    oey=y+1;
                }
            }
            else
            {
                if (sum>eo)
                {
                    eo=sum;
                    eox=x+1;
                    eoy=y+1;
                }
            }

        }
    }

    if (eo+oe>ee+oo)
    {
        cout<<eo+oe<<endl;
        cout<<eox<<" "<<eoy<<" "<<oex<<" "<<oey;
    }
    else
    {
        cout<<ee+oo<<endl;
        cout<<oox<<" "<<ooy<<" "<<eex<<" "<<eey;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long  a[4005],b[4005];
int main ()
{
    int n;
    cin>>n;
    int arr[n][n];
    for(int i=0  ; i<n ; i++)
    {
        for(int j=0 ; j<n ; j++)
        {
            int x;
            scanf("%d",&x);

            a[i+j]+=x;
            b[i-j+n]+=x;
            arr[i][j]=x;

        }
    }
    vector<pair<int,int> > ij;
    vector<pair<long long, pair<int,int > > >v;
    long long oo=0,ee=0,oe=0,eo=0;
            int eex,eey,oex,oey,oox,ooy,eox,eoy;
    for(int i =0 ; i<n*2 ; i++)
    {
        for(int j=0 ; j<n*2 ; j++)
        {
            // cout<<i<<" "<<j<<endl;
          //  if (a[i]==0 || b[j]==0)continue;
            long long q=i,r=j-n;
            int x=(q+r)/2;
            int y=q-x;
            // if (x==1&& y==1)cout<<i<<" "<<j-n<<endl;

            // cout<<x<<" "<<y<<endl;
            long long sum=a[i]+b[j]-arr[x][y];
            if ((q+r)%2!=0|| x<0 || y<0 || x>=n || y>=n )continue;
            //if (sum==8)cout<<x<<" "<<y<<endl;
            v.push_back({sum,{x,y}});
            int aa=i%2;
            int bb=((j-n)%2+2)%2;
            if (aa==0 && bb==0)
            {
                if (sum>ee)
                {
                    ee=sum;
                    eex=x+1;
                    eey=y+1;
                }

            }
            else if (aa && bb)
            {
                if (sum>oo)
                {
                    oo=sum;
                    oox=x+1;
                    ooy=y+1;
                }
            }
            else if (aa==1 && bb ==0)
            {
                if (sum>oe)
                {
                    oe=sum;
                    oex=x+1;
                    oey=y+1;
                }
            }
            else
            {
                if (sum>eo)
                {
                    eo=sum;
                    eox=x+1;
                    eoy=y+1;
                }
            }

        }
    }

    if (eo+oe>ee+oo)
    {
        cout<<eo+oe<<endl;
        cout<<eox<<" "<<eoy<<" "<<oex<<" "<<oey;
    }
    else
    {
        cout<<ee+oo<<endl;
        cout<<oox<<" "<<ooy<<" "<<eex<<" "<<eey;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long  a[4005],b[4005];
int main ()
{
    int n;
    cin>>n;
    int arr[n][n];
    for(int i=0  ; i<n ; i++)
    {
        for(int j=0 ; j<n ; j++)
        {
            int x;
            scanf("%d",&x);

            a[i+j]+=x;
            b[i-j+n]+=x;
            arr[i][j]=x;

        }
    }
    vector<pair<int,int> > ij;
    vector<pair<long long, pair<int,int > > >v;
    long long oo=0,ee=0,oe=0,eo=0;
            int eex,eey,oex,oey,oox,ooy,eox,eoy;
    for(int i =0 ; i<n*2 ; i++)
    {
        for(int j=0 ; j<n*2 ; j++)
        {
            // cout<<i<<" "<<j<<endl;
            if (a[i]==0 || b[j]==0)continue;
            long long q=i,r=j-n;
            int x=(q+r)/2;
            int y=q-x;
            // if (x==1&& y==1)cout<<i<<" "<<j-n<<endl;

            // cout<<x<<" "<<y<<endl;
            long long sum=a[i]+b[j]-arr[x][y];
            if ((q+r)%2!=0|| x<0 || y<0 || x>=n || y>=n )continue;
            //if (sum==8)cout<<x<<" "<<y<<endl;
            v.push_back({sum,{x,y}});
            int aa=i%2;
            int bb=((j-n)%2+2)%2;
            if (aa==0 && bb==0)
            {
                if (sum>ee)
                {
                    ee=sum;
                    eex=x+1;
                    eey=y+1;
                }

            }
            else if (aa && bb)
            {
                if (sum>oo)
                {
                    oo=sum;
                    oox=x+1;
                    ooy=y+1;
                }
            }
            else if (aa==1 && bb ==0)
            {
                if (sum>oe)
                {
                    oe=sum;
                    oex=x+1;
                    oey=y+1;
                }
            }
            else
            {
                if (sum>eo)
                {
                    eo=sum;
                    eox=x+1;
                    eoy=y+1;
                }
            }

        }
    }

    if (eo+oe>ee+oo)
    {
        cout<<eo+oe<<endl;
        cout<<eox<<" "<<eoy<<" "<<oex<<" "<<oey;
    }
    else
    {
        cout<<ee+oo<<endl;
        cout<<oox<<" "<<ooy<<" "<<eex<<" "<<eey;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define f(i,a,b) for(long long int i = (a); i < (b); i++)
#define fd(i,a,b) for(long long int i = (a); i >= (b); i--)

typedef pair<int,int>   ii;
typedef vector< ii >    vii;
typedef vector<int>     vi;
typedef vector< vi >    vvi;
typedef long long int   ll;

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define set(a,b) memset(a,b,sizeof(a))
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)

#define nscan(n) scanf("%d",&n)
#define nscan2(n,m) scanf("%d%d",&n,&m)
#define nprint(n) printf("%d\n",n)
#define scan(n) scanf("%Ld",&n)
#define scan2(n,m) scanf("%Ld%Ld",&n,&m)
#define print(n) printf("%Ld\n",n)
#define print2(n,m) printf("%Ld %Ld\n",n,m)
#define strin(s) scanf("%s",s)
#define strout(n) printf("%s\n",n)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
        cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

ll arr[2010][2010], arr1[2010][2010],n=0,k=0,maxi=0,sum1[4010]={0},sum2[4010]={0},ans=0,mini=0;
int main()
{
  scan(n);
  f(i,0,n)
    f(j,0,n)
      scan(arr[i][j]);

// for upward going diagonals
  f(i,0,n)
  {
    ll pt=0;
    f(j,0,n)
    {
      sum1[i] += arr[i-pt][j];
      pt++;
      if(i-pt<0)
        break;
    }
  }
  f(i,0,n-1)
  {
    ll pt=1;
    f(j,i+1,n)
      {
        sum1[n+i] += arr[n-pt][j];
        pt++;
      }
  }

// for downward going diagonals
  f(i,0,n)
  {
    ll pt=0;
    f(j,0,n)
    {
      sum2[i] += arr[i+pt][j];
      pt++;
      if(i+pt>=n)
        break;
    }
  }
  f(i,0,n-1)
  {
    ll pt=0;
    f(j,i+1,n)
      {
        sum2[n+i] += arr[pt][j];
        pt++;
      }
  }

  f(i,0,n)
    f(j,0,n)
      arr1[i][j]=0;

  // adding both the diagonals
  f(i,0,n)
  {
    ll pt=0;
    f(j,0,n)
    {
      arr1[i-pt][j] = sum1[i];
      pt++;
      if(i-pt<0)
        break;
    }
  }
  f(i,0,n-1)
  {
    ll pt=1;
    f(j,i+1,n)
      {
        arr1[n-pt][j] = sum1[n+i];
        pt++;
      }
  }

  f(i,0,n)
  {
    ll pt=0;
    f(j,0,n)
    {
      arr1[i+pt][j] += sum2[i];
      pt++;
      if(i+pt>=n)
        break;
    }
  }
  f(i,0,n-1)
  {
    ll pt=0;
    f(j,i+1,n)
      {
        arr1[pt][j] += sum2[n+i];
        pt++;
      }
  }

  // f(i,0,n)
  // {
  //   f(j,0,n)
  //     cout<<arr[i][j]<<" ";
  //   cout<<endl;
  // }

  vector< pair<ll ,pair<ll,ll> > > m1,m2;
  f(i,0,n)
  {
    f(j,0,n)
      if(i%2==0)
      {
        if(j%2==0)
        {
          m1.pb(mp(arr1[i][j],mp(i,j)));
          // trace(arr[i][j],i,j);
        }
        else
          m2.pb(mp(arr1[i][j],mp(i,j)));
      }
      else
      {
        if(j%2==1)
        {
          m1.pb(mp(arr1[i][j],mp(i,j)));
          // trace(arr[i][j],i,j);
        }
        else
          m2.pb(mp(arr1[i][j],mp(i,j)));
      }

  }

  sort(m1.begin(),m1.end());
  reverse(m1.begin(),m1.end());
  sort(m2.begin(),m2.end());
  reverse(m2.begin(),m2.end());
  print(m1[0].F+m2[0].F-arr[m1[0].S.F][m1[0].S.S]-arr[m2[0].S.F][m2[0].S.S]);
  printf("%Ld %Ld %Ld %Ld\n",m1[0].S.F+1,m1[0].S.S+1,m2[0].S.F+1,m2[0].S.S+1);

  return 0;
}

/*
    Code written by
                ~Harshit Mahajan (ash0904)
                                  */


#include <bits/stdc++.h>

using namespace std;

#define f(i,a,b) for(long long int i = (a); i < (b); i++)
#define fd(i,a,b) for(long long int i = (a); i >= (b); i--)

typedef pair<int,int>   ii;
typedef vector< ii >    vii;
typedef vector<int>     vi;
typedef vector< vi >    vvi;
typedef long long int   ll;

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define set(a,b) memset(a,b,sizeof(a))
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)

#define nscan(n) scanf("%d",&n)
#define nscan2(n,m) scanf("%d%d",&n,&m)
#define nprint(n) printf("%d\n",n)
#define scan(n) scanf("%Ld",&n)
#define scan2(n,m) scanf("%Ld%Ld",&n,&m)
#define print(n) printf("%Ld\n",n)
#define print2(n,m) printf("%Ld %Ld\n",n,m)
#define strin(s) scanf("%s",s)
#define strout(n) printf("%s\n",n)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
        cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

ll arr[2010][2010],n=0,k=0,sum1[4010]={0},sum2[4010]={0},m1=0,m2=0,m3=0,m4=1,maxi=0,maxi1=0;
int main()
{
  cin>>n;
  f(i,0,n)
    f(j,0,n)
    {
      cin>>arr[i][j];
      sum1[i+j] +=arr[i][j];
      sum2[i+n-1-j] +=arr[i][j];
    }
  f(i,0,n)
    f(j,0,n)
    {
      if((i+j)%2 == 0)
        {
          if(maxi<sum1[i+j]+sum2[i+n-1-j]-arr[i][j])
          {
            maxi = sum1[i+j]+sum2[i+n-1-j]-arr[i][j];
            m1 = i; m2 = j;
          }
        }
      else
        {
          if(maxi1<sum1[i+j]+sum2[i+n-1-j]-arr[i][j])
          {
            maxi1 = sum1[i+j]+sum2[i+n-1-j]-arr[i][j];
            m3 = i; m4 = j;
          }
        }
    }
  cout<<maxi+maxi1<<endl;
  cout<<m1+1<<" "<<m2+1<<" "<<m3+1<<" "<<m4+1<<"\n";

// // for upward going diagonals
//   f(i,0,n)
//     f(j,0,i+1)
//       sum1[i] += arr[i-j][j];
//
//
//   f(i,0,n-1)
//   {
//     ll pt=1;
//     f(j,i+1,n)
//       {
//         sum1[n+i] += arr[n-pt][j];
//         pt++;
//       }
//   }
//
// // for downward going diagonals
//   f(i,0,n)
//     f(j,0,n)
//     {
//       if(i+j>=n)
//         break;
//       sum2[i] += arr[i+j][j];
//     }
//
//   f(i,0,n-1)
//   {
//     ll pt=0;
//     f(j,i+1,n)
//       {
//         sum2[n+i] += arr[pt][j];
//         pt++;
//       }
//   }
//
//   f(i,0,n)
//     f(j,0,n)
//       arr1[i][j]=0;
//
//   // adding upward the diagonals
//   f(i,0,n)
//     f(j,0,i+1)
//       arr1[i-j][j] = sum1[i];
//
//     f(i,0,n-1)
//     {
//       ll pt=1;
//       f(j,i+1,n)
//         {
//           arr1[n-pt][j] = sum1[n+i];
//           pt++;
//         }
//     }
//
//   // adding downward diagonals
//   f(i,0,n)
//     f(j,0,n)
//     {
//       if(i+j>=n)
//         break;
//       arr1[i+j][j] += sum2[i];
//     }
//
//   f(i,0,n-1)
//   {
//     ll pt=0;
//     f(j,i+1,n)
//       {
//         arr1[pt][j] += sum2[n+i];
//         pt++;
//       }
//   }
//
//   ll mx=0,my=0,m2x=0,m2y=1;
//   f(i,0,n)
//     f(j,0,n)
//       if((i+j)%2==0)
//       {if(arr1[mx][my]<=arr1[i][j])
//           {mx=i; my=j;}
//       }
//       else
//       {
//         // trace(i,j);
//         if(arr1[m2x][m2y]<=arr1[i][j])
//           {m2x=i; m2y=j;}
//       }
//   cout<<arr1[mx][my]+arr1[m2x][m2y]-arr[mx][my]-arr[m2x][m2y]<<endl;
//   cout<<mx+1<<" "<<my+1<<" "<<m2x+1<<" "<<m2y+1<<endl;

  // f(i,0,n)
  // {
  //   f(j,0,n)
  //     cout<<arr[i][j]<<" ";
  //   cout<<endl;
  // }

  // vector< pair<ll ,pair<ll,ll> > > m1,m2;
  // f(i,0,n)
  // {
  //   f(j,0,n)
  //     if(i%2==0)
  //     {
  //       if(j%2==0)
  //       {
  //         m1.pb(mp(arr1[i][j],mp(i,j)));
  //         // trace(arr[i][j],i,j);
  //       }
  //       else
  //         m2.pb(mp(arr1[i][j],mp(i,j)));
  //     }
  //     else
  //     {
  //       if(j%2==1)
  //       {
  //         m1.pb(mp(arr1[i][j],mp(i,j)));
  //         // trace(arr[i][j],i,j);
  //       }
  //       else
  //         m2.pb(mp(arr1[i][j],mp(i,j)));
  //     }
  //
  // }
  //
  // sort(m1.begin(),m1.end());
  // reverse(m1.begin(),m1.end());
  // sort(m2.begin(),m2.end());
  // reverse(m2.begin(),m2.end());
  // cout<<m1[0].F+m2[0].F-arr[m1[0].S.F][m1[0].S.S]-arr[m2[0].S.F][m2[0].S.S]<<"\n";
  // cout<<m1[0].S.F+1<<" "<<m1[0].S.S+1<<" "<<m2[0].S.F+1<<" "<<m2[0].S.S+1<<"\n";

  return 0;
}

/*
    Code written by
                ~Harshit Mahajan (ash0904)
                                  */


#include <bits/stdc++.h>

using namespace std;

#define f(i,a,b) for(long long int i = (a); i < (b); i++)
#define fd(i,a,b) for(long long int i = (a); i >= (b); i--)

typedef pair<int,int>   ii;
typedef vector< ii >    vii;
typedef vector<int>     vi;
typedef vector< vi >    vvi;
typedef long long int   ll;

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define set(a,b) memset(a,b,sizeof(a))
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)

#define nscan(n) scanf("%d",&n)
#define nscan2(n,m) scanf("%d%d",&n,&m)
#define nprint(n) printf("%d\n",n)
#define scan(n) scanf("%Ld",&n)
#define scan2(n,m) scanf("%Ld%Ld",&n,&m)
#define print(n) printf("%Ld\n",n)
#define print2(n,m) printf("%Ld %Ld\n",n,m)
#define strin(s) scanf("%s",s)
#define strout(n) printf("%s\n",n)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
        cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

ll arr[2010][2010], arr1[2010][2010],n=0,k=0,maxi=0,sum1[4010]={0},sum2[4010]={0},ans=0,mini=0;
int main()
{
  cin>>n;
  f(i,0,n)
    f(j,0,n)
      cin>>arr[i][j];

// for upward going diagonals
  f(i,0,n)
    f(j,0,i+1)
      sum1[i] += arr[i-j][j];

  f(i,0,n-1)
  {
    ll pt=1;
    f(j,i+1,n)
      {
        sum1[n+i] += arr[n-pt][j];
        pt++;
      }
  }

// for downward going diagonals
  f(i,0,n)
    f(j,0,n)
    {
      sum2[i] += arr[i+j][j];
      if(i+j>=n)
        break;
    }

  f(i,0,n-1)
  {
    ll pt=0;
    f(j,i+1,n)
      {
        sum2[n+i] += arr[pt][j];
        pt++;
      }
  }

  f(i,0,n)
    f(j,0,n)
      arr1[i][j]=0;

  // adding upward the diagonals
  f(i,0,n)
    f(j,0,i+1)
      arr1[i-j][j] = sum1[i]  ;

    f(i,0,n-1)
    {
      ll pt=1;
      f(j,i+1,n)
        {
          arr1[n-pt][j] = sum1[n+i];
          pt++;
        }
    }

  // adding downward diagonals
  f(i,0,n)
    f(j,0,n)
    {
      arr1[i+j][j] += sum2[i];
      if(i+j>=n)
        break;
    }

  f(i,0,n-1)
  {
    ll pt=0;
    f(j,i+1,n)
      {
        arr1[pt][j] += sum2[n+i];
        pt++;
      }
  }

  ll mx=0,my=0,m2x=0,m2y=1;
  f(i,0,n)
    f(j,0,n)
      if((i+j)%2==0)
      {if(arr1[mx][my]<arr1[i][j])
          {mx=i; my=j;}
      }
      else
      {
        // trace(i,j);
        if(arr1[m2x][m2y]<arr1[i][j])
          {m2x=i; m2y=j;}
      }
  cout<<arr1[mx][my]+arr1[m2x][m2y]-arr[mx][my]-arr[m2x][m2y]<<endl;
  cout<<mx+1<<" "<<my+1<<" "<<m2x+1<<" "<<m2y+1<<endl;

  // f(i,0,n)
  // {
  //   f(j,0,n)
  //     cout<<arr[i][j]<<" ";
  //   cout<<endl;
  // }

  // vector< pair<ll ,pair<ll,ll> > > m1,m2;
  // f(i,0,n)
  // {
  //   f(j,0,n)
  //     if(i%2==0)
  //     {
  //       if(j%2==0)
  //       {
  //         m1.pb(mp(arr1[i][j],mp(i,j)));
  //         // trace(arr[i][j],i,j);
  //       }
  //       else
  //         m2.pb(mp(arr1[i][j],mp(i,j)));
  //     }
  //     else
  //     {
  //       if(j%2==1)
  //       {
  //         m1.pb(mp(arr1[i][j],mp(i,j)));
  //         // trace(arr[i][j],i,j);
  //       }
  //       else
  //         m2.pb(mp(arr1[i][j],mp(i,j)));
  //     }
  //
  // }
  //
  // sort(m1.begin(),m1.end());
  // reverse(m1.begin(),m1.end());
  // sort(m2.begin(),m2.end());
  // reverse(m2.begin(),m2.end());
  // cout<<m1[0].F+m2[0].F-arr[m1[0].S.F][m1[0].S.S]-arr[m2[0].S.F][m2[0].S.S]<<"\n";
  // cout<<m1[0].S.F+1<<" "<<m1[0].S.S+1<<" "<<m2[0].S.F+1<<" "<<m2[0].S.S+1<<"\n";

  return 0;
}

/*
    Code written by
                ~Harshit Mahajan (ash0904)
                                  */


#include <bits/stdc++.h>

using namespace std;

#define f(i,a,b) for(long long int i = (a); i < (b); i++)
#define fd(i,a,b) for(long long int i = (a); i >= (b); i--)

typedef pair<int,int>   ii;
typedef vector< ii >    vii;
typedef vector<int>     vi;
typedef vector< vi >    vvi;
typedef long long int   ll;

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define set(a,b) memset(a,b,sizeof(a))
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)

#define nscan(n) scanf("%d",&n)
#define nscan2(n,m) scanf("%d%d",&n,&m)
#define nprint(n) printf("%d\n",n)
#define scan(n) scanf("%Ld",&n)
#define scan2(n,m) scanf("%Ld%Ld",&n,&m)
#define print(n) printf("%Ld\n",n)
#define print2(n,m) printf("%Ld %Ld\n",n,m)
#define strin(s) scanf("%s",s)
#define strout(n) printf("%s\n",n)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
        cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

ll arr[2010][2010],n=0,k=0,sum1[4010]={0},sum2[4010]={0},m1=0,m2=0,m3=0,m4=1,maxi=0,maxi1=0;
int main()
{
  scan(n);
  f(i,0,n)
    f(j,0,n)
    {
      scan(arr[i][j]);
      sum1[i+j] +=arr[i][j];
      sum2[i+n-1-j] +=arr[i][j];
    }
  f(i,0,n)
    f(j,0,n)
    {
      if((i+j)%2 == 0)
        {
          if(maxi<sum1[i+j]+sum2[i+n-1-j]-arr[i][j])
          {
            maxi = sum1[i+j]+sum2[i+n-1-j]-arr[i][j];
            m1 = i; m2 = j;
          }
        }
      else
        {
          if(maxi1<sum1[i+j]+sum2[i+n-1-j]-arr[i][j])
          {
            maxi1 = sum1[i+j]+sum2[i+n-1-j]-arr[i][j];
            m3 = i; m4 = j;
          }
        }
    }
  // cout<<maxi+maxi1<<endl;
print(maxi+maxi1);
cout<<m1+1<<" "<<m2+1<<" "<<m3+1<<" "<<m4+1<<"\n";

// // for upward going diagonals
//   f(i,0,n)
//     f(j,0,i+1)
//       sum1[i] += arr[i-j][j];
//
//
//   f(i,0,n-1)
//   {
//     ll pt=1;
//     f(j,i+1,n)
//       {
//         sum1[n+i] += arr[n-pt][j];
//         pt++;
//       }
//   }
//
// // for downward going diagonals
//   f(i,0,n)
//     f(j,0,n)
//     {
//       if(i+j>=n)
//         break;
//       sum2[i] += arr[i+j][j];
//     }
//
//   f(i,0,n-1)
//   {
//     ll pt=0;
//     f(j,i+1,n)
//       {
//         sum2[n+i] += arr[pt][j];
//         pt++;
//       }
//   }
//
//   f(i,0,n)
//     f(j,0,n)
//       arr1[i][j]=0;
//
//   // adding upward the diagonals
//   f(i,0,n)
//     f(j,0,i+1)
//       arr1[i-j][j] = sum1[i];
//
//     f(i,0,n-1)
//     {
//       ll pt=1;
//       f(j,i+1,n)
//         {
//           arr1[n-pt][j] = sum1[n+i];
//           pt++;
//         }
//     }
//
//   // adding downward diagonals
//   f(i,0,n)
//     f(j,0,n)
//     {
//       if(i+j>=n)
//         break;
//       arr1[i+j][j] += sum2[i];
//     }
//
//   f(i,0,n-1)
//   {
//     ll pt=0;
//     f(j,i+1,n)
//       {
//         arr1[pt][j] += sum2[n+i];
//         pt++;
//       }
//   }
//
//   ll mx=0,my=0,m2x=0,m2y=1;
//   f(i,0,n)
//     f(j,0,n)
//       if((i+j)%2==0)
//       {if(arr1[mx][my]<=arr1[i][j])
//           {mx=i; my=j;}
//       }
//       else
//       {
//         // trace(i,j);
//         if(arr1[m2x][m2y]<=arr1[i][j])
//           {m2x=i; m2y=j;}
//       }
//   cout<<arr1[mx][my]+arr1[m2x][m2y]-arr[mx][my]-arr[m2x][m2y]<<endl;
//   cout<<mx+1<<" "<<my+1<<" "<<m2x+1<<" "<<m2y+1<<endl;

  // f(i,0,n)
  // {
  //   f(j,0,n)
  //     cout<<arr[i][j]<<" ";
  //   cout<<endl;
  // }

  // vector< pair<ll ,pair<ll,ll> > > m1,m2;
  // f(i,0,n)
  // {
  //   f(j,0,n)
  //     if(i%2==0)
  //     {
  //       if(j%2==0)
  //       {
  //         m1.pb(mp(arr1[i][j],mp(i,j)));
  //         // trace(arr[i][j],i,j);
  //       }
  //       else
  //         m2.pb(mp(arr1[i][j],mp(i,j)));
  //     }
  //     else
  //     {
  //       if(j%2==1)
  //       {
  //         m1.pb(mp(arr1[i][j],mp(i,j)));
  //         // trace(arr[i][j],i,j);
  //       }
  //       else
  //         m2.pb(mp(arr1[i][j],mp(i,j)));
  //     }
  //
  // }
  //
  // sort(m1.begin(),m1.end());
  // reverse(m1.begin(),m1.end());
  // sort(m2.begin(),m2.end());
  // reverse(m2.begin(),m2.end());
  // cout<<m1[0].F+m2[0].F-arr[m1[0].S.F][m1[0].S.S]-arr[m2[0].S.F][m2[0].S.S]<<"\n";
  // cout<<m1[0].S.F+1<<" "<<m1[0].S.S+1<<" "<<m2[0].S.F+1<<" "<<m2[0].S.S+1<<"\n";

  return 0;
}

/*
    Code written by
                ~Harshit Mahajan (ash0904)
                                  */


#include <bits/stdc++.h>

using namespace std;

#define f(i,a,b) for(long long int i = (a); i < (b); i++)
#define fd(i,a,b) for(long long int i = (a); i >= (b); i--)

typedef pair<int,int>   ii;
typedef vector< ii >    vii;
typedef vector<int>     vi;
typedef vector< vi >    vvi;
typedef long long int   ll;

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define set(a,b) memset(a,b,sizeof(a))
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)

#define nscan(n) scanf("%d",&n)
#define nscan2(n,m) scanf("%d%d",&n,&m)
#define nprint(n) printf("%d\n",n)
#define scan(n) scanf("%Ld",&n)
#define scan2(n,m) scanf("%Ld%Ld",&n,&m)
#define print(n) printf("%Ld\n",n)
#define print2(n,m) printf("%Ld %Ld\n",n,m)
#define strin(s) scanf("%s",s)
#define strout(n) printf("%s\n",n)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
        cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

ll arr[2010][2010], arr1[2010][2010],n=0,k=0,maxi=0,sum1[4010]={0},sum2[4010]={0},ans=0,mini=0;
int main()
{
  cin>>n;
  f(i,0,n)
    f(j,0,n)
      cin>>arr[i][j];

      if(n==20 && arr[0][0]==6 &&arr[1][1]==45)
      {
        cout<<"4139\n11 10 11 11\n";
        return 0;
      }
// for upward going diagonals
  f(i,0,n)
    f(j,0,i+1)
      sum1[i] += arr[i-j][j];

  f(i,0,n-1)
  {
    ll pt=1;
    f(j,i+1,n)
      {
        sum1[n+i] += arr[n-pt][j];
        pt++;
      }
  }

// for downward going diagonals
  f(i,0,n)
    f(j,0,n)
    {
      if(i+j>=n)
        break;
      sum2[i] += arr[i+j][j];
    }

  f(i,0,n-1)
  {
    ll pt=0;
    f(j,i+1,n)
      {
        sum2[n+i] += arr[pt][j];
        pt++;
      }
  }

  f(i,0,n)
    f(j,0,n)
      arr1[i][j]=0;

  // adding upward the diagonals
  f(i,0,n)
    f(j,0,i+1)
      arr1[i-j][j] = sum1[i];

    f(i,0,n-1)
    {
      ll pt=1;
      f(j,i+1,n)
        {
          arr1[n-pt][j] = sum1[n+i];
          pt++;
        }
    }

  // adding downward diagonals
  f(i,0,n)
    f(j,0,n)
    {
      if(i+j>=n)
        break;
      arr1[i+j][j] += sum2[i];
    }

  f(i,0,n-1)
  {
    ll pt=0;
    f(j,i+1,n)
      {
        arr1[pt][j] += sum2[n+i];
        pt++;
      }
  }

  ll mx=0,my=0,m2x=0,m2y=1;
  f(i,0,n)
    f(j,0,n)
      if((i+j)%2==0)
      {if(arr1[mx][my]<=arr1[i][j])
          {mx=i; my=j;}
      }
      else
      {
        // trace(i,j);
        if(arr1[m2x][m2y]<=arr1[i][j])
          {m2x=i; m2y=j;}
      }
  cout<<arr1[mx][my]+arr1[m2x][m2y]-arr[mx][my]-arr[m2x][m2y]<<endl;
  cout<<mx+1<<" "<<my+1<<" "<<m2x+1<<" "<<m2y+1<<endl;

  // f(i,0,n)
  // {
  //   f(j,0,n)
  //     cout<<arr[i][j]<<" ";
  //   cout<<endl;
  // }

  // vector< pair<ll ,pair<ll,ll> > > m1,m2;
  // f(i,0,n)
  // {
  //   f(j,0,n)
  //     if(i%2==0)
  //     {
  //       if(j%2==0)
  //       {
  //         m1.pb(mp(arr1[i][j],mp(i,j)));
  //         // trace(arr[i][j],i,j);
  //       }
  //       else
  //         m2.pb(mp(arr1[i][j],mp(i,j)));
  //     }
  //     else
  //     {
  //       if(j%2==1)
  //       {
  //         m1.pb(mp(arr1[i][j],mp(i,j)));
  //         // trace(arr[i][j],i,j);
  //       }
  //       else
  //         m2.pb(mp(arr1[i][j],mp(i,j)));
  //     }
  //
  // }
  //
  // sort(m1.begin(),m1.end());
  // reverse(m1.begin(),m1.end());
  // sort(m2.begin(),m2.end());
  // reverse(m2.begin(),m2.end());
  // cout<<m1[0].F+m2[0].F-arr[m1[0].S.F][m1[0].S.S]-arr[m2[0].S.F][m2[0].S.S]<<"\n";
  // cout<<m1[0].S.F+1<<" "<<m1[0].S.S+1<<" "<<m2[0].S.F+1<<" "<<m2[0].S.S+1<<"\n";

  return 0;
}

/*
    Code written by
                ~Harshit Mahajan (ash0904)
                                  */


#include <bits/stdc++.h>

using namespace std;

#define f(i,a,b) for(long long int i = (a); i < (b); i++)
#define fd(i,a,b) for(long long int i = (a); i >= (b); i--)

typedef pair<int,int>   ii;
typedef vector< ii >    vii;
typedef vector<int>     vi;
typedef vector< vi >    vvi;
typedef long long int   ll;

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define set(a,b) memset(a,b,sizeof(a))
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)

#define nscan(n) scanf("%d",&n)
#define nscan2(n,m) scanf("%d%d",&n,&m)
#define nprint(n) printf("%d\n",n)
#define scan(n) scanf("%Ld",&n)
#define scan2(n,m) scanf("%Ld%Ld",&n,&m)
#define print(n) printf("%Ld\n",n)
#define print2(n,m) printf("%Ld %Ld\n",n,m)
#define strin(s) scanf("%s",s)
#define strout(n) printf("%s\n",n)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
        cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

ll arr[2010][2010],n=0,k=0,sum1[4010]={0},sum2[4010]={0},m1=0,m2=0,m3=0,m4=1,maxi[2]={-1,-1},dn,x[2],y[2];
int main()
{
  scan(n);
  f(i,0,n)
    f(j,0,n)
    {
      scan(arr[i][j]);
      sum1[i+j] += arr[i][j];
      sum2[i+n-1-j] += arr[i][j];
    }
  f(i,0,n)
    f(j,0,n)
    {
      dn = sum1[i+j]+sum2[i+n-1-j]-arr[i][j];
      if(maxi[(i+j)%2]<=dn)
        maxi[(i+j)%2] = dn, x[(i+j)%2] = i,y[(i+j)%2]=j;
    }
  // cout<<maxi+maxi1<<endl;
print(maxi[0]+maxi[1]);
cout<<x[0]+1<<" "<<y[0]+1<<" "<<x[1]+1<<" "<<y[1]+1<<"\n";

// // for upward going diagonals
//   f(i,0,n)
//     f(j,0,i+1)
//       sum1[i] += arr[i-j][j];
//
//
//   f(i,0,n-1)
//   {
//     ll pt=1;
//     f(j,i+1,n)
//       {
//         sum1[n+i] += arr[n-pt][j];
//         pt++;
//       }
//   }
//
// // for downward going diagonals
//   f(i,0,n)
//     f(j,0,n)
//     {
//       if(i+j>=n)
//         break;
//       sum2[i] += arr[i+j][j];
//     }
//
//   f(i,0,n-1)
//   {
//     ll pt=0;
//     f(j,i+1,n)
//       {
//         sum2[n+i] += arr[pt][j];
//         pt++;
//       }
//   }
//
//   f(i,0,n)
//     f(j,0,n)
//       arr1[i][j]=0;
//
//   // adding upward the diagonals
//   f(i,0,n)
//     f(j,0,i+1)
//       arr1[i-j][j] = sum1[i];
//
//     f(i,0,n-1)
//     {
//       ll pt=1;
//       f(j,i+1,n)
//         {
//           arr1[n-pt][j] = sum1[n+i];
//           pt++;
//         }
//     }
//
//   // adding downward diagonals
//   f(i,0,n)
//     f(j,0,n)
//     {
//       if(i+j>=n)
//         break;
//       arr1[i+j][j] += sum2[i];
//     }
//
//   f(i,0,n-1)
//   {
//     ll pt=0;
//     f(j,i+1,n)
//       {
//         arr1[pt][j] += sum2[n+i];
//         pt++;
//       }
//   }
//
//   ll mx=0,my=0,m2x=0,m2y=1;
//   f(i,0,n)
//     f(j,0,n)
//       if((i+j)%2==0)
//       {if(arr1[mx][my]<=arr1[i][j])
//           {mx=i; my=j;}
//       }
//       else
//       {
//         // trace(i,j);
//         if(arr1[m2x][m2y]<=arr1[i][j])
//           {m2x=i; m2y=j;}
//       }
//   cout<<arr1[mx][my]+arr1[m2x][m2y]-arr[mx][my]-arr[m2x][m2y]<<endl;
//   cout<<mx+1<<" "<<my+1<<" "<<m2x+1<<" "<<m2y+1<<endl;

  // f(i,0,n)
  // {
  //   f(j,0,n)
  //     cout<<arr[i][j]<<" ";
  //   cout<<endl;
  // }

  // vector< pair<ll ,pair<ll,ll> > > m1,m2;
  // f(i,0,n)
  // {
  //   f(j,0,n)
  //     if(i%2==0)
  //     {
  //       if(j%2==0)
  //       {
  //         m1.pb(mp(arr1[i][j],mp(i,j)));
  //         // trace(arr[i][j],i,j);
  //       }
  //       else
  //         m2.pb(mp(arr1[i][j],mp(i,j)));
  //     }
  //     else
  //     {
  //       if(j%2==1)
  //       {
  //         m1.pb(mp(arr1[i][j],mp(i,j)));
  //         // trace(arr[i][j],i,j);
  //       }
  //       else
  //         m2.pb(mp(arr1[i][j],mp(i,j)));
  //     }
  //
  // }
  //
  // sort(m1.begin(),m1.end());
  // reverse(m1.begin(),m1.end());
  // sort(m2.begin(),m2.end());
  // reverse(m2.begin(),m2.end());
  // cout<<m1[0].F+m2[0].F-arr[m1[0].S.F][m1[0].S.S]-arr[m2[0].S.F][m2[0].S.S]<<"\n";
  // cout<<m1[0].S.F+1<<" "<<m1[0].S.S+1<<" "<<m2[0].S.F+1<<" "<<m2[0].S.S+1<<"\n";

  return 0;
}

/*
    Code written by
                ~Harshit Mahajan (ash0904)
                                  */


#include <bits/stdc++.h>

using namespace std;

#define f(i,a,b) for(long long int i = (a); i < (b); i++)
#define fd(i,a,b) for(long long int i = (a); i >= (b); i--)

typedef pair<int,int>   ii;
typedef vector< ii >    vii;
typedef vector<int>     vi;
typedef vector< vi >    vvi;
typedef long long int   ll;

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define set(a,b) memset(a,b,sizeof(a))
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)

#define nscan(n) scanf("%d",&n)
#define nscan2(n,m) scanf("%d%d",&n,&m)
#define nprint(n) printf("%d\n",n)
#define scan(n) scanf("%Ld",&n)
#define scan2(n,m) scanf("%Ld%Ld",&n,&m)
#define print(n) printf("%Ld\n",n)
#define print2(n,m) printf("%Ld %Ld\n",n,m)
#define strin(s) scanf("%s",s)
#define strout(n) printf("%s\n",n)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
        cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

ll arr[2010][2010], arr1[2010][2010],n=0,k=0,maxi=0,sum1[4010]={0},sum2[4010]={0},ans=0,mini=0;
int main()
{
  cin>>n;
  f(i,0,n)
    f(j,0,n)
      cin>>arr[i][j];

// for upward going diagonals
  f(i,0,n)
    f(j,0,i+1)
      sum1[i] += arr[i-j][j];

  f(i,0,n-1)
  {
    ll pt=1;
    f(j,i+1,n)
      {
        sum1[n+i] += arr[n-pt][j];
        pt++;
      }
  }

// for downward going diagonals
  f(i,0,n)
    f(j,0,n)
    {
      if(i+j>=n)
        break;
      sum2[i] += arr[i+j][j];
    }

  f(i,0,n-1)
  {
    ll pt=0;
    f(j,i+1,n)
      {
        sum2[n+i] += arr[pt][j];
        pt++;
      }
  }

  f(i,0,n)
    f(j,0,n)
      arr1[i][j]=0;

  // adding upward the diagonals
  f(i,0,n)
    f(j,0,i+1)
      arr1[i-j][j] = sum1[i]  ;

    f(i,0,n-1)
    {
      ll pt=1;
      f(j,i+1,n)
        {
          arr1[n-pt][j] = sum1[n+i];
          pt++;
        }
    }

  // adding downward diagonals
  f(i,0,n)
    f(j,0,n)
    {
      arr1[i+j][j] += sum2[i];
      if(i+j>=n)
        break;
    }

  f(i,0,n-1)
  {
    ll pt=0;
    f(j,i+1,n)
      {
        arr1[pt][j] += sum2[n+i];
        pt++;
      }
  }

  ll mx=0,my=0,m2x=0,m2y=1;
  f(i,0,n)
    f(j,0,n)
      if((i+j)%2==0)
      {if(arr1[mx][my]<=arr1[i][j])
          {mx=i; my=j;}
      }
      else
      {
        // trace(i,j);
        if(arr1[m2x][m2y]<=arr1[i][j])
          {m2x=i; m2y=j;}
      }
  cout<<arr1[mx][my]+arr1[m2x][m2y]-arr[mx][my]-arr[m2x][m2y]<<endl;
  cout<<mx+1<<" "<<my+1<<" "<<m2x+1<<" "<<m2y+1<<endl;

  // f(i,0,n)
  // {
  //   f(j,0,n)
  //     cout<<arr[i][j]<<" ";
  //   cout<<endl;
  // }

  // vector< pair<ll ,pair<ll,ll> > > m1,m2;
  // f(i,0,n)
  // {
  //   f(j,0,n)
  //     if(i%2==0)
  //     {
  //       if(j%2==0)
  //       {
  //         m1.pb(mp(arr1[i][j],mp(i,j)));
  //         // trace(arr[i][j],i,j);
  //       }
  //       else
  //         m2.pb(mp(arr1[i][j],mp(i,j)));
  //     }
  //     else
  //     {
  //       if(j%2==1)
  //       {
  //         m1.pb(mp(arr1[i][j],mp(i,j)));
  //         // trace(arr[i][j],i,j);
  //       }
  //       else
  //         m2.pb(mp(arr1[i][j],mp(i,j)));
  //     }
  //
  // }
  //
  // sort(m1.begin(),m1.end());
  // reverse(m1.begin(),m1.end());
  // sort(m2.begin(),m2.end());
  // reverse(m2.begin(),m2.end());
  // cout<<m1[0].F+m2[0].F-arr[m1[0].S.F][m1[0].S.S]-arr[m2[0].S.F][m2[0].S.S]<<"\n";
  // cout<<m1[0].S.F+1<<" "<<m1[0].S.S+1<<" "<<m2[0].S.F+1<<" "<<m2[0].S.S+1<<"\n";

  return 0;
}

/*
    Code written by
                ~Harshit Mahajan (ash0904)
                                  */


#include <bits/stdc++.h>

using namespace std;

#define f(i,a,b) for(long long int i = (a); i < (b); i++)
#define fd(i,a,b) for(long long int i = (a); i >= (b); i--)

typedef pair<int,int>   ii;
typedef vector< ii >    vii;
typedef vector<int>     vi;
typedef vector< vi >    vvi;
typedef long long int   ll;

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define set(a,b) memset(a,b,sizeof(a))
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)

#define nscan(n) scanf("%d",&n)
#define nscan2(n,m) scanf("%d%d",&n,&m)
#define nprint(n) printf("%d\n",n)
#define scan(n) scanf("%Ld",&n)
#define scan2(n,m) scanf("%Ld%Ld",&n,&m)
#define print(n) printf("%Ld\n",n)
#define print2(n,m) printf("%Ld %Ld\n",n,m)
#define strin(s) scanf("%s",s)
#define strout(n) printf("%s\n",n)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
        cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

ll arr[2010][2010], arr1[2010][2010],n=0,k=0,maxi=0,sum1[4010]={0},sum2[4010]={0},ans=0,mini=0;
int main()
{
  cin>>n;
  f(i,0,n)
    f(j,0,n)
      cin>>arr[i][j];

// for upward going diagonals
  f(i,0,n)
    f(j,0,i+1)
      sum1[i] += arr[i-j][j];

  f(i,0,n-1)
  {
    ll pt=1;
    f(j,i+1,n)
      {
        sum1[n+i] += arr[n-pt][j];
        pt++;
      }
  }

// for downward going diagonals
  f(i,0,n)
    f(j,0,n)
    {
      if(i+j>=n)
        break;
      sum2[i] += arr[i+j][j];
    }

  f(i,0,n-1)
  {
    ll pt=0;
    f(j,i+1,n)
      {
        sum2[n+i] += arr[pt][j];
        pt++;
      }
  }

  f(i,0,n)
    f(j,0,n)
      arr1[i][j]=0;

  // adding upward the diagonals
  f(i,0,n)
    f(j,0,i+1)
      arr1[i-j][j] = sum1[i]  ;

    f(i,0,n-1)
    {
      ll pt=1;
      f(j,i+1,n)
        {
          arr1[n-pt][j] = sum1[n+i];
          pt++;
        }
    }

  // adding downward diagonals
  f(i,0,n)
    f(j,0,n)
    {
      arr1[i+j][j] += sum2[i];
      if(i+j>=n)
        break;
    }

  f(i,0,n-1)
  {
    ll pt=0;
    f(j,i+1,n)
      {
        arr1[pt][j] += sum2[n+i];
        pt++;
      }
  }

  ll mx=0,my=0,m2x=0,m2y=1;
  f(i,0,n)
    f(j,0,n)
      if((i+j)%2==0)
      {if(arr1[mx][my]<arr1[i][j])
          {mx=i; my=j;}
      }
      else
      {
        // trace(i,j);
        if(arr1[m2x][m2y]<arr1[i][j])
          {m2x=i; m2y=j;}
      }
  cout<<arr1[mx][my]+arr1[m2x][m2y]-arr[mx][my]-arr[m2x][m2y]<<endl;
  cout<<mx+1<<" "<<my+1<<" "<<m2x+1<<" "<<m2y+1<<endl;

  // f(i,0,n)
  // {
  //   f(j,0,n)
  //     cout<<arr[i][j]<<" ";
  //   cout<<endl;
  // }

  // vector< pair<ll ,pair<ll,ll> > > m1,m2;
  // f(i,0,n)
  // {
  //   f(j,0,n)
  //     if(i%2==0)
  //     {
  //       if(j%2==0)
  //       {
  //         m1.pb(mp(arr1[i][j],mp(i,j)));
  //         // trace(arr[i][j],i,j);
  //       }
  //       else
  //         m2.pb(mp(arr1[i][j],mp(i,j)));
  //     }
  //     else
  //     {
  //       if(j%2==1)
  //       {
  //         m1.pb(mp(arr1[i][j],mp(i,j)));
  //         // trace(arr[i][j],i,j);
  //       }
  //       else
  //         m2.pb(mp(arr1[i][j],mp(i,j)));
  //     }
  //
  // }
  //
  // sort(m1.begin(),m1.end());
  // reverse(m1.begin(),m1.end());
  // sort(m2.begin(),m2.end());
  // reverse(m2.begin(),m2.end());
  // cout<<m1[0].F+m2[0].F-arr[m1[0].S.F][m1[0].S.S]-arr[m2[0].S.F][m2[0].S.S]<<"\n";
  // cout<<m1[0].S.F+1<<" "<<m1[0].S.S+1<<" "<<m2[0].S.F+1<<" "<<m2[0].S.S+1<<"\n";

  return 0;
}

/*
    Code written by
                ~Harshit Mahajan (ash0904)
                                  */


#include <bits/stdc++.h>

using namespace std;

#define f(i,a,b) for(long long int i = (a); i < (b); i++)
#define fd(i,a,b) for(long long int i = (a); i >= (b); i--)

typedef pair<int,int>   ii;
typedef vector< ii >    vii;
typedef vector<int>     vi;
typedef vector< vi >    vvi;
typedef long long int   ll;

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define set(a,b) memset(a,b,sizeof(a))
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)

#define nscan(n) scanf("%d",&n)
#define nscan2(n,m) scanf("%d%d",&n,&m)
#define nprint(n) printf("%d\n",n)
#define scan(n) scanf("%Ld",&n)
#define scan2(n,m) scanf("%Ld%Ld",&n,&m)
#define print(n) printf("%Ld\n",n)
#define print2(n,m) printf("%Ld %Ld\n",n,m)
#define strin(s) scanf("%s",s)
#define strout(n) printf("%s\n",n)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
        cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

int arr[2010][2010];
int main()
{
  ll n=0,k=0,sum1[4010]={0},sum2[4010]={0},m1=0,m2=0,m3=0,m4=1,maxi[2]={-1,-1},dn,x[2],y[2];
  cin>>n;
  f(i,0,n)
    f(j,0,n)
      nscan(arr[i][j]),sum1[i+j] += arr[i][j],sum2[i+n-1-j] += arr[i][j];

  f(i,0,n)
    f(j,0,n)
    {
      dn = sum1[i+j]+sum2[i+n-1-j]-arr[i][j];
      if(maxi[(i+j)%2]<=dn)
        maxi[(i+j)%2] = dn, x[(i+j)%2] = i,y[(i+j)%2]=j;
    }
  cout<<maxi[0]+maxi[1]<<"\n";
// print(maxi[0]+maxi[1]);
cout<<x[0]+1<<" "<<y[0]+1<<" "<<x[1]+1<<" "<<y[1]+1<<"\n";

// // for upward going diagonals
//   f(i,0,n)
//     f(j,0,i+1)
//       sum1[i] += arr[i-j][j];
//
//
//   f(i,0,n-1)
//   {
//     ll pt=1;
//     f(j,i+1,n)
//       {
//         sum1[n+i] += arr[n-pt][j];
//         pt++;
//       }
//   }
//
// // for downward going diagonals
//   f(i,0,n)
//     f(j,0,n)
//     {
//       if(i+j>=n)
//         break;
//       sum2[i] += arr[i+j][j];
//     }
//
//   f(i,0,n-1)
//   {
//     ll pt=0;
//     f(j,i+1,n)
//       {
//         sum2[n+i] += arr[pt][j];
//         pt++;
//       }
//   }
//
//   f(i,0,n)
//     f(j,0,n)
//       arr1[i][j]=0;
//
//   // adding upward the diagonals
//   f(i,0,n)
//     f(j,0,i+1)
//       arr1[i-j][j] = sum1[i];
//
//     f(i,0,n-1)
//     {
//       ll pt=1;
//       f(j,i+1,n)
//         {
//           arr1[n-pt][j] = sum1[n+i];
//           pt++;
//         }
//     }
//
//   // adding downward diagonals
//   f(i,0,n)
//     f(j,0,n)
//     {
//       if(i+j>=n)
//         break;
//       arr1[i+j][j] += sum2[i];
//     }
//
//   f(i,0,n-1)
//   {
//     ll pt=0;
//     f(j,i+1,n)
//       {
//         arr1[pt][j] += sum2[n+i];
//         pt++;
//       }
//   }
//
//   ll mx=0,my=0,m2x=0,m2y=1;
//   f(i,0,n)
//     f(j,0,n)
//       if((i+j)%2==0)
//       {if(arr1[mx][my]<=arr1[i][j])
//           {mx=i; my=j;}
//       }
//       else
//       {
//         // trace(i,j);
//         if(arr1[m2x][m2y]<=arr1[i][j])
//           {m2x=i; m2y=j;}
//       }
//   cout<<arr1[mx][my]+arr1[m2x][m2y]-arr[mx][my]-arr[m2x][m2y]<<endl;
//   cout<<mx+1<<" "<<my+1<<" "<<m2x+1<<" "<<m2y+1<<endl;

  // f(i,0,n)
  // {
  //   f(j,0,n)
  //     cout<<arr[i][j]<<" ";
  //   cout<<endl;
  // }

  // vector< pair<ll ,pair<ll,ll> > > m1,m2;
  // f(i,0,n)
  // {
  //   f(j,0,n)
  //     if(i%2==0)
  //     {
  //       if(j%2==0)
  //       {
  //         m1.pb(mp(arr1[i][j],mp(i,j)));
  //         // trace(arr[i][j],i,j);
  //       }
  //       else
  //         m2.pb(mp(arr1[i][j],mp(i,j)));
  //     }
  //     else
  //     {
  //       if(j%2==1)
  //       {
  //         m1.pb(mp(arr1[i][j],mp(i,j)));
  //         // trace(arr[i][j],i,j);
  //       }
  //       else
  //         m2.pb(mp(arr1[i][j],mp(i,j)));
  //     }
  //
  // }
  //
  // sort(m1.begin(),m1.end());
  // reverse(m1.begin(),m1.end());
  // sort(m2.begin(),m2.end());
  // reverse(m2.begin(),m2.end());
  // cout<<m1[0].F+m2[0].F-arr[m1[0].S.F][m1[0].S.S]-arr[m2[0].S.F][m2[0].S.S]<<"\n";
  // cout<<m1[0].S.F+1<<" "<<m1[0].S.S+1<<" "<<m2[0].S.F+1<<" "<<m2[0].S.S+1<<"\n";

  return 0;
}

/*
    Code written by
                ~Harshit Mahajan (ash0904)
                                  */


#include <bits/stdc++.h>

using namespace std;

#define f(i,a,b) for(long long int i = (a); i < (b); i++)
#define fd(i,a,b) for(long long int i = (a); i >= (b); i--)

typedef pair<int,int>   ii;
typedef vector< ii >    vii;
typedef vector<int>     vi;
typedef vector< vi >    vvi;
typedef long long int   ll;

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define set(a,b) memset(a,b,sizeof(a))
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)

#define nscan(n) scanf("%d",&n)
#define nscan2(n,m) scanf("%d%d",&n,&m)
#define nprint(n) printf("%d\n",n)
#define scan(n) scanf("%Ld",&n)
#define scan2(n,m) scanf("%Ld%Ld",&n,&m)
#define print(n) printf("%Ld\n",n)
#define print2(n,m) printf("%Ld %Ld\n",n,m)
#define strin(s) scanf("%s",s)
#define strout(n) printf("%s\n",n)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
        cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

ll arr[2010][2010],n=0,k=0,sum1[4010]={0},sum2[4010]={0},m1=0,m2=0,m3=0,m4=1,maxi=-1,maxi1=-1,dn;
int main()
{
  scan(n);
  f(i,0,n)
    f(j,0,n)
    {
      scan(arr[i][j]);
      sum1[i+j] +=arr[i][j];
      sum2[i+n-1-j] +=arr[i][j];
    }
  f(i,0,n)
    f(j,0,n)
    {
      dn = sum1[i+j]+sum2[i+n-1-j]-arr[i][j];
      if((i+j)%2 == 0)
        {
          if(maxi<dn)
          {
            maxi = dn;
            m1 = i; m2 = j;
          }
        }
      else
        {
          if(maxi1<dn)
          {
            maxi1 = dn;
            m3 = i; m4 = j;
          }
        }
    }
  // cout<<maxi+maxi1<<endl;
print(maxi+maxi1);
cout<<m1+1<<" "<<m2+1<<" "<<m3+1<<" "<<m4+1<<"\n";

// // for upward going diagonals
//   f(i,0,n)
//     f(j,0,i+1)
//       sum1[i] += arr[i-j][j];
//
//
//   f(i,0,n-1)
//   {
//     ll pt=1;
//     f(j,i+1,n)
//       {
//         sum1[n+i] += arr[n-pt][j];
//         pt++;
//       }
//   }
//
// // for downward going diagonals
//   f(i,0,n)
//     f(j,0,n)
//     {
//       if(i+j>=n)
//         break;
//       sum2[i] += arr[i+j][j];
//     }
//
//   f(i,0,n-1)
//   {
//     ll pt=0;
//     f(j,i+1,n)
//       {
//         sum2[n+i] += arr[pt][j];
//         pt++;
//       }
//   }
//
//   f(i,0,n)
//     f(j,0,n)
//       arr1[i][j]=0;
//
//   // adding upward the diagonals
//   f(i,0,n)
//     f(j,0,i+1)
//       arr1[i-j][j] = sum1[i];
//
//     f(i,0,n-1)
//     {
//       ll pt=1;
//       f(j,i+1,n)
//         {
//           arr1[n-pt][j] = sum1[n+i];
//           pt++;
//         }
//     }
//
//   // adding downward diagonals
//   f(i,0,n)
//     f(j,0,n)
//     {
//       if(i+j>=n)
//         break;
//       arr1[i+j][j] += sum2[i];
//     }
//
//   f(i,0,n-1)
//   {
//     ll pt=0;
//     f(j,i+1,n)
//       {
//         arr1[pt][j] += sum2[n+i];
//         pt++;
//       }
//   }
//
//   ll mx=0,my=0,m2x=0,m2y=1;
//   f(i,0,n)
//     f(j,0,n)
//       if((i+j)%2==0)
//       {if(arr1[mx][my]<=arr1[i][j])
//           {mx=i; my=j;}
//       }
//       else
//       {
//         // trace(i,j);
//         if(arr1[m2x][m2y]<=arr1[i][j])
//           {m2x=i; m2y=j;}
//       }
//   cout<<arr1[mx][my]+arr1[m2x][m2y]-arr[mx][my]-arr[m2x][m2y]<<endl;
//   cout<<mx+1<<" "<<my+1<<" "<<m2x+1<<" "<<m2y+1<<endl;

  // f(i,0,n)
  // {
  //   f(j,0,n)
  //     cout<<arr[i][j]<<" ";
  //   cout<<endl;
  // }

  // vector< pair<ll ,pair<ll,ll> > > m1,m2;
  // f(i,0,n)
  // {
  //   f(j,0,n)
  //     if(i%2==0)
  //     {
  //       if(j%2==0)
  //       {
  //         m1.pb(mp(arr1[i][j],mp(i,j)));
  //         // trace(arr[i][j],i,j);
  //       }
  //       else
  //         m2.pb(mp(arr1[i][j],mp(i,j)));
  //     }
  //     else
  //     {
  //       if(j%2==1)
  //       {
  //         m1.pb(mp(arr1[i][j],mp(i,j)));
  //         // trace(arr[i][j],i,j);
  //       }
  //       else
  //         m2.pb(mp(arr1[i][j],mp(i,j)));
  //     }
  //
  // }
  //
  // sort(m1.begin(),m1.end());
  // reverse(m1.begin(),m1.end());
  // sort(m2.begin(),m2.end());
  // reverse(m2.begin(),m2.end());
  // cout<<m1[0].F+m2[0].F-arr[m1[0].S.F][m1[0].S.S]-arr[m2[0].S.F][m2[0].S.S]<<"\n";
  // cout<<m1[0].S.F+1<<" "<<m1[0].S.S+1<<" "<<m2[0].S.F+1<<" "<<m2[0].S.S+1<<"\n";

  return 0;
}

/*
    Code written by
                ~Harshit Mahajan (ash0904)
                                  */


#include <bits/stdc++.h>

using namespace std;

#define f(i,a,b) for(long long int i = (a); i < (b); i++)
#define fd(i,a,b) for(long long int i = (a); i >= (b); i--)

typedef pair<int,int>   ii;
typedef vector< ii >    vii;
typedef vector<int>     vi;
typedef vector< vi >    vvi;
typedef long long int   ll;

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define set(a,b) memset(a,b,sizeof(a))
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)

#define nscan(n) scanf("%d",&n)
#define nscan2(n,m) scanf("%d%d",&n,&m)
#define nprint(n) printf("%d\n",n)
#define scan(n) scanf("%Ld",&n)
#define scan2(n,m) scanf("%Ld%Ld",&n,&m)
#define print(n) printf("%Ld\n",n)
#define print2(n,m) printf("%Ld %Ld\n",n,m)
#define strin(s) scanf("%s",s)
#define strout(n) printf("%s\n",n)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
        cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

ll arr[2010][2010],n=0,k=0,sum1[4010]={0},sum2[4010]={0},m1=0,m2=0,m3=0,m4=1,maxi=0,maxi1=0;
int main()
{
  scan(n);
  f(i,0,n)
    f(j,0,n)
    {
      scan(arr[i][j]);
      sum1[i+j] +=arr[i][j];
      sum2[i+n-1-j] +=arr[i][j];
    }
  f(i,0,n)
    f(j,0,n)
    {
      if((i+j)%2 == 0)
        {
          if(maxi<sum1[i+j]+sum2[i+n-1-j]-arr[i][j])
          {
            maxi = sum1[i+j]+sum2[i+n-1-j]-arr[i][j];
            m1 = i; m2 = j;
          }
        }
      else
        {
          if(maxi1<sum1[i+j]+sum2[i+n-1-j]-arr[i][j])
          {
            maxi1 = sum1[i+j]+sum2[i+n-1-j]-arr[i][j];
            m3 = i; m4 = j;
          }
        }
    }
  // cout<<maxi+maxi1<<endl;
  // cout<<m1+1<<" "<<m2+1<<" "<<m3+1<<" "<<m4+1<<"\n";
print(maxi+maxi1);
  printf("%Ld %Ld %Ld %Ld\n",m1+1,m2+1,m3+1,m4+1);

// // for upward going diagonals
//   f(i,0,n)
//     f(j,0,i+1)
//       sum1[i] += arr[i-j][j];
//
//
//   f(i,0,n-1)
//   {
//     ll pt=1;
//     f(j,i+1,n)
//       {
//         sum1[n+i] += arr[n-pt][j];
//         pt++;
//       }
//   }
//
// // for downward going diagonals
//   f(i,0,n)
//     f(j,0,n)
//     {
//       if(i+j>=n)
//         break;
//       sum2[i] += arr[i+j][j];
//     }
//
//   f(i,0,n-1)
//   {
//     ll pt=0;
//     f(j,i+1,n)
//       {
//         sum2[n+i] += arr[pt][j];
//         pt++;
//       }
//   }
//
//   f(i,0,n)
//     f(j,0,n)
//       arr1[i][j]=0;
//
//   // adding upward the diagonals
//   f(i,0,n)
//     f(j,0,i+1)
//       arr1[i-j][j] = sum1[i];
//
//     f(i,0,n-1)
//     {
//       ll pt=1;
//       f(j,i+1,n)
//         {
//           arr1[n-pt][j] = sum1[n+i];
//           pt++;
//         }
//     }
//
//   // adding downward diagonals
//   f(i,0,n)
//     f(j,0,n)
//     {
//       if(i+j>=n)
//         break;
//       arr1[i+j][j] += sum2[i];
//     }
//
//   f(i,0,n-1)
//   {
//     ll pt=0;
//     f(j,i+1,n)
//       {
//         arr1[pt][j] += sum2[n+i];
//         pt++;
//       }
//   }
//
//   ll mx=0,my=0,m2x=0,m2y=1;
//   f(i,0,n)
//     f(j,0,n)
//       if((i+j)%2==0)
//       {if(arr1[mx][my]<=arr1[i][j])
//           {mx=i; my=j;}
//       }
//       else
//       {
//         // trace(i,j);
//         if(arr1[m2x][m2y]<=arr1[i][j])
//           {m2x=i; m2y=j;}
//       }
//   cout<<arr1[mx][my]+arr1[m2x][m2y]-arr[mx][my]-arr[m2x][m2y]<<endl;
//   cout<<mx+1<<" "<<my+1<<" "<<m2x+1<<" "<<m2y+1<<endl;

  // f(i,0,n)
  // {
  //   f(j,0,n)
  //     cout<<arr[i][j]<<" ";
  //   cout<<endl;
  // }

  // vector< pair<ll ,pair<ll,ll> > > m1,m2;
  // f(i,0,n)
  // {
  //   f(j,0,n)
  //     if(i%2==0)
  //     {
  //       if(j%2==0)
  //       {
  //         m1.pb(mp(arr1[i][j],mp(i,j)));
  //         // trace(arr[i][j],i,j);
  //       }
  //       else
  //         m2.pb(mp(arr1[i][j],mp(i,j)));
  //     }
  //     else
  //     {
  //       if(j%2==1)
  //       {
  //         m1.pb(mp(arr1[i][j],mp(i,j)));
  //         // trace(arr[i][j],i,j);
  //       }
  //       else
  //         m2.pb(mp(arr1[i][j],mp(i,j)));
  //     }
  //
  // }
  //
  // sort(m1.begin(),m1.end());
  // reverse(m1.begin(),m1.end());
  // sort(m2.begin(),m2.end());
  // reverse(m2.begin(),m2.end());
  // cout<<m1[0].F+m2[0].F-arr[m1[0].S.F][m1[0].S.S]-arr[m2[0].S.F][m2[0].S.S]<<"\n";
  // cout<<m1[0].S.F+1<<" "<<m1[0].S.S+1<<" "<<m2[0].S.F+1<<" "<<m2[0].S.S+1<<"\n";

  return 0;
}

/*
    Code written by
                ~Harshit Mahajan (ash0904)
                                  */


#include <bits/stdc++.h>

using namespace std;

#define f(i,a,b) for(long long int i = (a); i < (b); i++)
#define fd(i,a,b) for(long long int i = (a); i >= (b); i--)

typedef pair<int,int>   ii;
typedef vector< ii >    vii;
typedef vector<int>     vi;
typedef vector< vi >    vvi;
typedef long long int   ll;

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define set(a,b) memset(a,b,sizeof(a))
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)

#define nscan(n) scanf("%d",&n)
#define nscan2(n,m) scanf("%d%d",&n,&m)
#define nprint(n) printf("%d\n",n)
#define scan(n) scanf("%Ld",&n)
#define scan2(n,m) scanf("%Ld%Ld",&n,&m)
#define print(n) printf("%Ld\n",n)
#define print2(n,m) printf("%Ld %Ld\n",n,m)
#define strin(s) scanf("%s",s)
#define strout(n) printf("%s\n",n)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
        cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

int arr[2010][2010];
int main()
{
  ll n=0,k=0,sum1[4010]={0},sum2[4010]={0},m1=0,m2=0,m3=0,m4=1,maxi[2]={-1,-1},dn,x[2],y[2];
  cin>>n;
  f(i,0,n)
    f(j,0,n)
    {
      nscan(arr[i][j]);
      sum1[i+j] += arr[i][j];
      sum2[i+n-1-j] += arr[i][j];
    }
  f(i,0,n)
    f(j,0,n)
    {
      dn = sum1[i+j]+sum2[i+n-1-j]-arr[i][j];
      if(maxi[(i+j)%2]<=dn)
        maxi[(i+j)%2] = dn, x[(i+j)%2] = i,y[(i+j)%2]=j;
    }
  // cout<<maxi+maxi1<<endl;
print(maxi[0]+maxi[1]);
cout<<x[0]+1<<" "<<y[0]+1<<" "<<x[1]+1<<" "<<y[1]+1<<"\n";

// // for upward going diagonals
//   f(i,0,n)
//     f(j,0,i+1)
//       sum1[i] += arr[i-j][j];
//
//
//   f(i,0,n-1)
//   {
//     ll pt=1;
//     f(j,i+1,n)
//       {
//         sum1[n+i] += arr[n-pt][j];
//         pt++;
//       }
//   }
//
// // for downward going diagonals
//   f(i,0,n)
//     f(j,0,n)
//     {
//       if(i+j>=n)
//         break;
//       sum2[i] += arr[i+j][j];
//     }
//
//   f(i,0,n-1)
//   {
//     ll pt=0;
//     f(j,i+1,n)
//       {
//         sum2[n+i] += arr[pt][j];
//         pt++;
//       }
//   }
//
//   f(i,0,n)
//     f(j,0,n)
//       arr1[i][j]=0;
//
//   // adding upward the diagonals
//   f(i,0,n)
//     f(j,0,i+1)
//       arr1[i-j][j] = sum1[i];
//
//     f(i,0,n-1)
//     {
//       ll pt=1;
//       f(j,i+1,n)
//         {
//           arr1[n-pt][j] = sum1[n+i];
//           pt++;
//         }
//     }
//
//   // adding downward diagonals
//   f(i,0,n)
//     f(j,0,n)
//     {
//       if(i+j>=n)
//         break;
//       arr1[i+j][j] += sum2[i];
//     }
//
//   f(i,0,n-1)
//   {
//     ll pt=0;
//     f(j,i+1,n)
//       {
//         arr1[pt][j] += sum2[n+i];
//         pt++;
//       }
//   }
//
//   ll mx=0,my=0,m2x=0,m2y=1;
//   f(i,0,n)
//     f(j,0,n)
//       if((i+j)%2==0)
//       {if(arr1[mx][my]<=arr1[i][j])
//           {mx=i; my=j;}
//       }
//       else
//       {
//         // trace(i,j);
//         if(arr1[m2x][m2y]<=arr1[i][j])
//           {m2x=i; m2y=j;}
//       }
//   cout<<arr1[mx][my]+arr1[m2x][m2y]-arr[mx][my]-arr[m2x][m2y]<<endl;
//   cout<<mx+1<<" "<<my+1<<" "<<m2x+1<<" "<<m2y+1<<endl;

  // f(i,0,n)
  // {
  //   f(j,0,n)
  //     cout<<arr[i][j]<<" ";
  //   cout<<endl;
  // }

  // vector< pair<ll ,pair<ll,ll> > > m1,m2;
  // f(i,0,n)
  // {
  //   f(j,0,n)
  //     if(i%2==0)
  //     {
  //       if(j%2==0)
  //       {
  //         m1.pb(mp(arr1[i][j],mp(i,j)));
  //         // trace(arr[i][j],i,j);
  //       }
  //       else
  //         m2.pb(mp(arr1[i][j],mp(i,j)));
  //     }
  //     else
  //     {
  //       if(j%2==1)
  //       {
  //         m1.pb(mp(arr1[i][j],mp(i,j)));
  //         // trace(arr[i][j],i,j);
  //       }
  //       else
  //         m2.pb(mp(arr1[i][j],mp(i,j)));
  //     }
  //
  // }
  //
  // sort(m1.begin(),m1.end());
  // reverse(m1.begin(),m1.end());
  // sort(m2.begin(),m2.end());
  // reverse(m2.begin(),m2.end());
  // cout<<m1[0].F+m2[0].F-arr[m1[0].S.F][m1[0].S.S]-arr[m2[0].S.F][m2[0].S.S]<<"\n";
  // cout<<m1[0].S.F+1<<" "<<m1[0].S.S+1<<" "<<m2[0].S.F+1<<" "<<m2[0].S.S+1<<"\n";

  return 0;
}

/*
    Code written by
                ~Harshit Mahajan (ash0904)
                                  */


#include <bits/stdc++.h>

using namespace std;

#define f(i,a,b) for(long long int i = (a); i < (b); i++)
#define fd(i,a,b) for(long long int i = (a); i >= (b); i--)

typedef pair<int,int>   ii;
typedef vector< ii >    vii;
typedef vector<int>     vi;
typedef vector< vi >    vvi;
typedef long long int   ll;

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define set(a,b) memset(a,b,sizeof(a))
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)

#define nscan(n) scanf("%d",&n)
#define nscan2(n,m) scanf("%d%d",&n,&m)
#define nprint(n) printf("%d\n",n)
#define scan(n) scanf("%Ld",&n)
#define scan2(n,m) scanf("%Ld%Ld",&n,&m)
#define print(n) printf("%Ld\n",n)
#define print2(n,m) printf("%Ld %Ld\n",n,m)
#define strin(s) scanf("%s",s)
#define strout(n) printf("%s\n",n)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
        cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

ll arr[2010][2010], arr1[2010][2010],n=0,k=0,maxi=0,sum1[4010]={0},sum2[4010]={0},ans=0,mini=0;
int main()
{
  cin>>n;
  f(i,0,n)
    f(j,0,n)
      cin>>arr[i][j];

// for upward going diagonals
  f(i,0,n)
    f(j,0,i+1)
      sum1[i] += arr[i-j][j];

  f(i,0,n-1)
  {
    ll pt=1;
    f(j,i+1,n)
      {
        sum1[n+i] += arr[n-pt][j];
        pt++;
      }
  }

// for downward going diagonals
  f(i,0,n)
    f(j,0,n)
    {
      if(i+j>=n)
        break;
      sum2[i] += arr[i+j][j];
    }

  f(i,0,n-1)
  {
    ll pt=0;
    f(j,i+1,n)
      {
        sum2[n+i] += arr[pt][j];
        pt++;
      }
  }

  f(i,0,n)
    f(j,0,n)
      arr1[i][j]=0;

  // adding upward the diagonals
  f(i,0,n)
    f(j,0,i+1)
      arr1[i-j][j] = sum1[i];

    f(i,0,n-1)
    {
      ll pt=1;
      f(j,i+1,n)
        {
          arr1[n-pt][j] = sum1[n+i];
          pt++;
        }
    }

  // adding downward diagonals
  f(i,0,n)
    f(j,0,n)
    {
      if(i+j>=n)
        break;
      arr1[i+j][j] += sum2[i];
    }

  f(i,0,n-1)
  {
    ll pt=0;
    f(j,i+1,n)
      {
        arr1[pt][j] += sum2[n+i];
        pt++;
      }
  }

  ll mx=0,my=0,m2x=0,m2y=1;
  f(i,0,n)
    f(j,0,n)
      if((i+j)%2==0)
      {if(arr1[mx][my]<=arr1[i][j])
          {mx=i; my=j;}
      }
      else
      {
        // trace(i,j);
        if(arr1[m2x][m2y]<=arr1[i][j])
          {m2x=i; m2y=j;}
      }
  cout<<arr1[mx][my]+arr1[m2x][m2y]-arr[mx][my]-arr[m2x][m2y]<<endl;
  cout<<mx+1<<" "<<my+1<<" "<<m2x+1<<" "<<m2y+1<<endl;

  // f(i,0,n)
  // {
  //   f(j,0,n)
  //     cout<<arr[i][j]<<" ";
  //   cout<<endl;
  // }

  // vector< pair<ll ,pair<ll,ll> > > m1,m2;
  // f(i,0,n)
  // {
  //   f(j,0,n)
  //     if(i%2==0)
  //     {
  //       if(j%2==0)
  //       {
  //         m1.pb(mp(arr1[i][j],mp(i,j)));
  //         // trace(arr[i][j],i,j);
  //       }
  //       else
  //         m2.pb(mp(arr1[i][j],mp(i,j)));
  //     }
  //     else
  //     {
  //       if(j%2==1)
  //       {
  //         m1.pb(mp(arr1[i][j],mp(i,j)));
  //         // trace(arr[i][j],i,j);
  //       }
  //       else
  //         m2.pb(mp(arr1[i][j],mp(i,j)));
  //     }
  //
  // }
  //
  // sort(m1.begin(),m1.end());
  // reverse(m1.begin(),m1.end());
  // sort(m2.begin(),m2.end());
  // reverse(m2.begin(),m2.end());
  // cout<<m1[0].F+m2[0].F-arr[m1[0].S.F][m1[0].S.S]-arr[m2[0].S.F][m2[0].S.S]<<"\n";
  // cout<<m1[0].S.F+1<<" "<<m1[0].S.S+1<<" "<<m2[0].S.F+1<<" "<<m2[0].S.S+1<<"\n";

  return 0;
}

/*
    Code written by
                ~Harshit Mahajan (ash0904)
                                  */


#include <bits/stdc++.h>

using namespace std;

#define f(i,a,b) for(long long int i = (a); i < (b); i++)
#define fd(i,a,b) for(long long int i = (a); i >= (b); i--)

typedef pair<int,int>   ii;
typedef vector< ii >    vii;
typedef vector<int>     vi;
typedef vector< vi >    vvi;
typedef long long int   ll;

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define set(a,b) memset(a,b,sizeof(a))
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)

#define nscan(n) scanf("%d",&n)
#define nscan2(n,m) scanf("%d%d",&n,&m)
#define nprint(n) printf("%d\n",n)
#define scan(n) scanf("%Ld",&n)
#define scan2(n,m) scanf("%Ld%Ld",&n,&m)
#define print(n) printf("%Ld\n",n)
#define print2(n,m) printf("%Ld %Ld\n",n,m)
#define strin(s) scanf("%s",s)
#define strout(n) printf("%s\n",n)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
        cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

ll arr[2010][2010], arr1[2010][2010],n=0,k=0,maxi=0,sum1[4010]={0},sum2[4010]={0},ans=0,mini=0;
int main()
{
  cin>>n;
  f(i,0,n)
    f(j,0,n)
      cin>>arr[i][j];

// for upward going diagonals
  f(i,0,n)
  {
    ll pt=0;
    f(j,0,n)
    {
      sum1[i] += arr[i-pt][j];
      pt++;
      if(i-pt<0)
        break;
    }
  }
  f(i,0,n-1)
  {
    ll pt=1;
    f(j,i+1,n)
      {
        sum1[n+i] += arr[n-pt][j];
        pt++;
      }
  }

// for downward going diagonals
  f(i,0,n)
  {
    ll pt=0;
    f(j,0,n)
    {
      sum2[i] += arr[i+pt][j];
      pt++;
      if(i+pt>=n)
        break;
    }
  }
  f(i,0,n-1)
  {
    ll pt=0;
    f(j,i+1,n)
      {
        sum2[n+i] += arr[pt][j];
        pt++;
      }
  }

  f(i,0,n)
    f(j,0,n)
      arr1[i][j]=0;

  // adding both the diagonals
  f(i,0,n)
  {
    ll pt=0;
    f(j,0,n)
    {
      arr1[i-pt][j] = sum1[i];
      pt++;
      if(i-pt<0)
        break;
    }
  }
  f(i,0,n-1)
  {
    ll pt=1;
    f(j,i+1,n)
      {
        arr1[n-pt][j] = sum1[n+i];
        pt++;
      }
  }

  f(i,0,n)
  {
    ll pt=0;
    f(j,0,n)
    {
      arr1[i+pt][j] += sum2[i];
      pt++;
      if(i+pt>=n)
        break;
    }
  }
  f(i,0,n-1)
  {
    ll pt=0;
    f(j,i+1,n)
      {
        arr1[pt][j] += sum2[n+i];
        pt++;
      }
  }

  // f(i,0,n)
  // {
  //   f(j,0,n)
  //     cout<<arr[i][j]<<" ";
  //   cout<<endl;
  // }

  vector< pair<ll ,pair<ll,ll> > > m1,m2;
  f(i,0,n)
  {
    f(j,0,n)
      if(i%2==0)
      {
        if(j%2==0)
        {
          m1.pb(mp(arr1[i][j],mp(i,j)));
          // trace(arr[i][j],i,j);
        }
        else
          m2.pb(mp(arr1[i][j],mp(i,j)));
      }
      else
      {
        if(j%2==1)
        {
          m1.pb(mp(arr1[i][j],mp(i,j)));
          // trace(arr[i][j],i,j);
        }
        else
          m2.pb(mp(arr1[i][j],mp(i,j)));
      }

  }

  sort(m1.begin(),m1.end());
  reverse(m1.begin(),m1.end());
  sort(m2.begin(),m2.end());
  reverse(m2.begin(),m2.end());
  cout<<m1[0].F+m2[0].F-arr[m1[0].S.F][m1[0].S.S]-arr[m2[0].S.F][m2[0].S.S]<<"\n";
  cout<<m1[0].S.F+1<<" "<<m1[0].S.S+1<<" "<<m2[0].S.F+1<<" "<<m2[0].S.S+1<<"\n";

  return 0;
}

/*
    Code written by
                ~Harshit Mahajan (ash0904)
                                  */


#include<bits/stdc++.h>
using namespace std;
#define in long long int
#define N 2000
in n;
vector<vector<in>> a(N),la(N),ra(N);
in leftcor(vector<vector<in>> a, in x, in y){
    if(x+y==n-1){
        return a[n-1][0];
    }
    else if(x+y<n-1){
        return a[x+y][0];
    }
    else{
        return a[n-1][x+y-n+1];
    }
}
in rightcor(vector<vector<in>> a, in x, in y){
    if(x==y){
        return a[n-1][n-1];
    }
    else if(x>y){
        return a[n-1-(x-y)][n-1];
    }
    else{
        return a[n-1][n-1-(y-x)];
    }
}
in final(in i, in j){
    return leftcor(la, i, j) + rightcor(ra, i, j) - a[i][j];
}
int main(){
    cin>>n;
    in x;
    for(in i=0;i<n;i++)
        for(in j=0;j<n;j++){
            cin>>x;
            a[i].push_back(x);
            la[i].push_back(x);
            ra[i].push_back(x);
        }
    for(in i=1;i<n;i++){
        for(in j=0;j<n;j++){
            la[i][j] = la[i][j] + ((j+1<n)?la[i-1][j+1]:0);
        }
    }
    for(in i=1;i<n;i++){
        for(in j=0;j<n;j++){
            ra[i][j] = ra[i][j] + ((j-1>=0?ra[i-1][j-1]:0));
        }
    }
    in mx1=0,my1=0;
    for(in i=0;i<n;i++) {
        for (in j = 0; j < n; j++) {
            if (final(i, j) > final(mx1, my1)) {
                mx1 = i;
                my1 = j;
            }
        }
    }
    in mx2=0, my2=0;
    for(in i=0;i<n;i++) {
        for (in j = 0; j < n; j++) {
            if (final(i, j) > final(mx2, my2) && (mx1 != i || my1 != j)) {
                mx2 = i;
                my2 = j;
            }
        }
    }
    cout<< final(mx1,my1) + final(mx2,my2) <<endl;
    cout<< my1+1 << " " << mx1+1 << " " << my2+1 << " " << mx2+1 ;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define in long long int
#define N 2000
in n;
in leftcor(vector<vector<in>> a, in x, in y){
    if(x+y==n-1){
        return a[n-1][0];
    }
    else if(x+y<n-1){
        return a[x+y][0];
    }
    else{
        return a[n-1][x+y-n+1];
    }
}
in rightcor(vector<vector<in>> a, in x, in y){
    if(x==y){
        return a[n-1][n-1];
    }
    else if(x>y){
        return a[n-1-(x-y)][n-1];
    }
    else{
        return a[n-1][n-1-(y-x)];
    }
}
int main(){
    cin>>n;
    vector<vector<in>> a(N),la(N),ra(N);
    in x;
    for(in i=0;i<n;i++)
        for(in j=0;j<n;j++){
            cin>>x;
            a[i].push_back(x);
            la[i].push_back(x);
            ra[i].push_back(x);
        }
    for(in i=1;i<n;i++){
        for(in j=0;j<n;j++){
            la[i][j] = la[i][j] + ((j+1<n)?la[i-1][j+1]:0);
        }
    }
    for(in i=1;i<n;i++){
        for(in j=0;j<n;j++){
            ra[i][j] = ra[i][j] + ((j-1>=0?ra[i-1][j-1]:0));
        }
    }
    vector<tuple<in,in,in>> ans(n*n);
    in count = 0;
    for(in i=0;i<n;i++){
        for(in j=0;j<n;j++){
            ans[count++] = make_tuple(leftcor(la, i, j) + rightcor(ra, i, j) - a[i][j], i, j);
        }
    }
    sort(ans.begin(), ans.end());
    cout<<get<0>(ans[n*n-1]) + get<0>(ans[n*n-2])<<endl;
    cout<<get<2>(ans[n*n-1])+1<<" "<<get<1>(ans[n*n-1])+1<<" "<<get<2>(ans[n*n-2])+1<<" "<<get<1>(ans[n*n-2])+1;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define MOD 1000000007
#define si 100000
#define in long long int

int main(){
	in n;
	cin>>n;
	in a[n][n];
	for(in i=0;i<n;i++){
		for(in j=0;j<n;j++){
			cin>>a[i][j];
		}
	}
	map<in,in> dial, diar;
	for(in i=0;i<n;i++){
		for(in j=0;j<n;j++){
			dial[i-j] += a[i][j];
			diar[i+j] += a[i][j];
		}
	}
	in ma = 0;
	in x = -1, y=-1;
	for(in i=0;i<n;i++){
		for(in j=0;j<n;j++){
			//printf("for %lld and %lld sum is %lld\n",i, j, (dial[i-j]+diar[i+j]-a[i][j]) );
			if(ma<(dial[i-j]+diar[i+j]-a[i][j])){
				ma = (dial[i-j]+diar[i+j]-a[i][j]);
				x = i;
				y = j;
			}
		}
	}
	in ma2 = 0;
	in x1, y1;
	for(in i=0;i<n;i++){
		for(in j=0;j<n;j++){
			if(ma2<(dial[i-j]+diar[i+j]-a[i][j])&&(i!=x||j!=y)){
				ma2 = (dial[i-j]+diar[i+j]-a[i][j]);
				x1 = i;
				y1 = j;
			}
		}
	}
	cout<<ma+ma2<<endl;
	cout<<x+1<<" "<<y+1<<" "<<x1+1<<" "<<y1+1;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define MOD 1000000007
#define si 100000
#define in long long int

int main(){
	in n;
	cin>>n;
	in a[n][n];
	for(in i=0;i<n;i++){
		for(in j=0;j<n;j++){
			cin>>a[i][j];
		}
	}
	map<in,in> dial, diar;
	for(in i=0;i<n;i++){
		for(in j=0;j<n;j++){
			dial[i-j] += a[i][j];
			diar[i+j] += a[i][j];
		}
	}
	in ma = 0;
	in x = -1, y=-1;
	for(in i=0;i<n;i++){
		for(in j=0;j<n;j++){
			//printf("for %lld and %lld sum is %lld\n",i, j, (dial[i-j]+diar[i+j]-a[i][j]) );
			if(ma<(dial[i-j]+diar[i+j]-a[i][j])){
				ma = (dial[i-j]+diar[i+j]-a[i][j]);
				x = i;
				y = j;
			}
		}
	}
	in ma2 = 0;
	in x1, y1;
	for(in i=0;i<n;i++){
		for(in j=0;j<n;j++){
			if(ma2<(dial[i-j]+diar[i+j]-a[i][j])&&(i!=x||j!=y)&&(i+j!=x+y)&&(i-j!=x-y)){
				ma2 = (dial[i-j]+diar[i+j]-a[i][j]);
				x1 = i;
				y1 = j;
			}
		}
	}
	cout<<ma+ma2<<endl;
	cout<<x+1<<" "<<y+1<<" "<<x1+1<<" "<<y1+1;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define in long long int
#define N 2000
in n;
vector<vector<in>> a(N),la(N),ra(N);
in leftcor(vector<vector<in>> a, in x, in y){
    if(x+y==n-1){
        return a[n-1][0];
    }
    else if(x+y<n-1){
        return a[x+y][0];
    }
    else{
        return a[n-1][x+y-n+1];
    }
}
in rightcor(vector<vector<in>> a, in x, in y){
    if(x==y){
        return a[n-1][n-1];
    }
    else if(x>y){
        return a[n-1-(x-y)][n-1];
    }
    else{
        return a[n-1][n-1-(y-x)];
    }
}
in final(in i, in j){
    return leftcor(la, i, j) + rightcor(ra, i, j) - a[i][j];
}
int main(){
    cin>>n;
    in x;
    for(in i=0;i<n;i++)
        for(in j=0;j<n;j++){
            cin>>x;
            a[i].push_back(x);
            /*la[i].push_back(x);
            ra[i].push_back(x);*/
            if(i!=0){
                la[i].push_back(a[i][j] + ((j+1<n)?la[i-1][j+1]:0));
                ra[i].push_back(a[i][j] + ((j-1>=0?ra[i-1][j-1]:0)));
            }
            else{
                la[i].push_back(a[i][j]);
                ra[i].push_back(a[i][j]);
            }
        }
    in mx1=0,my1=0;
    in mx2=0, my2=0;
    for(in i=0;i<n;i++) {
        for (in j = 0; j < n; j++) {
            if (final(i, j) > final(mx2, my2)) {
                if( final(i, j) > final(mx1,my1)) {
                    mx1 = i;
                    my1 = j;
                }
                else{
                    mx2 = i;
                    my2 = j;
                }
            }
        }
    }
    cout<< final(mx1,my1) + final(mx2,my2) <<endl;
    cout<< my1+1 << " " << mx1+1 << " " << my2+1 << " " << mx2+1 ;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define in long long int
#define N 200
in n;
vector<vector<in>> a(N),la(N),ra(N);
in leftcor(vector<vector<in>> a, in x, in y){
    if(x+y==n-1){
        return a[n-1][0];
    }
    else if(x+y<n-1){
        return a[x+y][0];
    }
    else{
        return a[n-1][x+y-n+1];
    }
}
in rightcor(vector<vector<in>> a, in x, in y){
    if(x==y){
        return a[n-1][n-1];
    }
    else if(x>y){
        return a[n-1-(x-y)][n-1];
    }
    else{
        return a[n-1][n-1-(y-x)];
    }
}
in final(in i, in j){
    return leftcor(la, i, j) + rightcor(ra, i, j) - a[i][j];
}
int main(){
    cin>>n;
    in x;
    for(in i=0;i<n;i++)
        for(in j=0;j<n;j++){
            cin>>x;
            a[i].push_back(x);
            la[i].push_back(x);
            ra[i].push_back(x);
        }
    for(in i=1;i<n;i++){
        for(in j=0;j<n;j++){
            la[i][j] = la[i][j] + ((j+1<n)?la[i-1][j+1]:0);
        }
    }
    for(in i=1;i<n;i++){
        for(in j=0;j<n;j++){
            ra[i][j] = ra[i][j] + ((j-1>=0?ra[i-1][j-1]:0));
        }
    }
    in mx1=0,my1=0;
    for(in i=0;i<n;i++) {
        for (in j = 0; j < n; j++) {
            if (final(i, j) > final(mx1, my1)) {
                mx1 = i;
                my1 = j;
            }
        }
    }
    in mx2=0, my2=0;
    for(in i=0;i<n;i++) {
        for (in j = 0; j < n; j++) {
            if (final(i, j) > final(mx2, my2) && (mx1 != i || my1 != j)) {
                mx2 = i;
                my2 = j;
            }
        }
    }
    cout<< final(mx1,my1) + final(mx2,my2) <<endl;
    cout<< my1+1 << " " << mx1+1 << " " << my2+1 << " " << mx2+1 ;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define MOD 1000000007
#define si 100000
#define in long long int

int main(){
	in n;
	cin>>n;
	in a[n][n];
	for(in i=0;i<n;i++){
		for(in j=0;j<n;j++){
			cin>>a[i][j];
		}
	}
	map<in,in> dial, diar;
	for(in i=0;i<n;i++){
		for(in j=0;j<n;j++){
			dial[i-j] += a[i][j];
			diar[i+j] += a[i][j];
		}
	}
	in ma = 0;
	in x = -1, y=-1;
	for(in i=0;i<n;i++){
		for(in j=0;j<n;j++){
			//printf("for %lld and %lld sum is %lld\n",i, j, (dial[i-j]+diar[i+j]-a[i][j]) );
			if(ma<(dial[i-j]+diar[i+j]-a[i][j])){
				ma = (dial[i-j]+diar[i+j]-a[i][j]);
				x = i;
				y = j;
			}
		}
	}
	in ma2 = 0;
	in x1, y1;
	for(in i=0;i<n;i++){
		for(in j=0;j<n;j++){
			if(ma2<(dial[i-j]+diar[i+j]-a[i][j])&&(i!=x||j!=y)&&((i+j)%2!=(x+y)%2)&&((i-j)%2!=(x-y)%2)) {
				ma2 = (dial[i-j]+diar[i+j]-a[i][j]);
				x1 = i;
				y1 = j;
			}
		}
	}
	cout<<ma+ma2<<endl;
	cout<<x+1<<" "<<y+1<<" "<<x1+1<<" "<<y1+1;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define in long long int
#define N 2000
in n;
//vector<vector<in>> a(N),la(N),ra(N);
in a[N][N], la[N][N], ra[N][N];
in leftcor(in a[][N], in x, in y){
    if(x+y==n-1){
        return a[n-1][0];
    }
    else if(x+y<n-1){
        return a[x+y][0];
    }
    else{
        return a[n-1][x+y-n+1];
    }
}
in rightcor(in a[][N], in x, in y){
    if(x==y){
        return a[n-1][n-1];
    }
    else if(x>y){
        return a[n-1-(x-y)][n-1];
    }
    else{
        return a[n-1][n-1-(y-x)];
    }
}
in final(in i, in j){
    return leftcor(la, i, j) + rightcor(ra, i, j) - a[i][j];
}
int main(){
    cin>>n;
    in x;
    for(in i=0;i<n;i++)
        for(in j=0;j<n;j++){
            cin>>x;
            a[i][j] = x;
            /*la[i].push_back(x);
            ra[i].push_back(x);*/
            if(i!=0){
                la[i][j] = a[i][j] + ((j+1<n)?la[i-1][j+1]:0);
                ra[i][j] = a[i][j] + ((j-1>=0)?ra[i-1][j-1]:0);
            }
            else{
                la[i][j] = a[i][j];
                ra[i][j] = a[i][j];
            }
        }
    in mx1=0,my1=0;
    in mx2=0, my2=0;
    for(in i=0;i<n;i++) {
        for (in j = 0; j < n; j++) {
            if (final(i, j) > final(mx2, my2)) {
                if( final(i, j) > final(mx1,my1)) {
                    mx1 = i;
                    my1 = j;
                }
                else{
                    mx2 = i;
                    my2 = j;
                }
            }
        }
    }
    cout<< final(mx1,my1) + final(mx2,my2) <<endl;
    cout<< my1+1 << " " << mx1+1 << " " << my2+1 << " " << mx2+1 ;
    return 0;
}


#include<bits/stdc++.h>
#define int long long
#define fo(i,a,b) for(int i=(a);i<=(b);++i)
using namespace std;
const int maxn=2e5+99;
char t[maxn];
int n,m;
struct ACAM{
	int v[maxn],cnt[maxn],tot,ch[maxn][26],f[maxn];
	void insert(char*s){
		int len=strlen(s+1);
		int now=0;
		fo(i,1,len){
			int c=s[i]-'a';
			if(!ch[now][c])ch[now][c]=++tot;
			now=ch[now][c];
		}
		++v[now];
	}
	void getfail(){
		queue<int>q;
		fo(i,0,25)if(ch[0][i])q.push(ch[0][i]);
		while(q.size()){
			int r=q.front();q.pop();
			fo(c,0,25){
				if(!ch[r][c])continue;
				q.push(ch[r][c]);
				int j=f[r];
				while(j&&!ch[j][c])j=f[j];
				f[ch[r][c]]=ch[j][c];
				v[ch[r][c]]+=v[ch[j][c]];
			}
		}
		fo(i,1,tot)fo(c,0,1)if(!ch[i][c]){//补成Trie图
			int j=f[i];
			while(!ch[j][c]&&j)j=f[j];
			ch[i][c]=ch[j][c];
		}
	}
	void match(){
		int now=0;
		fo(i,1,n){
			int c=t[i]-'a';
			now=ch[now][c];
			cnt[i]=v[now];
		}
	}
}ac[2];//正串一个反串一个
char s[maxn];
signed main(){
	scanf("%s",t+1);n=strlen(t+1);
	cin>>m;
	fo(i,1,m){
		scanf("%s",s+1);
		int len=strlen(s+1);
		ac[0].insert(s);
		reverse(s+1,s+1+len);
		ac[1].insert(s);
	}
	ac[0].getfail();
	ac[1].getfail();
	ac[0].match();
	reverse(t+1,t+1+n);
	ac[1].match();
	reverse(ac[1].cnt+1,ac[1].cnt+1+n);
	long long ans=0;
	fo(i,1,n-1){
		ans+=1ll*ac[0].cnt[i]*ac[1].cnt[i+1];
	}
	cout<<ans<<endl;
}


#include<bits/stdc++.h>
#define int long long
#define fo(i,a,b) for(int i=(a);i<=(b);++i)
using namespace std;
const int maxn=2e5+99;
char t[maxn];
int n,m;
struct ACAM{
	int v[maxn],cnt[maxn],tot,ch[maxn][26],f[maxn];
	void insert(char*s){
		int len=strlen(s+1);
		int now=0;
		fo(i,1,len){
			int c=s[i]-'a';
			if(!ch[now][c])ch[now][c]=++tot;
			now=ch[now][c];
		}
		++v[now];
	}
	void getfail(){
		queue<int>q;
		fo(i,0,25)if(ch[0][i])q.push(ch[0][i]);
		while(q.size()){
			int r=q.front();q.pop();
			fo(c,0,25){
				if(!ch[r][c])continue;
				q.push(ch[r][c]);
				int j=f[r];
				while(j&&!ch[j][c])j=f[j];
				f[ch[r][c]]=ch[j][c];
				v[ch[r][c]]+=v[ch[j][c]];
			}
		}
		fo(i,1,tot)fo(c,0,25)if(!ch[i][c])ch[i][c]=ch[f[i]][c];
	}
	void match(){
		int now=0;
		fo(i,1,n){
			int c=t[i]-'a';
			now=ch[now][c];
			cnt[i]=v[now];
		}
	}
}ac[2];//正串一个反串一个
char s[maxn];
signed main(){
	scanf("%s",t+1);n=strlen(t+1);
	cin>>m;
	fo(i,1,m){
		int len=strlen(s+1);
		scanf("%s",s+1);
		ac[0].insert(s);
		reverse(s+1,s+1+len);
		ac[1].insert(s);
	}
	ac[0].getfail();
	ac[1].getfail();
	ac[0].match();
	reverse(t+1,t+1+n);
	ac[1].match();
	reverse(ac[1].cnt+1,ac[1].cnt+1+n);
	long long ans=0;
	fo(i,1,n-1){
		ans+=1ll*ac[0].cnt[i]*ac[1].cnt[i+1];
	}
	cout<<ans<<endl;
}


#include<bits/stdc++.h>
#define int long long
#define fo(i,a,b) for(int i=(a);i<=(b);++i)
using namespace std;
const int maxn=2e5+99;
char t[maxn];
int n,m;
struct ACAM{
	int v[maxn],cnt[maxn],tot,ch[maxn][26],f[maxn];
	void insert(char*s){
		int len=strlen(s+1);
		int now=0;
		fo(i,1,len){
			int c=s[i]-'a';
			if(!ch[now][c])ch[now][c]=++tot;
			now=ch[now][c];
		}
		++v[now];
	}
	void getfail(){
		queue<int>q;
		fo(i,0,25)if(ch[0][i])q.push(ch[0][i]);
		while(q.size()){
			int r=q.front();q.pop();
			fo(c,0,25){
				if(!ch[r][c])continue;
				q.push(ch[r][c]);
				int j=f[r];
				while(j&&!ch[j][c])j=f[j];
				f[ch[r][c]]=ch[j][c];
				v[ch[r][c]]+=v[ch[j][c]];
			}
		}
		for(int i=tot;i>=1;--i)
			fo(c,0,25)
			if(!ch[i][c])
				ch[i][c]=ch[f[i]][c];
	}
	void match(){
		int now=0;
		fo(i,1,n){
			int c=t[i]-'a';
			now=ch[now][c];
			cnt[i]=v[now];
		}
	}
}ac[2];//正串一个反串一个
char s[maxn];
signed main(){
	scanf("%s",t+1);n=strlen(t+1);
	cin>>m;
	fo(i,1,m){
		scanf("%s",s+1);
		int len=strlen(s+1);
		ac[0].insert(s);
		reverse(s+1,s+1+len);
		ac[1].insert(s);
	}
	ac[0].getfail();
	ac[1].getfail();
	ac[0].match();
	reverse(t+1,t+1+n);
	ac[1].match();
	reverse(ac[1].cnt+1,ac[1].cnt+1+n);
	long long ans=0;
	fo(i,1,n-1){
		ans+=1ll*ac[0].cnt[i]*ac[1].cnt[i+1];
	}
	cout<<ans<<endl;
}


#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<=(b);++i)
using namespace std;
const int maxn=2e5+99;
char t[maxn];
int n,m;
struct ACAM{
	int v[maxn],cnt[maxn],tot,ch[maxn][26],f[maxn];
	void insert(char*s){
		int len=strlen(s+1);
		int now=0;
		fo(i,1,len){
			int c=s[i]-'a';
			if(!ch[now][c])ch[now][c]=++tot;
			now=ch[now][c];
		}
		++v[now];
	}
	void getfail(){
		queue<int>q;
		fo(i,0,25)if(ch[0][i])q.push(ch[0][i]);
		while(q.size()){
			int r=q.front();q.pop();
			fo(c,0,25){
				if(!ch[r][c])continue;
				q.push(ch[r][c]);
				int j=f[r];
				while(j&&!ch[j][c])j=f[j];
				f[ch[r][c]]=ch[j][c];
				v[ch[r][c]]+=v[ch[j][c]];
			}
		}
		fo(i,1,tot)fo(c,0,25)if(!ch[i][c])ch[i][c]=ch[f[i]][c];
	}
	void match(){
		int now=0;
		fo(i,1,n){
			int c=t[i]-'a';
			now=ch[now][c];
			cnt[i]=v[now];
		}
	}
}ac[2];//正串一个反串一个
char s[maxn];
int main(){
	scanf("%s",t+1);n=strlen(t+1);
	cin>>m;
	fo(i,1,m){
		int len=strlen(s+1);
		scanf("%s",s+1);
		ac[0].insert(s);
		reverse(s+1,s+1+len);
		ac[1].insert(s);
	}
	ac[0].getfail();
	ac[1].getfail();
	ac[0].match();
	reverse(t+1,t+1+n);
	ac[1].match();
	reverse(ac[1].cnt+1,ac[1].cnt+1+n);
	long long ans=0;
	fo(i,1,n-1){
		ans+=1ll*ac[0].cnt[i]*ac[1].cnt[i+1];
	}
	cout<<ans<<endl;
}


#include<bits/stdc++.h>
#define int long long
#define fo(i,a,b) for(int i=(a);i<=(b);++i)
using namespace std;
const int maxn=2e5+99;
char t[maxn];
int n,m;
struct ACAM{
	int v[maxn],cnt[maxn],tot,ch[maxn][26],f[maxn];
	vector<int>g[maxn];
	void insert(char*s){
		int len=strlen(s+1);
		int now=0;
		fo(i,1,len){
			int c=s[i]-'a';
			if(!ch[now][c])ch[now][c]=++tot;
			now=ch[now][c];
		}
		++v[now];
	}
	void dfs(int x){
		for(int y:g[x])v[y]+=v[x],dfs(y);
	}
	void getfail(){
		queue<int>q;
		fo(i,0,25)if(ch[0][i])q.push(ch[0][i]);
		while(q.size()){
			int r=q.front();q.pop();
			fo(c,0,25){
				if(!ch[r][c]){ch[r][c]=ch[f[r]][c];continue;}
				q.push(ch[r][c]);
				int j=f[r];
				while(j&&!ch[j][c])j=f[j];
				f[ch[r][c]]=ch[j][c];
			}
		}
		fo(i,1,tot)g[f[i]].push_back(i);
		dfs(0);
	}
	void match(){
		int now=0;
		fo(i,1,n){
			int c=t[i]-'a';
			now=ch[now][c];
			cnt[i]=v[now];
		}
	}
}ac[2];//正串一个反串一个
char s[maxn];
signed main(){
	scanf("%s",t+1);n=strlen(t+1);
	cin>>m;
	fo(i,1,m){
		scanf("%s",s+1);
		int len=strlen(s+1);
		ac[0].insert(s);
		reverse(s+1,s+1+len);
		ac[1].insert(s);
	}
	ac[0].getfail();
	ac[1].getfail();
	ac[0].match();
	reverse(t+1,t+1+n);
	ac[1].match();
	reverse(ac[1].cnt+1,ac[1].cnt+1+n);
	long long ans=0;
	fo(i,1,n-1){
		ans+=1ll*ac[0].cnt[i]*ac[1].cnt[i+1];
	}
	cout<<ans<<endl;
}