//Equalising by Division
#include<bits/stdc++.h>
using namespace std;
int largest;

int convertToZero(map<int,int> m ,int k)
{
	int steps=0;
	vector<pair<int,int>> v;
	map<int,int> ::iterator it;
	for(it=m.begin();it!=m.end();it++)
	{
		v.push_back({it->first,it->second});

	}
	sort(v.begin(),v.end());
	int eq=0;
	for(int i=0;i<v.size();i++)
	{
		int x = v[i].first;
		int s = 0;
		while(x>0)
		{
			x = x/2;
			s++;
		}
		if(v[i].second>=(k-eq))
		{
			steps = steps + s*(k-eq);
			eq = k;
			return steps;
		}
		else
		{
			steps = steps + s*v[i].second;
			eq+=v[i].second;
		}
	}

	return steps;
}

int check(int mid, vector<pair<int,int>> v, int k, map<int,int> m)
{
	int eq = 0;
	if(m.count(mid))
		eq+=m[mid];
	if(eq>=k)
		return 0;
	int steps = 0;
	vector<int> dp(200000,-1);
	dp[mid] = 0;
	//vector<pair<int,int>> :: iterator it;
	//it = upper_bound(v.begin(),v.end(),make_pair(mid,0));
	int i;
	for( i=0;i<v.size();i++)
	{
		if(v[i].first<=mid)
			continue;

		int temp = v[i].first;
		int s=0;
		while(temp>mid)
		{
			if(dp[temp]!=-1)
			{
				s+=dp[temp];
				break;
			}
			s++;
			temp/=2;
		}

		if(temp==mid)
		{
			dp[v[i].first] =  s;
			if(v[i].second>=(k-eq))
			{
				steps = steps + s*(k-eq);
				return steps;
			}

			else{
				steps = steps + s*v[i].second;
				eq+=v[i].second;
			}
		}
	}

	if(eq>=k)
		return steps;

	return -1;

}

int equaliseByDivision(int n, int k, int a[])
{
	map<int,int> m;
	for(int i=0;i<n;i++)
	{
		m[a[i]]++;
		if(a[i]>largest)
			largest = a[i];
	}
	vector<pair<int,int>> v;
	map<int,int> ::iterator it;
	for(it=m.begin();it!=m.end();it++)
	{
		v.push_back({it->first,it->second});

	}
	sort(v.begin(),v.end());
	//cout<<largest<<"\n";
	int ans = convertToZero(m,k);		//let us say that all the numbers are being converted to zero
	//cout<<"Answer from convert to zero is: "<<ans<<"\n";
	int mid = 1;
	while(mid<=largest)
	{
		//int mid = low + (high-low)/2;
		//Check if mid is the ans
		int temp = check(mid,v,k,m);
		if(temp!=-1)
		{
			ans = min(ans,temp);
		}

		mid++;
	}

	return ans;

}

int main()
{
	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++)
		cin>>a[i];
	largest = 0;
	cout<<equaliseByDivision(n,k,a);
	return 0;
}


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

int equaliseByDivision(int n,int k,int a[])
{
	vector<vector<int> > dp(200001);

	for(int i=0;i<n;i++)
	{
		int x = a[i];
		int s=0;
		while(x>0)
		{
			dp[x].push_back(s);
			x/=2;
			s++;
		}
	}

	int ans = INT_MAX;
	for(int i=0;i<200001;i++)
	{
		if(dp[i].size()<k)
			continue;

		sort(dp[i].begin(),dp[i].end());

		int temp=0;
		for(int j=0;j<k;j++)
		{
			temp+=dp[i][j];
		}
		ans = min(ans,temp);

	}

	return ans;
}

int main()
{
	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++)
		cin>>a[i];
	cout<<equaliseByDivision(n,k,a);
	return 0;
}


//Equalising by Division
#include<bits/stdc++.h>
using namespace std;
int largest;

int convertToZero(map<int,int> m ,int k)
{
	int steps=0;
	vector<pair<int,int>> v;
	map<int,int> ::iterator it;
	for(it=m.begin();it!=m.end();it++)
	{
		v.push_back({it->first,it->second});

	}
	sort(v.begin(),v.end());
	int eq=0;
	for(int i=0;i<v.size();i++)
	{
		int x = v[i].first;
		int s = 0;
		while(x>0)
		{
			x = x/2;
			s++;
		}
		if(v[i].second>=(k-eq))
		{
			steps = steps + s*(k-eq);
			eq = k;
			return steps;
		}
		else
		{
			steps = steps + s*v[i].second;
			eq+=v[i].second;
		}
	}

	return steps;
}

int check(int mid, vector<pair<int,int>> v, int k, map<int,int> m)
{
	int eq = 0;
	if(m.count(mid))
		eq+=m[mid];
	if(eq>=k)
		return 0;
	int steps = 0;
	vector<int> dp(200011,-1);
	dp[mid] = 0;
	vector<pair<int,int>> :: iterator it;
	it = upper_bound(v.begin(),v.end(),make_pair(mid,0));
	int i;
	for( i=it-v.begin();i<v.size();i++)
	{
		if(v[i].first<=mid)
			continue;

		int temp = v[i].first;
		int s=0;
		while(temp>mid)
		{
			if(dp[temp]!=-1)
			{
				s+=dp[temp];
				break;
			}
			s++;
			temp/=2;
		}

		if(temp==mid)
		{
			dp[v[i].first] =  s;
			if(v[i].second>=(k-eq))
			{
				steps = steps + s*(k-eq);
				return steps;
			}

			else{
				steps = steps + s*v[i].second;
				eq+=v[i].second;
			}
		}
	}

	if(eq>=k)
		return steps;

	return -1;

}

int equaliseByDivision(int n, int k, int a[])
{
	map<int,int> m;
	for(int i=0;i<n;i++)
	{
		m[a[i]]++;
		if(a[i]>largest)
			largest = a[i];
	}
	vector<pair<int,int>> v;
	map<int,int> ::iterator it;
	for(it=m.begin();it!=m.end();it++)
	{
		v.push_back({it->first,it->second});

	}
	sort(v.begin(),v.end());
	//cout<<largest<<"\n";
	int ans = convertToZero(m,k);		//let us say that all the numbers are being converted to zero
	//cout<<"Answer from convert to zero is: "<<ans<<"\n";
	int mid = 1;
	while(mid<=largest)
	{
		//int mid = low + (high-low)/2;
		//Check if mid is the ans
		int temp = check(mid,v,k,m);
		if(temp!=-1)
		{
			ans = min(ans,temp);
		}

		mid++;
	}

	return ans;

}

int main()
{
	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++)
		cin>>a[i];
	largest = 0;
	cout<<equaliseByDivision(n,k,a);
	return 0;
}


#include<bits/stdc++.h>
#define YES cout<<"YES"<<"\n"
#define NO cout<<"NO"<<"\n"
#define Yes cout<<"Yes"<<"\n"
#define No cout<<"No"<<"\n"
using namespace std;
typedef pair<int ,int > pa;
int n;
int k;
int a[200007][22];
vector< int > kt[200005];
int  b[(int)1e6];
int main(){

	ios::sync_with_stdio(false);
  	cin.tie(0);
	cin >> n >> k;
	int Max = 0;
	for(int i = 1 ; i <= n ;i++ )
	{
		int x;
		cin >> x;
		b[i] = x;
		Max  = max(Max , b[i]);
		int tmp = x;
		a[tmp][0]=x;
		for(int j = 1; j <= 20 ; j++ )
		{
			tmp/=2;
			a[x][j] = tmp;
		}

	}
	for(int i=1 ; i<= n; i++)
	{
		for(int j=0 ; j <= 20 ; j++ )
		{
			kt[a[b[i]][j]].push_back(j);
		}
	//	cout<<endl;
	}
	int id;
	long long MIN = 1e15;
	for(int i=200004 ; i >=0 ;i --)
	{
		if(kt[i].size() >= k)
		{
			id = i;
			sort(kt[id].begin(),kt[id].end());
			long long ans =0;
			for(int j=0 ; j < k ; j++)
			{
				ans+=kt[id][j];
			}
			MIN = min(MIN,ans);
//			cout<<i<<endl;
		//	break;
		}
	}
	cout<<MIN;

}


#include<bits/stdc++.h>
#define YES cout<<"YES"<<"\n"
#define NO cout<<"NO"<<"\n"
#define Yes cout<<"Yes"<<"\n"
#define No cout<<"No"<<"\n"
using namespace std;
typedef pair<int ,int > pa;
int n;
int k;
int a[200007][22];
vector<int > kt[200005];
int  b[(int)1e6];
int main(){

	ios::sync_with_stdio(false);
  	cin.tie(0);
	cin >> n >> k;
	int Max = 0;
	for(int i = 1 ; i <= n ;i++ )
	{
		int x;
		cin >> x;
		b[i] = x;
		Max  = max(Max , b[i]);
		int tmp = x;
		a[tmp][0]=x;
		for(int j = 1; j <= 20 ; j++ )
		{
			tmp/=2;
			a[x][j] = tmp;
		}

	}
	for(int i=1 ; i<= n; i++)
	{
		for(int j=0 ; j <= 20 ; j++ )
		{
			kt[a[b[i]][j]].push_back(j);
		}
	//	cout<<endl;
	}
	int id;
	for(int i=Max ; i >=0 ;i --)
	{
		if(kt[i].size() >= k)
		{
		//	cout<<i<<endl;
			id = i;
			break;
		}
	}
	sort(kt[id].begin(),kt[id].end());
	long long ans =0;
	for(int i=0 ; i < k ; i++)
	{
		ans+=kt[id][i];
	}
	cout<<ans <<endl;

}


#include<bits/stdc++.h>
#define YES cout<<"YES"<<"\n"
#define NO cout<<"NO"<<"\n"
#define Yes cout<<"Yes"<<"\n"
#define No cout<<"No"<<"\n"
using namespace std;
typedef pair<int ,int > pa;
int n;
int k;
int a[200007][22];
vector<int > kt[200005];
int  b[(int)1e6];
int main(){

	ios::sync_with_stdio(false);
  	cin.tie(0);
	cin >> n >> k;
	int Max = 0;
	for(int i = 1 ; i <= n ;i++ )
	{
		int x;
		cin >> x;
		b[i] = x;
		Max  = max(Max , b[i]);
		int tmp = x;
		a[tmp][0]=x;
		for(int j = 1; j <= 20 ; j++ )
		{
			tmp/=2;
			a[x][j] = tmp;
		}

	}
	for(int i=1 ; i<= n; i++)
	{
		for(int j=0 ; j <= 20 ; j++ )
		{
			kt[a[b[i]][j]].push_back(j);
		}
	//	cout<<endl;
	}
	int id;
	for(int i=Max ; i >=0 ;i --)
	{
		if(kt[i].size() == k)
		{
		//	cout<<i<<endl;
			id = i;
			break;
		}
	}
	long long ans =0;
	for(int i=0 ; i < k ; i++)
	{
		ans+=kt[id][i];
	}
	cout<<ans <<endl;

}


#include<bits/stdc++.h>
#define YES cout<<"YES"<<"\n"
#define NO cout<<"NO"<<"\n"
#define Yes cout<<"Yes"<<"\n"
#define No cout<<"No"<<"\n"
using namespace std;
typedef pair<int ,int > pa;
int n;
int k;
int a[200007][22];
vector< int > kt[200005];
int  b[(int)1e6];
int main(){

	ios::sync_with_stdio(false);
  	cin.tie(0);
	cin >> n >> k;
	int Max = 0;
	for(int i = 1 ; i <= n ;i++ )
	{
		int x;
		cin >> x;
		b[i] = x;
		Max  = max(Max , b[i]);
		int tmp = x;
		a[tmp][0]=x;
		for(int j = 1; j <= 20 ; j++ )
		{
			tmp/=2;
			a[x][j] = tmp;
		}

	}
	for(int i=1 ; i<= n; i++)
	{
		int tmp = b[i];
		for(int j=0 ; j <= 20 ; j++ )
		{

			kt[tmp].push_back(j);
			tmp/=2;

		}
	//	cout<<endl;
	}
	int id;
	long long MIN = 1e15;
	for(int i=200004 ; i >=0 ;i --)
	{
		if(kt[i].size() >= k)
		{
			id = i;
			sort(kt[id].begin(),kt[id].end());
			long long ans =0;
			for(int j=0 ; j < k ; j++)
			{
				ans+=kt[id][j];
			}
			MIN = min(MIN,ans);
//			cout<<i<<endl;
		//	break;
		}
	}
	cout<<MIN;

}


#include<bits/stdc++.h>
#define YES cout<<"YES"<<"\n"
#define NO cout<<"NO"<<"\n"
#define Yes cout<<"Yes"<<"\n"
#define No cout<<"No"<<"\n"
using namespace std;
typedef pair<int ,int > pa;
int n;
int k;
int a[200007][22];
vector< int > kt[200005];
int  b[(int)1e6];
int main(){

	ios::sync_with_stdio(false);
  	cin.tie(0);
	cin >> n >> k;
	int Max = 0;
	for(int i = 1 ; i <= n ;i++ )
	{
		int x;
		cin >> x;
		b[i] = x;
		Max  = max(Max , b[i]);
		int tmp = x;
		a[tmp][0]=x;
		for(int j = 1; j <= 20 ; j++ )
		{
			tmp/=2;
			a[x][j] = tmp;
		}

	}
	for(int i=1 ; i<= n; i++)
	{
		for(int j=0 ; j <= 20 ; j++ )
		{
			kt[a[b[i]][j]].push_back(j);
		}
	//	cout<<endl;
	}
	int id;
	for(int i=Max ; i >=0 ;i --)
	{
		if(kt[i].size() >= k)
		{
			id = i;
//			cout<<i<<endl;
			break;
		}
	}
	sort(kt[id].begin(),kt[id].end());
	long long ans =0;
	for(int i=0 ; i < k ; i++)
	{
		ans+=kt[id][i];
	}
	cout<< ans <<endl;

}


#include<bits/stdc++.h>
#define YES cout<<"YES"<<"\n"
#define NO cout<<"NO"<<"\n"
#define Yes cout<<"Yes"<<"\n"
#define No cout<<"No"<<"\n"
using namespace std;
typedef pair<int ,int > pa;
int n;
int k;
int a[200007][22];
vector< int > kt[200005];
int  b[(int)1e6];
int main(){

	ios::sync_with_stdio(false);
  	cin.tie(0);
	cin >> n >> k;
	int Max = 0;
	for(int i = 1 ; i <= n ;i++ )
	{
		int x;
		cin >> x;
		b[i] = x;
		Max  = max(Max , b[i]);
		int tmp = x;
		a[tmp][0]=x;
		for(int j = 1; j <= 20 ; j++ )
		{
			tmp/=2;
			a[x][j] = tmp;
		}

	}
	for(int i=1 ; i<= n; i++)
	{
		for(int j=0 ; j <= 20 ; j++ )
		{
			kt[a[b[i]][j]].push_back(j);
		}
	//	cout<<endl;
	}
	int id;
	for(int i=200004 ; i >=0 ;i --)
	{
		if(kt[i].size() >= k)
		{
			id = i;
//			cout<<i<<endl;
			break;
		}
	}
	sort(kt[id].begin(),kt[id].end());
	long long ans =0;
	for(int i=0 ; i < k ; i++)
	{
		ans+=kt[id][i];
	}
	cout<< ans <<endl;

}


#include<bits/stdc++.h>
#define YES cout<<"YES"<<"\n"
#define NO cout<<"NO"<<"\n"
#define Yes cout<<"Yes"<<"\n"
#define No cout<<"No"<<"\n"
using namespace std;
typedef pair<int ,int > pa;
int n;
int k;
int a[200007][22];
vector<int > kt[(int)1e6];
int  b[(int)1e6];
int main(){

	ios::sync_with_stdio(false);
  	cin.tie(0);
	cin >> n >> k;
	int Max = 0;
	for(int i = 1 ; i <= n ;i++ )
	{
		int x;
		cin >> x;
		b[i] = x;
		Max  = max(Max , b[i]);
		int tmp = x;
		a[tmp][0]=x;
		for(int j = 1; j <= 20 ; j++ )
		{
			tmp/=2;
			a[x][j] = tmp;
		}

	}
	for(int i=1 ; i<= n; i++)
	{
		for(int j=0 ; j <= 20 ; j++ )
		{
			kt[a[b[i]][j]].push_back(j);
		}
	//	cout<<endl;
	}
	int id;
	for(int i=Max ; i >=0 ;i --)
	{
		if(kt[i].size() >= k)
		{
		//	cout<<i<<endl;
			id = i;	break;
		}
	}
	long long ans =0;
	for(int i=0 ; i < k ; i++)
	{
		ans+=kt[id][i];
	}
	cout<<ans <<endl;

}


#include<bits/stdc++.h>
#define YES cout<<"YES"<<"\n"
#define NO cout<<"NO"<<"\n"
#define Yes cout<<"Yes"<<"\n"
#define No cout<<"No"<<"\n"
using namespace std;
typedef pair<int ,int > pa;
int n;
int k;
int a[200007][22];
vector< int > kt[200005];
int  b[(int)1e6];
int main(){

	ios::sync_with_stdio(false);
  	cin.tie(0);
	cin >> n >> k;
	int Max = 0;
	for(int i = 1 ; i <= n ;i++ )
	{
		int x;
		cin >> x;
		b[i] = x;
		Max  = max(Max , b[i]);
		int tmp = x;
		a[tmp][0]=x;
		for(int j = 1; j <= 20 ; j++ )
		{
			tmp/=2;
			a[x][j] = tmp;
		}

	}
	for(int i=1 ; i<= n; i++)
	{
		int tmp = b[i];
		int j=0;
		while(tmp > 1)
		{

			kt[tmp].push_back(j);
			tmp/=2;
			j++;

		}
		kt[tmp].push_back(j);
	//	cout<<endl;
	}
	int id;
	long long MIN = 1e15;
	for(int i=200004 ; i >=0 ;i --)
	{
		if(kt[i].size() >= k)
		{
			id = i;
			sort(kt[id].begin(),kt[id].end());
			long long ans =0;
			for(int j=0 ; j < k ; j++)
			{
				ans+=kt[id][j];
			}
			MIN = min(MIN,ans);
//			cout<<i<<endl;
		//	break;
		}
	}
	cout<<MIN;

}


#include<bits/stdc++.h>
#define YES cout<<"YES"<<"\n"
#define NO cout<<"NO"<<"\n"
#define Yes cout<<"Yes"<<"\n"
#define No cout<<"No"<<"\n"
using namespace std;
typedef pair<int ,int > pa;
int n;
int k;
int a[200007][22];
vector< int > kt[200005];
int  b[(int)1e6];
int main(){

	ios::sync_with_stdio(false);
  	cin.tie(0);
	cin >> n >> k;
	int Max = 0;
	for(int i = 1 ; i <= n ;i++ )
	{
		int x;
		cin >> x;
		b[i] = x;
		Max  = max(Max , b[i]);
		int tmp = x;
		a[tmp][0]=x;
		for(int j = 1; j <= 20 ; j++ )
		{
			tmp/=2;
			a[x][j] = tmp;
		}

	}
	for(int i=1 ; i<= n; i++)
	{
		for(int j=0 ; j <= 20 ; j++ )
		{
			kt[a[b[i]][j]].push_back(j);
		}
	//	cout<<endl;
	}
	int id;
	for(int i=Max ; i >=0 ;i --)
	{
		if(kt[i].size() >= k)
		{
			id = i;
//			cout<<i<<endl;
			break;
		}
	}

	long long ans =0;
	for(int i=0 ; i < k ; i++)
	{
		ans+=kt[id][i];
	}
	cout<< ans <<endl;

}


#include<bits/stdc++.h>
#define YES cout<<"YES"<<"\n"
#define NO cout<<"NO"<<"\n"
#define Yes cout<<"Yes"<<"\n"
#define No cout<<"No"<<"\n"
using namespace std;
typedef pair<int ,int > pa;
int n;
int k;
int a[200007][22];
vector< int > kt[200005];
int  b[(int)1e6];
int main(){

	ios::sync_with_stdio(false);
  	cin.tie(0);
	cin >> n >> k;
	int Max = 0;
	for(int i = 1 ; i <= n ;i++ )
	{
		int x;
		cin >> x;
		b[i] = x;
		Max  = max(Max , b[i]);
		int tmp = x;
		a[tmp][0]=x;
		for(int j = 1; j <= 20 ; j++ )
		{
			tmp/=2;
			a[x][j] = tmp;
		}

	}
	for(int i=1 ; i<= n; i++)
	{
		for(int j=0 ; j <= 20 ; j++ )
		{
			kt[a[b[i]][j]].push_back(j);
		}
	//	cout<<endl;
	}
	int id;
	long long MIN = 1e15;
	for(int i=200004 ; i >=0 ;i --)
	{
		if(kt[i].size() >= k)
		{
			id = i;	sort(kt[id].begin(),kt[id].end());
			long long ans =0;
			for(int i=0 ; i < k ; i++)
			{
				ans+=kt[id][i];
			}
			MIN = min(MIN,ans);
//			cout<<i<<endl;
		//	break;
		}
	}
	cout<<MIN;

}


#include <bits/stdc++.h>
using namespace std;
#define len (int)(2e5 + 5)
int main()
{
    int k, n, i, ans = INT_MAX, x, c, j;
    cin >> n >> k;
    vector<int> a(n);
    for (i = 0; i < n; i++)
        cin >> a[i];

    vector<int> v[len];

    for (i = 0; i < n; i++)
    {
        x = a[i];
        c = 0;
        while (x)
        {
            v[x].push_back(c);
            x /= 2;
            c++;
        }
    }

    for (i = 0; i <= len - 1; i++)
    {
        sort(v[i].begin(), v[i].end());
        if ((int)v[i].size() < k)
            continue;

        c = 0;
        for (j = 0; j <= k - 1; j++)
            c += v[i][j];

        ans = min(ans, c);
    }
    cout << ans << '\n';
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define len (int)(2e5 + 1)
int main()
{
    int k, n, i, ans = INT_MAX, x, c, j;
    cin >> n >> k;
    vector<int> a(n);
    for (i = 0; i < n; i++)
        cin >> a[i];

    vector<int> v[len];

    for (i = 0; i < n; i++)
    {
        x = a[i];
        c = 0;
        while (x)
        {
            v[x].push_back(c);
            x /= 2;
            c++;
        }
    }

    for (i = 1; i <= len - 1; i++)
    {
        sort(v[i].begin(), v[i].end());
        if ((int)v[i].size() < k)
            continue;

        c = 0;
        for (j = 0; j <= k - 1; j++)
            c += v[i][j];

        ans = min(ans, c);
    }
    cout << ans << '\n';
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define len (int)(2e5 + 1)
int main()
{
    int k, n, i, ans = INT_MAX, x, c, j;
    cin >> n >> k;
    vector<int> a(n);
    for (i = 0; i < n; i++)
        cin >> a[i];

    vector<int> v[len];

    for (i = 0; i < n; i++)
    {
        x = a[i];
        c = 0;
        while (x != 1)
        {
            v[x].push_back(c);
            x /= 2;
            c++;
        }
    }

    for (i = 1; i <= len - 1; i++)
    {
        sort(v[i].begin(), v[i].end());
        if ((int)v[i].size() < k)
            continue;

        c = 0;
        for (j = 0; j <= k - 1; j++)
            c += v[i][j];

        ans = min(ans, c);
    }
    cout << ans << '\n';
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define len (int)(2e5 + 5)
int main()
{
    int k, n, i, ans = 0, x, c, j;
    cin >> n >> k;
    vector<int> a(n);
    for (i = 0; i < n; i++)
        cin >> a[i];

    vector<int> v[len];

    for (i = 0; i < n; i++)
    {
        x = a[i];
        c = 0;
        while (x)
        {
            v[x].push_back(c);
            x /= 2;
            c++;
        }
        ans += c;
    }

    for (i = 1; i <= len - 1; i++)
    {
        sort(v[i].begin(), v[i].end());
        if ((int)v[i].size() < k)
            continue;

        c = 0;
        for (j = 0; j <= k - 1; j++)
            c += v[i][j];

        ans = min(ans, c);
    }
    cout << ans << '\n';
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define size 2003

lli board[size][size],sum1[5003],sum2[5003];
int main()
{
    memset(sum1,0,sizeof(sum1));
    memset(sum2,0,sizeof(sum2));
    int i,n,j;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
	for(j=1;j<=n;j++)
	{
	    scanf("%lld",&board[i][j]);
	    sum1[i+j]+=board[i][j];
	    sum2[i-j+n]+=board[i][j];
	}
    }
    int temp=0;
    lli max[2],x[2],y[2];
    max[0]=0;
    max[1]=0;
    for(i=1;i<=n;i++)
    {
	for(j=1;j<=n;j++)
	{
	    lli tot=sum1[i+j]+sum2[i-j+n]-board[i][j];
	    int in=(i+j)%2;
	    if(max[in]<=tot)
	    {
		max[in]=tot;
		x[in]=i;
		y[in]=j;
	    }
	}
    }
    cout<<max[0]+max[1]<<endl;
    printf("%lld %lld %lld %lld\n",x[0],y[0],x[1],y[1]);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define size 2003

lli board[size][size],sum1[5003],sum2[5003];
int main()
{
    memset(sum1,0,sizeof(sum1));
    memset(sum2,0,sizeof(sum2));
    int i,n,j;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
	for(j=1;j<=n;j++)
	{
	    scanf("%lld",&board[i][j]);
	    sum1[i+j]+=board[i][j];
	    sum2[i-j+n]+=board[i][j];
	}
    }
    int temp=0;
    lli max[2],x[2],y[2];
    max[0]=0;
    max[1]=0;
    for(i=1;i<=n;i++)
    {
	for(j=1;j<=n;j++)
	{
	    int tot=sum1[i+j]+sum2[i-j+n]-board[i][j];
	    int in=(i+j)%2;
	    if(max[in]<=tot)
	    {
		max[in]=tot;
		x[in]=i;
		y[in]=j;
	    }
	}
    }
    cout<<max[0]+max[1]<<endl;
    printf("%lld %lld %lld %lld\n",x[0],y[0],x[1],y[1]);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define size 2003

lli board[size][size],sum1[5003],sum2[5003];
int main()
{
    memset(sum1,0,sizeof(sum1));
    memset(sum2,0,sizeof(sum2));
    int i,n,j;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
	for(j=1;j<=n;j++)
	{
	    scanf("%lld",&board[i][j]);
	    sum1[i+j]+=board[i][j];
	    sum2[i-j+n]+=board[i][j];
	}
    }
    lli max[2]={0},x[2],y[2];
    for(i=1;i<=n;i++)
    {
	for(j=1;j<=n;j++)
	{
	    int tot=sum1[i+j]+sum2[i-j+n]-board[i][j];
	    int in=(i+j)%2;
	    if(max[in]<=tot)
	    {
		max[in]=tot;
		x[in]=i;
		y[in]=j;
	    }
	}
    }
    cout<<max[0]+max[1]<<endl;
    printf("%lld %lld %lld %lld\n",x[0],y[0],x[1],y[1]);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define size 2003

lli board[size][size],sum1[size],sum2[size];
int main()
{
    int i,n,j;
    cin>>n;
    for(i=1;i<=n;i++)
    {
	for(j=1;j<=n;j++)
	{
	    cin>>board[i][j];
	    sum1[i+j]+=board[i][j];
	    sum2[i-j+n]+=board[i][j];
	}
    }
    lli em=-1,om=-1,ep1,ep2,op1,op2;
    for(i=1;i<=n;i++)
    {
	for(j=1;j<=n;j++)
	{
	    int tot=sum1[i+j]+sum2[i-j+n]-board[i][j];
	    if((i+j)%2==0)
	    {
		if(tot>em)
		{
		    ep1=i;
		    ep2=j;
		    em=tot;
		}
	    }
	    else
	    {
		if(tot>om)
		{
		    op1=i;
		    op2=j;
		    om=tot;
		}
	    }
	}
    }
    cout<<em+om<<endl;
    printf("%lld %lld %lld %lld\n",ep1,ep2,op1,op2);
    return 0;
}


#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#define ll long long
using namespace std;
ll hash(ll ,ll );
ll a[2005][2005],d[2005][2005],v[4005],w[4005];
ll n;
int main()
{
    ll i,j,k,sum,p,q,l;
    cin>>n;
    for(i=0;i<2*n;i++)
    {
        w[i]=0;
        v[i]=0;
    }
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            cin>>a[i][j];
            v[j-i+n-1]=v[j-i+n-1]+a[i][j];
            w[i+j]=w[i+j]+a[i][j];
        }
    }
    ll ans,ans1,ans2,r,s,x;
    ans1=-1; ans2=-1;
    for(i=0;i<n;i++)
    {
        if((i%2)==0)
            j=0;
        else
            j=1;
        for(j;j<n;j+=2)
        {
            x=hash(i,j);
            if(x>ans1)
            {
                ans1=x;
                p=i; q=j;
            }
        }
    }
    for(i=0;i<n;i++)
    {
        if((i%2)!=0)
            j=0;
        else
            j=1;
        for(j;j<n;j+=2)
        {
            x=hash(i,j);
            if(x>ans2)
            {
                ans2=x;
                r=i; s=j;
            }
        }
    }
    ans=ans1+ans2;
    cout<<ans<<endl;
    cout<<p+1<<" "<<q+1<<" "<<r+1<<" "<<s+1<<endl;
    return 0;
}
ll hash(ll i,ll j)
{
    return v[i+j]+w[j-i+n-1]-a[i][j];
}


#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#define ll long long
using namespace std;
ll has(ll ,ll );
ll a[2005][2005],d[2005][2005],v[4005],w[4005];
ll n;
int main()
{
    ll i,j,k,sum,p,q,l;
    cin>>n;
    for(i=0;i<2*n;i++)
    {
        w[i]=0;
        v[i]=0;
    }
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            cin>>a[i][j];
            v[j-i+n-1]+=a[i][j];
            w[i+j]+=a[i][j];
        }
    }
    ll ans,ans1,ans2,r,s,x;
    ans1=-1; ans2=-1;
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            x=has(i,j);
            if(((i+j)%2)==0)
            {
                if(x>ans1)
                {
                    ans1=x;
                    p=i; q=j;
                }
            }
            else
            {
                x=has(i,j);
                if(x>ans2)
                {
                    ans2=x;
                    r=i; s=j;
                }
            }
        }
    }
    cout<<ans1+ans2<<endl;
    cout<<p+1<<" "<<q+1<<" "<<r+1<<" "<<s+1<<endl;
    return 0;
}
ll has(ll i,ll j)
{
    return v[j-i+n-1]+w[j+i]-a[i][j];
}


#include<stdio.h>
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#define ll long long
using namespace std;
ll a[2005][2005],v[4005],w[4005];
int n;
ll has1(int i,int j)
{
    return j-i+n-1;
}
ll has2(int i,int j)
{
    return i+j-1;
}
int main()
{
    int i,j,k,p,q;
    cin>>n;
    for(i=0;i<2*n;i++)
    {
        w[i]=0;
        v[i]=0;
    }
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            cin>>a[i][j];
            v[has1(i,j)]+=a[i][j];
            w[has2(i,j)]+=a[i][j];
        }
    }
    ll ans,ans1,ans2,r,s,x;
    ans1=-1; ans2=-1;
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            x=v[has1(i,j)]+w[has2(i,j)]-a[i][j];
            if(((i+j)%2)==0)
            {
                if(x>ans1)
                {
                    ans1=x;
                    p=i;
                    q=j;
                }
            }
            else
            {
                if(x>ans2)
                {
                    ans2=x;
                    r=i;
                    s=j;
                }
            }
        }
    }
    cout<<ans1+ans2<<endl;
    cout<<p+1<<" "<<q+1<<" "<<r+1<<" "<<s+1<<endl;
    return 0;
}


#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#define ll long long
using namespace std;
ll hash(ll ,ll );
ll a[2005][2005],d[2005][2005],v[4005],w[4005];
ll n;
int main()
{
    ll i,j,k,sum,p,q,l;
    cin>>n;
    for(i=0;i<2*n;i++)
    {
        w[i]=0;
        v[i]=0;
    }
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            cin>>a[i][j];
            v[j-i+n-1]=v[j-i+n-1]+a[i][j];
            w[i+j]=w[i+j]+a[i][j];
        }
    }
    ll ans,ans1,ans2,r,s,x;
    ans1=-1; ans2=-1;
    for(i=0;i<n;i++)
    {
        if((i%2)==0)
            j=0;
        else
            j=1;
        for(j;j<n;j+=2)
        {
            x=hash(i,j);
            if(x>ans1)
            {
                ans1=x;
                p=i; q=j;
            }
        }
    }
    for(i=0;i<n;i++)
    {
        if((i%2)!=0)
            j=0;
        else
            j=1;
        for(j;j<n;j+=2)
        {
            x=hash(i,j);
            if(x>ans2)
            {
                ans2=x;
                r=i; s=j;
            }
        }
    }
    ans=ans1+ans2;
    cout<<ans<<endl;
    cout<<p+1<<" "<<q+1<<" "<<r+1<<" "<<s+1<<endl;
    return 0;
}
ll hash(ll i,ll j)
{
    return v[j-i+n-1]+w[j+i]-a[i][j];
}


#include<stdio.h>
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#define ll long long
using namespace std;
ll a[2005][2005],v[4005],w[4005];
int n;
ll has1(int i,int j)
{
    return j-i+n-1;
}
ll has2(int i,int j)
{
    return i+j-1;
}
int main()
{
    int i,j,k,p,q;
    scanf("%d",&n);
    for(i=0;i<2*n;i++)
    {
        w[i]=0;
        v[i]=0;
    }
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            scanf("%d",&a[i][j]);
            v[has1(i,j)]+=a[i][j];
            w[has2(i,j)]+=a[i][j];
        }
    }
    ll ans,ans1,ans2,r,s,x;
    ans1=-1; ans2=-1;
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            x=v[has1(i,j)]+w[has2(i,j)]-a[i][j];
            if(((i+j)%2)==0)
            {
                if(x>ans1)
                {
                    ans1=x;
                    p=i;
                    q=j;
                }
            }
            else
            {
                if(x>ans2)
                {
                    ans2=x;
                    r=i;
                    s=j;
                }
            }
        }
    }
    printf("%I64d\n",ans1+ans2);
    cout<<p+1<<" "<<q+1<<" "<<r+1<<" "<<s+1<<endl;
    return 0;
}


#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#define ll long long
using namespace std;
ll has(ll ,ll );
ll a[2005][2005],v[4005],w[4005];
ll n;
ll has(ll i,ll j)
{
    return v[j-i+n-1]+w[j+i]-a[i][j];
}
int main()
{
    ll i,j,k,sum,p,q,l;
    cin>>n;
    for(i=0;i<2*n;i++)
    {
        w[i]=0;
        v[i]=0;
    }
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            cin>>a[i][j];
            v[j-i+n-1]+=a[i][j];
            w[i+j]+=a[i][j];
        }
    }
    ll ans,ans1,ans2,r,s,x;
    ans1=-1; ans2=-1;
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            x=has(i,j);
            if(((i+j)%2)==0)
            {
                if(x>ans1)
                {
                    ans1=x;
                    p=i;
                    q=j;
                }
            }
            else
            {
                if(x>ans2)
                {
                    ans2=x;
                    r=i;
                    s=j;
                }
            }
        }
    }
    cout<<ans1+ans2<<endl;
    cout<<p+1<<" "<<q+1<<" "<<r+1<<" "<<s+1<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int n;
ll chess[2005][2005];
ll d1[4010];
ll d2[4010];
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        for(ll j=1;j<=n;j++){
            cin>>chess[i][j];
            d1[i-j+n]+=chess[i][j];
            d2[i+j]+=chess[i][j];
        }
    }
    int x1=-1,y1=-1,x2=-1,y2=-1;
    ll maxx1=INT_MIN,maxx2=INT_MIN;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            chess[i][j]=d1[i-j+n]+d2[i+j]-chess[i][j];
            if((i%2==0&&j%2==0)||(i%2&&j%2))
            {
                if(maxx1<chess[i][j])
                {
                    maxx1=chess[i][j];
                    x1=i;
                    y1=j;
                }
            }
            else
            {
                if(maxx2<chess[i][j])
                {
                    maxx2=chess[i][j];
                    x2=i;
                    y2=j;
                }
            }
        }
    }
    cout<<maxx1+maxx2<<endl;
    cout<<x1<<" "<<y1<<" "<<x2<<" "<<y2<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll n;
ll chess[2005][2005];
ll sum1[2005][2005];
ll sum2[2005][2005];
ll sum3[2005][2005];
ll sum4[2005][2005];
ll func1(ll i,ll j)
{
    if(i>n||j>n||i<1||j<1)
        return 0;
    if(sum1[i][j]!=-1) return sum1[i][j];
    return sum1[i][j]=chess[i][j]+func1(i+1,j+1);
}
ll func2(ll i,ll j)
{
    if(i>n||j>n||i<1||j<1)
        return 0;
    if(sum2[i][j]!=-1) return sum2[i][j];
    return sum2[i][j]=chess[i][j]+func2(i-1,j-1);
}
ll func3(ll i,ll j)
{
    if(i>n||j>n||i<1||j<1)
        return 0;
    if(sum3[i][j]!=-1) return sum3[i][j];
    return sum3[i][j]=chess[i][j]+func3(i-1,j+1);
}
ll func4(ll i,ll j)
{
    if(i>n||j>n||i<1||j<1)
        return 0;
    if(sum4[i][j]!=-1) return sum4[i][j];
    return sum4[i][j]=chess[i][j]+func4(i+1,j-1);
}
int main()
{
    cin>>n;
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=n;j++)
            cin>>chess[i][j];
    }
   // cout<<endl;
    memset(sum1,-1,sizeof sum1);
    memset(sum2,-1,sizeof sum2);
    memset(sum3,-1,sizeof sum3);
    memset(sum4,-1,sizeof sum4);
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=n;j++)
        {
            if(sum1[i][j]==-1)
            {
                func1(i,j);
            }
            if(sum2[i][j]==-1)
            {
                func2(i,j);
            }
            if(sum3[i][j]==-1)
            {
                func3(i,j);
            }
            if(sum4[i][j]==-1)
            {
                func4(i,j);
            }
        }
    }
   /* for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=n;j++)
        {
            cout<<sum1[i][j]<<" ";
        }
        cout<<endl;
    }
    cout<<endl;
     for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=n;j++)
        {
            cout<<sum2[i][j]<<" ";
        }
        cout<<endl;
    }
    cout<<endl;
     for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=n;j++)
        {
            cout<<sum3[i][j]<<" ";
        }
        cout<<endl;
    }
    cout<<endl;
     for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=n;j++)
        {
            cout<<sum4[i][j]<<" ";
        }
        cout<<endl;
    }*/
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=n;j++)
        {
            chess[i][j]=sum1[i][j]+sum2[i][j]+sum3[i][j]+sum4[i][j]-3*chess[i][j];
       //     cout<<chess[i][j]<<" ";
        }
        //cout<<endl;
    }
    ll x1=-1,y1=-1,x2=-1,y2=-1;
    ll maxx1=INT_MIN,maxx2=INT_MIN;
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=n;j++)
        {
            if((i%2==0&&j%2==0)||(i%2&&j%2))
            {
                if(maxx1<chess[i][j])
                {
                    maxx1=chess[i][j];
                    x1=i;
                    y1=j;
                }
            }
            else
            {
                if(maxx2<chess[i][j])
                {
                    maxx2=chess[i][j];
                    x2=i;
                    y2=j;
                }
            }
        }
    }
    cout<<maxx1+maxx2<<endl;
    cout<<x1<<" "<<y1<<" "<<x2<<" "<<y2<<endl;
    return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <climits>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
#define REP(i,n) for(int i=0; i<n; i++)
#define FOR(i,st,end) for(int i=st;i<end;i++)
#define db(x) cout << (#x) << " = " << x << endl;
#define mp make_pair
#define pb push_back
#define MAX 100005
typedef long long int ll;

ll secondary[4001];
ll primary[4001];
pair<int,int> evenIndex;
pair<int,int> oddIndex;
ll value[2];

	int arr[2001][2001];
//value 0 denotes even
//value 1 denotes odd

int main(){
	memset(value,-1,sizeof value);
	int n;
	cin>>n;
	REP(i,n){
		REP(j,n){
			scanf("%d",&arr[i][j]);
			secondary[i+j]+=arr[i][j];
			primary[i-j+n-1]+=arr[i][j];
		}
	}

	ll candidate;
	REP(i,n){
		REP(j,n){
			candidate=secondary[i+j]+primary[i-j+n-1]-arr[i][j];

			if((i+j)&1){
				if(candidate>value[1]){
					value[1]=candidate;
					oddIndex.first=i;
					oddIndex.second=j;
				}

			}
			else{
				if(candidate>value[0]){
					value[0]=candidate;
					evenIndex.first=i;
					evenIndex.second=j;
				}
			}

		}
	}
	cout<<value[0]+value[1]<<endl;
	if(value[0]>value[1]){
		cout<<evenIndex.first+1<<" "<<evenIndex.second+1<<" ";
		cout<<oddIndex.first+1<<" "<<oddIndex.second+1<<endl;
	}
	else{
		cout<<oddIndex.first+1<<" "<<oddIndex.second+1<<" ";
		cout<<evenIndex.first+1<<" "<<evenIndex.second+1<<endl;
	}

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll n;
ll chess[2005][2005];
ll sum1[2005][2005];
ll sum2[2005][2005];
void func1(ll i,ll j,ll &s)
{
    if(i>n||j>n||i<1||j<1)
        return;
    s+=chess[i][j];
    func1(i+1,j+1,s);
    sum1[i][j]=s;
}
void func2(ll i,ll j,ll &s)
{
    if(i>n||j>n||i<1||j<1)
        return;
    s+=chess[i][j];
    func2(i+1,j-1,s);
    sum2[i][j]=s;
}
int main()
{
    cin>>n;
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=n;j++)
            cin>>chess[i][j];
    }
    ll s;
    for(ll i=1;i<=n;i++)
    {
        s=0;
        func1(1,i,s);
        s=0;
        func1(i,1,s);
        s=0;
        func2(1,i,s);
        s=0;
        func2(i,n,s);
    }
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=n;j++)
        {
            chess[i][j]=sum1[i][j]+sum2[i][j]-chess[i][j];
       //     cout<<chess[i][j]<<" ";
        }
        //cout<<endl;
    }
    ll x1=-1,y1=-1,x2=-1,y2=-1;
    ll maxx1=INT_MIN,maxx2=INT_MIN;
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=n;j++)
        {
            if((i%2==0&&j%2==0)||(i%2&&j%2))
            {
                if(maxx1<chess[i][j])
                {
                    maxx1=chess[i][j];
                    x1=i;
                    y1=j;
                }
            }
            else
            {
                if(maxx2<chess[i][j])
                {
                    maxx2=chess[i][j];
                    x2=i;
                    y2=j;
                }
            }
        }
    }
    cout<<maxx1+maxx2<<endl;
    cout<<x1<<" "<<y1<<" "<<x2<<" "<<y2<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll n;
ll chess[2005][2005];
ll sum1[2005][2005];
ll sum2[2005][2005];
ll sum3[2005][2005];
ll sum4[2005][2005];
ll func1(ll i,ll j)
{
    if(i>n||j>n||i<1||j<1)
        return 0;
    if(sum1[i][j]!=-1) return sum1[i][j];
    return sum1[i][j]=chess[i][j]+func1(i+1,j+1);
}
ll func2(ll i,ll j)
{
    if(i>n||j>n||i<1||j<1)
        return 0;
    if(sum2[i][j]!=-1) return sum2[i][j];
    return sum2[i][j]=chess[i][j]+func2(i-1,j-1);
}
ll func3(ll i,ll j)
{
    if(i>n||j>n||i<1||j<1)
        return 0;
    if(sum3[i][j]!=-1) return sum3[i][j];
    return sum3[i][j]=chess[i][j]+func3(i-1,j+1);
}
ll func4(ll i,ll j)
{
    if(i>n||j>n||i<1||j<1)
        return 0;
    if(sum4[i][j]!=-1) return sum4[i][j];
    return sum4[i][j]=chess[i][j]+func4(i+1,j-1);
}
int main()
{
    cin>>n;
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=n;j++)
            cin>>chess[i][j];
    }
   // cout<<endl;
    memset(sum1,-1,sizeof sum1);
    memset(sum2,-1,sizeof sum2);
    memset(sum3,-1,sizeof sum3);
    memset(sum4,-1,sizeof sum4);
    for(ll i=1;i<=n;i++)
    {
        func1(1,i);
        func4(1,i);
    }
    for(ll i=1;i<=n;i++)
    {
        func2(i,n);
        func4(i,n);
    }
    for(ll i=1;i<=n;i++)
    {
        func2(n,i);
        func3(n,i);
    }
    for(ll i=1;i<=n;i++)
    {
        func1(i,1);
        func3(i,1);
    }
   /* for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=n;j++)
        {
            cout<<sum1[i][j]<<" ";
        }
        cout<<endl;
    }
    cout<<endl;
     for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=n;j++)
        {
            cout<<sum2[i][j]<<" ";
        }
        cout<<endl;
    }
    cout<<endl;
     for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=n;j++)
        {
            cout<<sum3[i][j]<<" ";
        }
        cout<<endl;
    }
    cout<<endl;
     for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=n;j++)
        {
            cout<<sum4[i][j]<<" ";
        }
        cout<<endl;
    }*/
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=n;j++)
        {
            chess[i][j]=sum1[i][j]+sum2[i][j]+sum3[i][j]+sum4[i][j]-3*chess[i][j];
       //     cout<<chess[i][j]<<" ";
        }
        //cout<<endl;
    }
    ll x1=-1,y1=-1,x2=-1,y2=-1;
    ll maxx1=INT_MIN,maxx2=INT_MIN;
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=n;j++)
        {
            if((i%2==0&&j%2==0)||(i%2&&j%2))
            {
                if(maxx1<chess[i][j])
                {
                    maxx1=chess[i][j];
                    x1=i;
                    y1=j;
                }
            }
            else
            {
                if(maxx2<chess[i][j])
                {
                    maxx2=chess[i][j];
                    x2=i;
                    y2=j;
                }
            }
        }
    }
    cout<<maxx1+maxx2<<endl;
    cout<<x1<<" "<<y1<<" "<<x2<<" "<<y2<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int n;
ll chess[2005][2005];
ll d1[4010];
ll d2[4010];
void func1(int i,int j,ll &s)
{
    int x=i,y=j;
    while(i<=n&&j<=n)
    {
        s+=chess[i][j];
        i+=1;
        j+=1;
    }
    d1[x-y+n]=s;
}
void func2(int i,int j,ll &s)
{
    int x=i,y=j;
    while(i<=n&&j<=n)
    {
        s+=chess[i][j];
        i+=1;
        j-=1;
    }
    d2[x+y]=s;
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        for(ll j=1;j<=n;j++)
            cin>>chess[i][j];
    }
    ll s;
    for(int i=1;i<=n;i++)
    {
        s=0;
        func1(1,i,s);
        s=0;
        func1(i,1,s);
        s=0;
        func2(1,i,s);
        s=0;
        func2(i,n,s);
    }
    int x1=-1,y1=-1,x2=-1,y2=-1;
    ll maxx1=INT_MIN,maxx2=INT_MIN;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            chess[i][j]=d1[i-j+n]+d2[i+j]-chess[i][j];
            if((i%2==0&&j%2==0)||(i%2&&j%2))
            {
                if(maxx1<chess[i][j])
                {
                    maxx1=chess[i][j];
                    x1=i;
                    y1=j;
                }
            }
            else
            {
                if(maxx2<chess[i][j])
                {
                    maxx2=chess[i][j];
                    x2=i;
                    y2=j;
                }
            }
        }
    }
    cout<<maxx1+maxx2<<endl;
    cout<<x1<<" "<<y1<<" "<<x2<<" "<<y2<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int n;
ll chess[2005][2005];
ll sum1[2005][2005];
ll sum2[2005][2005];
void func1(int i,int j,ll &s)
{
    if(i>n||j>n||i<1||j<1)
        return;
    s+=chess[i][j];
    func1(i+1,j+1,s);
    sum1[i][j]=s;
}
void func2(int i,int j,ll &s)
{
    if(i>n||j>n||i<1||j<1)
        return;
    s+=chess[i][j];
    func2(i+1,j-1,s);
    sum2[i][j]=s;
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        for(ll j=1;j<=n;j++)
            cin>>chess[i][j];
    }
    ll s;
    for(int i=1;i<=n;i++)
    {
        s=0;
        func1(1,i,s);
        s=0;
        func1(i,1,s);
        s=0;
        func2(1,i,s);
        s=0;
        func2(i,n,s);
    }
    int x1=-1,y1=-1,x2=-1,y2=-1;
    ll maxx1=INT_MIN,maxx2=INT_MIN;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            chess[i][j]=sum1[i][j]+sum2[i][j]-chess[i][j];
            if((i%2==0&&j%2==0)||(i%2&&j%2))
            {
                if(maxx1<chess[i][j])
                {
                    maxx1=chess[i][j];
                    x1=i;
                    y1=j;
                }
            }
            else
            {
                if(maxx2<chess[i][j])
                {
                    maxx2=chess[i][j];
                    x2=i;
                    y2=j;
                }
            }
        }
    }
    cout<<maxx1+maxx2<<endl;
    cout<<x1<<" "<<y1<<" "<<x2<<" "<<y2<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll n;
ll chess[2005][2005];
ll sum1[2005][2005];
ll sum2[2005][2005];
void func1(ll i,ll j,ll &s)
{
    if(i>n||j>n||i<1||j<1)
        return;
    s+=chess[i][j];
    func1(i+1,j+1,s);
    sum1[i][j]=s;
}
void func2(ll i,ll j,ll &s)
{
    if(i>n||j>n||i<1||j<1)
        return;
    s+=chess[i][j];
    func2(i+1,j-1,s);
    sum2[i][j]=s;
}
int main()
{
    cin>>n;
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=n;j++)
            cin>>chess[i][j];
    }
    ll s;
    for(ll i=1;i<=n;i++)
    {
        s=0;
        func1(1,i,s);
        s=0;
        func1(i,1,s);
        s=0;
        func2(1,i,s);
        s=0;
        func2(i,n,s);
    }
    ll x1=-1,y1=-1,x2=-1,y2=-1;
    ll maxx1=INT_MIN,maxx2=INT_MIN;
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=n;j++)
        {
            chess[i][j]=sum1[i][j]+sum2[i][j]-chess[i][j];
            if((i%2==0&&j%2==0)||(i%2&&j%2))
            {
                if(maxx1<chess[i][j])
                {
                    maxx1=chess[i][j];
                    x1=i;
                    y1=j;
                }
            }
            else
            {
                if(maxx2<chess[i][j])
                {
                    maxx2=chess[i][j];
                    x2=i;
                    y2=j;
                }
            }
        }
    }
    cout<<maxx1+maxx2<<endl;
    cout<<x1<<" "<<y1<<" "<<x2<<" "<<y2<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int n;
ll chess[2005][2005];
ll sum1[2005][2005];
ll sum2[2005][2005];
/*void func1(int i,int j,ll &s)
{
    if(i>n||j>n||i<1||j<1)
        return;
    s+=chess[i][j];
    func1(i+1,j+1,s);
    sum1[i][j]=s;
}
void func2(int i,int j,ll &s)
{
    if(i>n||j>n||i<1||j<1)
        return;
    s+=chess[i][j];
    func2(i+1,j-1,s);
    sum2[i][j]=s;
}*/
void func1(int i,int j,ll &s)
{
    int x=i,y=j;
    while(i<=n&&j<=n)
    {
        s+=chess[i][j];
        i+=1;
        j+=1;
    }
    i=x;
    j=y;
    while(i<=n&&j<=n)
    {
        sum1[i][j]=s;
        i+=1;
        j+=1;
    }
}
void func2(int i,int j,ll &s)
{
    int x=i,y=j;
    while(i<=n&&j<=n)
    {
        s+=chess[i][j];
        i+=1;
        j-=1;
    }
    i=x;
    j=y;
    while(i<=n&&j<=n)
    {
        sum2[i][j]=s;
        i+=1;
        j-=1;
    }
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        for(ll j=1;j<=n;j++)
            cin>>chess[i][j];
    }
    ll s;
    for(int i=1;i<=n;i++)
    {
        s=0;
        func1(1,i,s);
        s=0;
        func1(i,1,s);
        s=0;
        func2(1,i,s);
        s=0;
        func2(i,n,s);
    }
    int x1=-1,y1=-1,x2=-1,y2=-1;
    ll maxx1=INT_MIN,maxx2=INT_MIN;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            chess[i][j]=sum1[i][j]+sum2[i][j]-chess[i][j];
            if((i%2==0&&j%2==0)||(i%2&&j%2))
            {
                if(maxx1<chess[i][j])
                {
                    maxx1=chess[i][j];
                    x1=i;
                    y1=j;
                }
            }
            else
            {
                if(maxx2<chess[i][j])
                {
                    maxx2=chess[i][j];
                    x2=i;
                    y2=j;
                }
            }
        }
    }
    cout<<maxx1+maxx2<<endl;
    cout<<x1<<" "<<y1<<" "<<x2<<" "<<y2<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int n;
ll chess[2005][2005];
ll d1[4010];
ll d2[4010];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++){
           scanf("%I64d ",&chess[i][j]);
            d1[i-j+n]+=chess[i][j];
            d2[i+j]+=chess[i][j];
        }
    }
    int x1=-1,y1=-1,x2=-1,y2=-1;
    ll maxx1=INT_MIN,maxx2=INT_MIN;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            chess[i][j]=d1[i-j+n]+d2[i+j]-chess[i][j];
            if((i%2==0&&j%2==0)||(i%2&&j%2))
            {
                if(maxx1<chess[i][j])
                {
                    maxx1=chess[i][j];
                    x1=i;
                    y1=j;
                }
            }
            else
            {
                if(maxx2<chess[i][j])
                {
                    maxx2=chess[i][j];
                    x2=i;
                    y2=j;
                }
            }
        }
    }
    printf("%I64d\n",maxx1+maxx2);
    printf("%d %d %d %d\n",x1,y1,x2,y2);
    return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <functional>
#include <map>
#include <stdio.h>
#include <inttypes.h>

using namespace std;

int d1_coord(int n, int x, int y) {
    return x + y;
}

int d2_coord(int n, int x, int y) {
    return n - 1 - y + x;
}

int abs(int x) {
    return x > 0 ? x : -x;
}

int main()
{
    int n;
    cin >> n;
    int *data = new int[n * n];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            cin >> data[i * n + j];

    int64_t *d1 = new int64_t[2 * n - 1], *d2 = new int64_t[2 * n - 1];

    // d1
    for (int i = 0; i < n; i++) {
        int64_t sum = 0L, x = i, y = 0;
        while (x >= 0 && y < n) {
            sum += data[x * n + y];
            x--, y++;
        }
        d1[i] = sum;
    }
    for (int i = 1; i < n; i++) {
        int64_t sum = 0, x = n - 1, y = i;
        while (x >= 0 && y < n) {
            sum += data[x * n + y];
            x--, y++;
        }
        d1[n - 1 + i] = sum;
    }

    // d2
    for (int i = 0; i < n; i++) {
        int64_t sum = 0, x = 0, y = n - 1 - i;
        while (x < n && y < n) {
            sum += data[x * n + y];
            x++, y++;
        }
        d2[i] = sum;
    }
    for (int i = 1; i < n; i++) {
        int64_t sum = 0, x = i, y = 0;
        while (x < n && y < n) {
            sum += data[x * n + y];
            x++, y++;
        }
        d2[n - 1 + i] = sum;
    }

    int64_t *count = new int64_t[n * n];
    int64_t max_b = 0, max_w = 0, x_b, y_b, x_w, y_w;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) {
            count[i * n + j] = -data[i * n + j] + d1[d1_coord(n, i, j)] + d2[d2_coord(n, i, j)];
            switch ((i + j) % 2)
            {
            case 0:
                if (count[i * n + j] > max_b) {
                    max_b = count[i * n + j];
                    x_b = i;
                    y_b = j;
                }
                break;
            case 1:
                if (count[i * n + j] > max_w) {
                    max_w = count[i * n + j];
                    x_w = i;
                    y_w = j;
                }
                break;
            default:
                break;
            }
        }

    cout << max_b + max_w << endl << ++x_b << " " << ++y_b << " " << ++x_w << " " << ++y_w << endl;

    delete[] count;
    delete[] d1;
    delete[] d2;
    delete[] data;
    return 0;
}


#include <cstring>
#include <stdio.h>

typedef long long int64_t;

int d1_coord(int n, int x, int y) {
    return x + y;
}

int d2_coord(int n, int x, int y) {
    return n - 1 - y + x;
}

int abs(int x) {
    return x > 0 ? x : -x;
}

int main()
{
    int n;
    scanf("%d", &n);
    int *data = new int[n * n];
    int size = 2 * n - 1;
    int64_t *d1 = new int64_t[size], *d2 = new int64_t[size];
    memset(d1, 0, size * sizeof(int64_t));
    memset(d2, 0, size * sizeof(int64_t));
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) {
            scanf("%I64d", data[i * n + j]);
            d1[i + j] += data[i * n + j];
            d2[i + n - 1 - j] += data[i * n + j];
        }

    int64_t *count = new int64_t[n * n];
    int64_t max_b = 0, max_w = 0, x_b = 0, y_b = 0, x_w = 0, y_w = 1;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) {
            count[i * n + j] = -data[i * n + j] + d1[d1_coord(n, i, j)] + d2[d2_coord(n, i, j)];
            if ((i + j) % 2 == 0)
            {
                if (count[i * n + j] > max_b) {
                    max_b = count[i * n + j];
                    x_b = i;
                    y_b = j;
                }
            }
            else {
                if (count[i * n + j] > max_w) {
                    max_w = count[i * n + j];
                    x_w = i;
                    y_w = j;
                }
            }
        }

    printf("%I64d\n", max_b + max_w);
    printf("%d %d %d %d\n", x_b + 1, y_b + 1, x_w + 1, y_w + 1);

    delete[] count;
    delete[] d1;
    delete[] d2;
    delete[] data;
    return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <functional>
#include <map>
#include <stdio.h>
#include <inttypes.h>

using namespace std;

int d1_coord(int n, int x, int y) {
    return x + y;
}

int d2_coord(int n, int x, int y) {
    return n - 1 - y + x;
}

int abs(int x) {
    return x > 0 ? x : -x;
}

int main()
{
    int n;
    cin >> n;
    int *data = new int[n * n];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            cin >> data[i * n + j];

    int64_t *d1 = new int64_t[2 * n - 1], *d2 = new int64_t[2 * n - 1];

    // d1
    for (int i = 0; i < n; i++) {
        int64_t sum = 0L, x = i, y = 0;
        while (x >= 0 && y < n) {
            sum += data[x * n + y];
            x--, y++;
        }
        d1[i] = sum;
    }
    for (int i = 1; i < n; i++) {
        int64_t sum = 0, x = n - 1, y = i;
        while (x >= 0 && y < n) {
            sum += data[x * n + y];
            x--, y++;
        }
        d1[n - 1 + i] = sum;
    }

    // d2
    for (int i = 0; i < n; i++) {
        int64_t sum = 0, x = 0, y = n - 1 - i;
        while (x < n && y < n) {
            sum += data[x * n + y];
            x++, y++;
        }
        d2[i] = sum;
    }
    for (int i = 1; i < n; i++) {
        int64_t sum = 0, x = i, y = 0;
        while (x < n && y < n) {
            sum += data[x * n + y];
            x++, y++;
        }
        d2[n - 1 + i] = sum;
    }

    int64_t *count = new int64_t[n * n];
    int64_t max_b = 0, max_w = 0, x_b = 0, y_b = 0, x_w = 0, y_w = 1;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) {
            count[i * n + j] = -data[i * n + j] + d1[d1_coord(n, i, j)] + d2[d2_coord(n, i, j)];
            switch ((i + j) % 2)
            {
            case 0:
                if (count[i * n + j] > max_b) {
                    max_b = count[i * n + j];
                    x_b = i;
                    y_b = j;
                }
                break;
            case 1:
                if (count[i * n + j] > max_w) {
                    max_w = count[i * n + j];
                    x_w = i;
                    y_w = j;
                }
                break;
            default:
                break;
            }
        }

    cout << max_b + max_w << endl << ++x_b << " " << ++y_b << " " << ++x_w << " " << ++y_w << endl;

    delete[] count;
    delete[] d1;
    delete[] d2;
    delete[] data;
    return 0;
}


#include <iostream>
#include <cstring>

using namespace std;

typedef long long int64_t;

int d1_coord(int n, int x, int y) {
    return x + y;
}

int d2_coord(int n, int x, int y) {
    return n - 1 - y + x;
}

int abs(int x) {
    return x > 0 ? x : -x;
}

int main()
{
    int n;
    cin >> n;
    int *data = new int[n * n];
    int size = 2 * n - 1;
    int64_t *d1 = new int64_t[size], *d2 = new int64_t[size];
    memset(d1, 0, size * sizeof(int64_t));
    memset(d2, 0, size * sizeof(int64_t));
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) {
            cin >> data[i * n + j];
            d1[i + j] += data[i * n + j];
            d2[i + n - 1 - j] += data[i * n + j];
        }

    int64_t *count = new int64_t[n * n];
    int64_t max_b = 0, max_w = 0, x_b = 0, y_b = 0, x_w = 0, y_w = 1;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) {
            count[i * n + j] = -data[i * n + j] + d1[d1_coord(n, i, j)] + d2[d2_coord(n, i, j)];
            if ((i + j) % 2 == 0)
            {
                if (count[i * n + j] > max_b) {
                    max_b = count[i * n + j];
                    x_b = i;
                    y_b = j;
                }
            }
            else {
                if (count[i * n + j] > max_w) {
                    max_w = count[i * n + j];
                    x_w = i;
                    y_w = j;
                }
            }
        }

    cout << max_b + max_w << endl << ++x_b << " " << ++y_b << " " << ++x_w << " " << ++y_w << endl;

    delete[] count;
    delete[] d1;
    delete[] d2;
    delete[] data;
    return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <functional>
#include <map>
#include <stdio.h>

using namespace std;

int d1_coord(int n, int x, int y) {
    return x + y;
}

int d2_coord(int n, int x, int y) {
    return n - 1 - y + x;
}

int abs(int x) {
    return x > 0 ? x : -x;
}

struct node {
    int v, x, y;

    bool operator<(const node& a) const {
        return v > a.v;
    }
};

int main()
{
    int n;
    cin >> n;
    int *data = new int[n * n];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            cin >> data[i * n + j];

    int *d1 = new int[2 * n - 1], *d2 = new int[2 * n - 1];

    // d1
    for (int i = 0; i < n; i++) {
        int sum = 0, x = i, y = 0;
        while (x >= 0 && y < n) {
            sum += data[x * n + y];
            x--, y++;
        }
        d1[i] = sum;
    }
    for (int i = 1; i < n; i++) {
        int sum = 0, x = n - 1, y = i;
        while (x >= 0 && y < n) {
            sum += data[x * n + y];
            x--, y++;
        }
        d1[n - 1 + i] = sum;
    }

    // d2
    for (int i = 0; i < n; i++) {
        int sum = 0, x = 0, y = n - 1 - i;
        while (x < n && y < n) {
            sum += data[x * n + y];
            x++, y++;
        }
        d2[i] = sum;
    }
    for (int i = 1; i < n; i++) {
        int sum = 0, x = i, y = 0;
        while (x < n && y < n) {
            sum += data[x * n + y];
            x++, y++;
        }
        d2[n - 1 + i] = sum;
    }

    int *count = new int[n * n];
    vector<node> nodes;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) {
            count[i * n + j] = -data[i, j];
            int d = d1[d1_coord(n, i, j)];
            count[i * n + j] += d;
            d = d2[d2_coord(n, i, j)];
            count[i * n + j] += d;

            node zxc;
            zxc.v = count[i * n + j];
            zxc.x = i;
            zxc.y = j;
            nodes.push_back(zxc);
        }

    sort(nodes.begin(), nodes.end());

    int v1 = -1, v2 = -1, x1, y1, x2, y2;
    bool procceed = true;
    for (vector<node>::iterator it1 = nodes.begin(); it1 != nodes.end() && procceed; it1++) {
        node& n1 = *it1;
        vector<node>::iterator it2 = it1;
        it2++;
        bool seq_met = true;
        for (; it2 != nodes.end(); it2++) {
            node& n2 = *it2;
            if (abs(n1.x - n2.x) != abs(n1.y - n2.y) && v1 + v2 < n1.v + n2.v) {
                v1 = n1.v, v2 = n2.v;
                x1 = n1.x, y1 = n1.y, x2 = n2.x, y2 = n2.y;
                break;
            } else {
                seq_met = false;
            }
        }
        if (seq_met) procceed = false;
    }

    printf("%d\n%d %d %d %d\n", v1 + v2, ++x1, ++y1, ++x2, ++y2);

    delete[] count;
    delete[] d1;
    delete[] d2;
    delete[] data;
    return 0;
}


#include <cstring>
#include <iostream>
#include <stdio.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    int *data = new int[n * n];
    int size = 2 * n - 1;
    long long *d1 = new long long[size], *d2 = new long long[size];
    memset(d1, 0, size * sizeof(long long));
    memset(d2, 0, size * sizeof(long long));
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) {
            cin >> data[i * n + j];
            d1[i + j] += data[i * n + j];
            d2[i + n - 1 - j] += data[i * n + j];
        }

    long long max_b = 0, max_w = 0;
    int x_b = 0, y_b = 0, x_w = 0, y_w = 1;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) {
            long long c = -data[i * n + j] + d1[i + j] + d2[i + n - 1 - j];
            if ((i + j) % 2 == 0)
            {
                if (c > max_b) {
                    max_b = c;
                    x_b = i;
                    y_b = j;
                }
            }
            else {
                if (c > max_w) {
                    max_w = c;
                    x_w = i;
                    y_w = j;
                }
            }
        }

    cout << max_b + max_w << endl;
    cout << x_b + 1 << " " << y_b + 1 << " " << x_w + 1 << " " << y_w + 1 << endl;

    delete[] d1;
    delete[] d2;
    delete[] data;
    return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <functional>
#include <map>
#include <stdio.h>
#include <inttypes.h>

using namespace std;

int d1_coord(int n, int x, int y) {
    return x + y;
}

int d2_coord(int n, int x, int y) {
    return n - 1 - y + x;
}

int abs(int x) {
    return x > 0 ? x : -x;
}

int main()
{
    int n;
    cin >> n;
    int *data = new int[n * n];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            cin >> data[i * n + j];

    int64_t *d1 = new int64_t[2 * n - 1], *d2 = new int64_t[2 * n - 1];

    // d1
    for (int i = 0; i < n; i++) {
        int64_t sum = 0L, x = i, y = 0;
        while (x >= 0 && y < n) {
            sum += data[x * n + y];
            x--, y++;
        }
        d1[i] = sum;
    }
    for (int i = 1; i < n; i++) {
        int64_t sum = 0, x = n - 1, y = i;
        while (x >= 0 && y < n) {
            sum += data[x * n + y];
            x--, y++;
        }
        d1[n - 1 + i] = sum;
    }

    // d2
    for (int i = 0; i < n; i++) {
        int64_t sum = 0, x = 0, y = n - 1 - i;
        while (x < n && y < n) {
            sum += data[x * n + y];
            x++, y++;
        }
        d2[i] = sum;
    }
    for (int i = 1; i < n; i++) {
        int64_t sum = 0, x = i, y = 0;
        while (x < n && y < n) {
            sum += data[x * n + y];
            x++, y++;
        }
        d2[n - 1 + i] = sum;
    }

    int64_t *count = new int64_t[n * n];
    int64_t max_b = 0, max_w = 0, x_b = 0, y_b = 0, x_w = 0, y_w = 0;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) {
            count[i * n + j] = -data[i * n + j] + d1[d1_coord(n, i, j)] + d2[d2_coord(n, i, j)];
            switch ((i + j) % 2)
            {
            case 0:
                if (count[i * n + j] > max_b) {
                    max_b = count[i * n + j];
                    x_b = i;
                    y_b = j;
                }
                break;
            case 1:
                if (count[i * n + j] > max_w) {
                    max_w = count[i * n + j];
                    x_w = i;
                    y_w = j;
                }
                break;
            default:
                break;
            }
        }

    cout << max_b + max_w << endl << ++x_b << " " << ++y_b << " " << ++x_w << " " << ++y_w << endl;

    delete[] count;
    delete[] d1;
    delete[] d2;
    delete[] data;
    return 0;
}


#include <cstring>
#include <iostream>
#include <stdio.h>

using namespace std;

int main()
{
    int n;
    scanf("%d", &n);
    int *data = new int[n * n];
    int size = 2 * n - 1;
    long long int *d1 = new long long int[size], *d2 = new long long int[size];
    memset(d1, 0, size * sizeof(long long int));
    memset(d2, 0, size * sizeof(long long int));
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) {
            scanf("%I64d", &data[i * n + j]);
            d1[i + j] += data[i * n + j];
            d2[i + n - 1 - j] += data[i * n + j];
        }

    long long int max_b = 0, max_w = 0;
    int x_b = 0, y_b = 0, x_w = 0, y_w = 1;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) {
            long long int c = -data[i * n + j] + d1[i + j] + d2[i + n - 1 - j];
            if ((i + j) % 2 == 0)
            {
                if (c > max_b) {
                    max_b = c;
                    x_b = i;
                    y_b = j;
                }
            }
            else {
                if (c > max_w) {
                    max_w = c;
                    x_w = i;
                    y_w = j;
                }
            }
        }

    cout << max_b + max_w << endl;
    cout << x_b + 1 << " " << y_b + 1 << " " << x_w + 1 << " " << y_w + 1 << endl;

    delete[] d1;
    delete[] d2;
    delete[] data;
    return 0;
}


#include <cstring>
#include <inttypes.h>
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int *data = new int[n * n];
    int size = 2 * n - 1;
    int64_t *d1 = new int64_t[size], *d2 = new int64_t[size];
    memset(d1, 0, size * sizeof(int64_t));
    memset(d2, 0, size * sizeof(int64_t));
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) {
            cin >> data[i * n + j];
            d1[i + j] += data[i * n + j];
            d2[i + n - 1 - j] += data[i * n + j];
        }

    int64_t max_b = 0, max_w = 0;
    int x_b = 0, y_b = 0, x_w = 0, y_w = 1;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) {
            int64_t c = -data[i * n + j] + d1[i + j] + d2[i + n - 1 - j];
            if ((i + j) % 2 == 0)
            {
                if (c > max_b) {
                    max_b = c;
                    x_b = i;
                    y_b = j;
                }
            }
            else {
                if (c > max_w) {
                    max_w = c;
                    x_w = i;
                    y_w = j;
                }
            }
        }

    cout << max_b + max_w << endl;
    cout << x_b + 1 << " " << y_b + 1 << " " << x_w + 1 << " " << y_w + 1 << endl;

    delete[] d1;
    delete[] d2;
    delete[] data;
    return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <functional>
#include <map>
#include <stdio.h>

using namespace std;

int d1_coord(int n, int x, int y) {
    return x + y;
}

int d2_coord(int n, int x, int y) {
    return n - 1 - y + x;
}

int abs(int x) {
    return x > 0 ? x : -x;
}

int main()
{
    int n;
    cin >> n;
    int *data = new int[n * n];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            cin >> data[i * n + j];

    int *d1 = new int[2 * n - 1], *d2 = new int[2 * n - 1];

    // d1
    for (int i = 0; i < n; i++) {
        int sum = 0, x = i, y = 0;
        while (x >= 0 && y < n) {
            sum += data[x * n + y];
            x--, y++;
        }
        d1[i] = sum;
    }
    for (int i = 1; i < n; i++) {
        int sum = 0, x = n - 1, y = i;
        while (x >= 0 && y < n) {
            sum += data[x * n + y];
            x--, y++;
        }
        d1[n - 1 + i] = sum;
    }

    // d2
    for (int i = 0; i < n; i++) {
        int sum = 0, x = 0, y = n - 1 - i;
        while (x < n && y < n) {
            sum += data[x * n + y];
            x++, y++;
        }
        d2[i] = sum;
    }
    for (int i = 1; i < n; i++) {
        int sum = 0, x = i, y = 0;
        while (x < n && y < n) {
            sum += data[x * n + y];
            x++, y++;
        }
        d2[n - 1 + i] = sum;
    }

    int *count = new int[n * n];
    int max_b = -1, max_w = -1, x_b, y_b, x_w, y_w;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) {
            count[i * n + j] = -data[i, j] + d1[d1_coord(n, i, j)] + d2[d2_coord(n, i, j)];
            switch ((i + j) % 2)
            {
            case 0:
                if (count[i * n + j] > max_b) {
                    max_b = count[i * n + j];
                    x_b = i;
                    y_b = j;
                }
                break;
            case 1:
                if (count[i * n + j] > max_w) {
                    max_w = count[i * n + j];
                    x_w = i;
                    y_w = j;
                }
                break;
            default:
                break;
            }
        }

    printf("%d\n%d %d %d %d\n", max_b + max_w, ++x_b, ++y_b, ++x_w, ++y_w);

    delete[] count;
    delete[] d1;
    delete[] d2;
    delete[] data;
    return 0;
}


#include <cstring>
#include <stdio.h>

typedef long long int64_t;

int main()
{
    int n;
    scanf("%d", &n);
    int *data = new int[n * n];
    int size = 2 * n - 1;
    int64_t *d1 = new int64_t[size], *d2 = new int64_t[size];
    memset(d1, 0, size * sizeof(int64_t));
    memset(d2, 0, size * sizeof(int64_t));
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) {
            scanf("%I64d", data[i * n + j]);
            d1[i + j] += data[i * n + j];
            d2[i + n - 1 - j] += data[i * n + j];
        }

    int64_t *count = new int64_t[n * n];
    int64_t max_b = 0, max_w = 0;
    int x_b = 0, y_b = 0, x_w = 0, y_w = 1;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) {
            count[i * n + j] = -data[i * n + j] + d1[d1_coord(n, i, j)] + d2[d2_coord(n, i, j)];
            if ((i + j) % 2 == 0)
            {
                if (count[i * n + j] > max_b) {
                    max_b = count[i * n + j];
                    x_b = i;
                    y_b = j;
                }
            }
            else {
                if (count[i * n + j] > max_w) {
                    max_w = count[i * n + j];
                    x_w = i;
                    y_w = j;
                }
            }
        }

    printf("%I64d\n", max_b + max_w);
    printf("%d %d %d %d\n", x_b + 1, y_b + 1, x_w + 1, y_w + 1);

    delete[] count;
    delete[] d1;
    delete[] d2;
    delete[] data;
    return 0;
}


#include <cstring>
#include <stdio.h>
#include <inttypes.h>

int main()
{
    int n;
    scanf("%d", &n);
    int *data = new int[n * n];
    int size = 2 * n - 1;
    int64_t *d1 = new int64_t[size], *d2 = new int64_t[size];
    memset(d1, 0, size * sizeof(int64_t));
    memset(d2, 0, size * sizeof(int64_t));
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) {
            scanf("%I64d", &data[i * n + j]);
            d1[i + j] += data[i * n + j];
            d2[i + n - 1 - j] += data[i * n + j];
        }

    int64_t max_b = 0, max_w = 0;
    int x_b = 0, y_b = 0, x_w = 0, y_w = 1;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) {
            int64_t c = -data[i * n + j] + d1[i + j] + d2[i + n - 1 - j];
            if ((i + j) % 2 == 0)
            {
                if (c > max_b) {
                    max_b = c;
                    x_b = i;
                    y_b = j;
                }
            }
            else {
                if (c > max_w) {
                    max_w = c;
                    x_w = i;
                    y_w = j;
                }
            }
        }

    printf("%I64d\n", max_b + max_w);
    printf("%d %d %d %d\n", x_b + 1, y_b + 1, x_w + 1, y_w + 1);

    delete[] d1;
    delete[] d2;
    delete[] data;
    return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

int d1_coord(int n, int x, int y) {
    return x + y;
}

int d2_coord(int n, int x, int y) {
    return n - 1 - y + x;
}

int abs(int x) {
    return x > 0 ? x : -x;
}

int main()
{
    int n;
    cin >> n;
    int *data = new int[n * n];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            cin >> data[i * n + j];

    int *d1 = new int[2 * n - 1], *d2 = new int[2 * n - 1];

    // d1
    for (int i = 0; i < n; i++) {
        int sum = 0, x = i, y = 0;
        while (x >= 0 && y < n) {
            sum += data[x * n + y];
            x--, y++;
        }
        d1[i] = sum;
    }
    for (int i = 1; i < n; i++) {
        int sum = 0, x = n - 1, y = i;
        while (x >= 0 && y < n) {
            sum += data[x * n + y];
            x--, y++;
        }
        d1[n - 1 + i] = sum;
    }

    // d2
    for (int i = 0; i < n; i++) {
        int sum = 0, x = 0, y = n - 1 - i;
        while (x < n && y < n) {
            sum += data[x * n + y];
            x++, y++;
        }
        d2[i] = sum;
    }
    for (int i = 1; i < n; i++) {
        int sum = 0, x = i, y = 0;
        while (x < n && y < n) {
            sum += data[x * n + y];
            x++, y++;
        }
        d2[n - 1 + i] = sum;
    }

    int *count = new int[n * n], max_value = -1, max_x, max_y;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) {
            count[i * n + j] = -data[i, j];
            int d = d1[d1_coord(n, i, j)];
            count[i * n + j] += d;
            d = d2[d2_coord(n, i, j)];
            count[i * n + j] += d;
            if (count[i * n + j] > max_value)
                max_value = count[i * n + j], max_x = i, max_y = j;
        }

    int max_value_second = -1;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            if (abs(i - max_x) != abs(j - max_y) && count[i * n + j] > max_value_second)
                max_value_second = count[i * n + j];

    cout << max_value + max_value_second << endl;

    delete[] count;
    delete[] d1;
    delete[] d2;
    delete[] data;
    return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <functional>
#include <map>
#include <stdio.h>
#include <inttypes.h>

using namespace std;

int d1_coord(int n, int x, int y) {
    return x + y;
}

int d2_coord(int n, int x, int y) {
    return n - 1 - y + x;
}

int abs(int x) {
    return x > 0 ? x : -x;
}

int main()
{
    int n;
    cin >> n;
    int *data = new int[n * n];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            cin >> data[i * n + j];

    uint64_t *d1 = new uint64_t[2 * n - 1], *d2 = new uint64_t[2 * n - 1];

    // d1
    for (int i = 0; i < n; i++) {
        uint64_t sum = 0, x = i, y = 0;
        while (x >= 0 && y < n) {
            sum += data[x * n + y];
            x--, y++;
        }
        d1[i] = sum;
    }
    for (int i = 1; i < n; i++) {
        uint64_t sum = 0, x = n - 1, y = i;
        while (x >= 0 && y < n) {
            sum += data[x * n + y];
            x--, y++;
        }
        d1[n - 1 + i] = sum;
    }

    // d2
    for (int i = 0; i < n; i++) {
        uint64_t sum = 0, x = 0, y = n - 1 - i;
        while (x < n && y < n) {
            sum += data[x * n + y];
            x++, y++;
        }
        d2[i] = sum;
    }
    for (int i = 1; i < n; i++) {
        uint64_t sum = 0, x = i, y = 0;
        while (x < n && y < n) {
            sum += data[x * n + y];
            x++, y++;
        }
        d2[n - 1 + i] = sum;
    }

    uint64_t *count = new uint64_t[n * n];
    uint64_t max_b = 0, max_w = 0, x_b, y_b, x_w, y_w;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) {
            count[i * n + j] = -data[i * n + j] + d1[d1_coord(n, i, j)] + d2[d2_coord(n, i, j)];
            switch ((i + j) % 2)
            {
            case 0:
                if (count[i * n + j] > max_b) {
                    max_b = count[i * n + j];
                    x_b = i;
                    y_b = j;
                }
                break;
            case 1:
                if (count[i * n + j] > max_w) {
                    max_w = count[i * n + j];
                    x_w = i;
                    y_w = j;
                }
                break;
            default:
                break;
            }
        }

    cout << max_b + max_w << endl << ++x_b << " " << ++y_b << " " << ++x_w << " " << ++y_w << endl;

    delete[] count;
    delete[] d1;
    delete[] d2;
    delete[] data;
    return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <functional>
#include <map>

using namespace std;

int d1_coord(int n, int x, int y) {
    return x + y;
}

int d2_coord(int n, int x, int y) {
    return n - 1 - y + x;
}

int abs(int x) {
    return x > 0 ? x : -x;
}

int main()
{
    int n;
    cin >> n;
    int *data = new int[n * n];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            cin >> data[i * n + j];

    int *d1 = new int[2 * n - 1], *d2 = new int[2 * n - 1];

    // d1
    for (int i = 0; i < n; i++) {
        int sum = 0, x = i, y = 0;
        while (x >= 0 && y < n) {
            sum += data[x * n + y];
            x--, y++;
        }
        d1[i] = sum;
    }
    for (int i = 1; i < n; i++) {
        int sum = 0, x = n - 1, y = i;
        while (x >= 0 && y < n) {
            sum += data[x * n + y];
            x--, y++;
        }
        d1[n - 1 + i] = sum;
    }

    // d2
    for (int i = 0; i < n; i++) {
        int sum = 0, x = 0, y = n - 1 - i;
        while (x < n && y < n) {
            sum += data[x * n + y];
            x++, y++;
        }
        d2[i] = sum;
    }
    for (int i = 1; i < n; i++) {
        int sum = 0, x = i, y = 0;
        while (x < n && y < n) {
            sum += data[x * n + y];
            x++, y++;
        }
        d2[n - 1 + i] = sum;
    }

    int *count = new int[n * n];
    int max_b = -1, max_w = -1, x_b, y_b, x_w, y_w;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) {
            count[i * n + j] = -data[i, j] + d1[d1_coord(n, i, j)] + d2[d2_coord(n, i, j)];
            switch ((i + j) % 2)
            {
            case 0:
                if (count[i * n + j] > max_b) {
                    max_b = count[i * n + j];
                    x_b = i;
                    y_b = j;
                }
                break;
            case 1:
                if (count[i * n + j] > max_w) {
                    max_w = count[i * n + j];
                    x_w = i;
                    y_w = j;
                }
                break;
            default:
                break;
            }
        }

    printf("%d\n%d %d %d %d\n", max_b + max_w, ++x_b, ++y_b, ++x_w, ++y_w);

    delete[] count;
    delete[] d1;
    delete[] d2;
    delete[] data;
    return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <functional>
#include <map>
#include <stdio.h>
#include <inttypes.h>

using namespace std;

int d1_coord(int n, int x, int y) {
    return x + y;
}

int d2_coord(int n, int x, int y) {
    return n - 1 - y + x;
}

int abs(int x) {
    return x > 0 ? x : -x;
}

int main()
{
    int n;
    cin >> n;
    int *data = new int[n * n];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            cin >> data[i * n + j];

    uint64_t *d1 = new uint64_t[2 * n - 1], *d2 = new uint64_t[2 * n - 1];

    // d1
    for (int i = 0; i < n; i++) {
        uint64_t sum = 0, x = i, y = 0;
        while (x >= 0 && y < n) {
            sum += data[x * n + y];
            x--, y++;
        }
        d1[i] = sum;
    }
    for (int i = 1; i < n; i++) {
        uint64_t sum = 0, x = n - 1, y = i;
        while (x >= 0 && y < n) {
            sum += data[x * n + y];
            x--, y++;
        }
        d1[n - 1 + i] = sum;
    }

    // d2
    for (int i = 0; i < n; i++) {
        uint64_t sum = 0, x = 0, y = n - 1 - i;
        while (x < n && y < n) {
            sum += data[x * n + y];
            x++, y++;
        }
        d2[i] = sum;
    }
    for (int i = 1; i < n; i++) {
        uint64_t sum = 0, x = i, y = 0;
        while (x < n && y < n) {
            sum += data[x * n + y];
            x++, y++;
        }
        d2[n - 1 + i] = sum;
    }

    uint64_t *count = new uint64_t[n * n];
    uint64_t max_b = -1, max_w = -1, x_b, y_b, x_w, y_w;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) {
            count[i * n + j] = -data[i * n + j] + d1[d1_coord(n, i, j)] + d2[d2_coord(n, i, j)];
            switch ((i + j) % 2)
            {
            case 0:
                if (count[i * n + j] > max_b) {
                    max_b = count[i * n + j];
                    x_b = i;
                    y_b = j;
                }
                break;
            case 1:
                if (count[i * n + j] > max_w) {
                    max_w = count[i * n + j];
                    x_w = i;
                    y_w = j;
                }
                break;
            default:
                break;
            }
        }

    cout << max_b + max_w << endl << ++x_b << " " << ++y_b << " " << ++x_w << " " << ++y_w << endl;

    delete[] count;
    delete[] d1;
    delete[] d2;
    delete[] data;
    return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <functional>
#include <map>
#include <stdio.h>

using namespace std;

int d1_coord(int n, int x, int y) {
    return x + y;
}

int d2_coord(int n, int x, int y) {
    return n - 1 - y + x;
}

int abs(int x) {
    return x > 0 ? x : -x;
}

int main()
{
    int n;
    cin >> n;
    int *data = new int[n * n];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            cin >> data[i * n + j];

    int *d1 = new int[2 * n - 1], *d2 = new int[2 * n - 1];

    // d1
    for (int i = 0; i < n; i++) {
        int sum = 0, x = i, y = 0;
        while (x >= 0 && y < n) {
            sum += data[x * n + y];
            x--, y++;
        }
        d1[i] = sum;
    }
    for (int i = 1; i < n; i++) {
        int sum = 0, x = n - 1, y = i;
        while (x >= 0 && y < n) {
            sum += data[x * n + y];
            x--, y++;
        }
        d1[n - 1 + i] = sum;
    }

    // d2
    for (int i = 0; i < n; i++) {
        int sum = 0, x = 0, y = n - 1 - i;
        while (x < n && y < n) {
            sum += data[x * n + y];
            x++, y++;
        }
        d2[i] = sum;
    }
    for (int i = 1; i < n; i++) {
        int sum = 0, x = i, y = 0;
        while (x < n && y < n) {
            sum += data[x * n + y];
            x++, y++;
        }
        d2[n - 1 + i] = sum;
    }

    int *count = new int[n * n];
    int max_b = -1, max_w = -1, x_b, y_b, x_w, y_w;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) {
            count[i * n + j] = -data[i * n + j] + d1[d1_coord(n, i, j)] + d2[d2_coord(n, i, j)];
            switch ((i + j) % 2)
            {
            case 0:
                if (count[i * n + j] > max_b) {
                    max_b = count[i * n + j];
                    x_b = i;
                    y_b = j;
                }
                break;
            case 1:
                if (count[i * n + j] > max_w) {
                    max_w = count[i * n + j];
                    x_w = i;
                    y_w = j;
                }
                break;
            default:
                break;
            }
        }

    printf("%d\n%d %d %d %d\n", max_b + max_w, ++x_b, ++y_b, ++x_w, ++y_w);

    delete[] count;
    delete[] d1;
    delete[] d2;
    delete[] data;
    return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

int d1_coord(int n, int x, int y) {
    return x + y;
}

int d2_coord(int n, int x, int y) {
    return n - 1 - y + x;
}

int abs(int x) {
    return x > 0 ? x : -x;
}

int main()
{
    int n;
    cin >> n;
    int *data = new int[n * n];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            cin >> data[i * n + j];

    int *d1 = new int[2 * n - 1], *d2 = new int[2 * n - 1];

    // d1
    for (int i = 0; i < n; i++) {
        int sum = 0, x = i, y = 0;
        while (x >= 0 && y < n) {
            sum += data[x * n + y];
            x--, y++;
        }
        d1[i] = sum;
    }
    for (int i = 1; i < n; i++) {
        int sum = 0, x = n - 1, y = i;
        while (x >= 0 && y < n) {
            sum += data[x * n + y];
            x--, y++;
        }
        d1[n - 1 + i] = sum;
    }

    // d2
    for (int i = 0; i < n; i++) {
        int sum = 0, x = 0, y = n - 1 - i;
        while (x < n && y < n) {
            sum += data[x * n + y];
            x++, y++;
        }
        d2[i] = sum;
    }
    for (int i = 1; i < n; i++) {
        int sum = 0, x = i, y = 0;
        while (x < n && y < n) {
            sum += data[x * n + y];
            x++, y++;
        }
        d2[n - 1 + i] = sum;
    }

    int *count = new int[n * n], max_value = -1, max_x, max_y;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) {
            count[i * n + j] = -data[i, j];
            int d = d1[d1_coord(n, i, j)];
            count[i * n + j] += d;
            d = d2[d2_coord(n, i, j)];
            count[i * n + j] += d;
            if (count[i * n + j] > max_value)
                max_value = count[i * n + j], max_x = i, max_y = j;
        }

    int max_value_second = -1, max_x_2, max_y_2;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            if (abs(i - max_x) != abs(j - max_y) && count[i * n + j] > max_value_second)
                max_value_second = count[i * n + j], max_x_2 = i, max_y_2 = j;

    cout << max_value + max_value_second << endl << ++max_x << " " << ++max_y << " " << ++max_x_2 << " " << ++max_y_2 << endl;

    delete[] count;
    delete[] d1;
    delete[] d2;
    delete[] data;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

long long int a[2001][2001];
long long int x;
long long int cur,maxe,maxo;
map<long long,long long>mp;
map<long long,long long>mp1;

int main()
{
    ios::sync_with_stdio(0);
    int i,j,n,xe,xo,ye,yo;
cin>>n;
for(i=1;i<=n;i++)
{
    for(j=1;j<=n;j++)
    {
      cin>>a[i][j];
    mp[i+j]+=a[i][j];
    mp1[i-j]+=a[i][j];
    }
}

maxe=-1;
maxo=-1;
for(i=1;i<=n;i++)
{
    for(j=1;j<=n;j++)
    {
x=mp[i+j]+mp1[i-j]-a[i][j];
if((i+j)%2==0)
{
    if(x>maxe)
    {
        maxe=x;
        xe=i;
        ye=j;
    }
}
else
if((i+j)%2==1)
{
    if(x>maxo)
    {
        maxo=x;
        xo=i;
        yo=j;
    }
}
    }
}
cout<<maxe+maxo<<"\n";
cout<<xe<<" "<<ye<<" "<<xo<<" "<<yo;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

 int a[2001][2001];
 int x;
 int cur,maxe,maxo;
map<int,int>mp;
map<int,int>mp1;

int main()
{
  //  ios::sync_with_stdio(0);
    int i,j,n,xe,xo,ye,yo;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
    for(j=1;j<=n;j++)
    {
      cin>>a[i][j];
    mp[i+j]+=a[i][j];
    mp1[i-j]+=a[i][j];
    }
}

maxe=-1;
maxo=-1;
for(i=1;i<=n;i++)
{
    for(j=1;j<=n;j++)
    {
x=mp[i+j]+mp1[i-j]-a[i][j];
if((i+j)%2==0)
{
    if(x>maxe)
    {
        maxe=x;
        xe=i;
        ye=j;
    }
}
else
if((i+j)%2==1)
{
    if(x>maxo)
    {
        maxo=x;
        xo=i;
        yo=j;
    }
}
    }
}
scanf("%d\n",maxe+maxo);
scanf("%d %d %d %d",xe,ye,xo,yo);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

long long int a[2001][2001];
long long int x;
long long int cur,maxe,maxo;
map<long long,long long>mp;
map<long long,long long>mp1;

int main()
{
    ios::sync_with_stdio(0);
    int i,j,n,xe,xo,ye,yo;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
    for(j=1;j<=n;j++)
    {
      cin>>a[i][j];
    mp[i+j]+=a[i][j];
    mp1[i-j]+=a[i][j];
    }
}

maxe=-1;
maxo=-1;
for(i=1;i<=n;i++)
{
    for(j=1;j<=n;j++)
    {
x=mp[i+j]+mp1[i-j]-a[i][j];
if((i+j)%2==0)
{
    if(x>maxe)
    {
        maxe=x;
        xe=i;
        ye=j;
    }
}
else
if((i+j)%2==1)
{
    if(x>maxo)
    {
        maxo=x;
        xo=i;
        yo=j;
    }
}
    }
}
cout<<maxe+maxo<<"\n";
cout<<xe<<" "<<ye<<" "<<xo<<" "<<yo;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

long long int a[2001][2001];
long long int x;
long long int cur,maxe,maxo;
map<long long,long long>mp;
map<long long,long long>mp1;

int main()
{
cin.sync_with_stdio(false);
    int i,j,n,xe,xo,ye,yo;
cin>>n;
for(i=1;i<=n;i++)
{
    for(j=1;j<=n;j++)
    {
      cin>>a[i][j];
    mp[i+j]+=a[i][j];
    mp1[i-j]+=a[i][j];
    }
}

maxe=-1;
maxo=-1;
for(i=1;i<=n;i++)
{
    for(j=1;j<=n;j++)
    {
x=mp[i+j]+mp1[i-j]-a[i][j];
if((i+j)%2==0)
{
    if(x>maxe)
    {
        maxe=x;
        xe=i;
        ye=j;
    }
}
else
if((i+j)%2==1)
{
    if(x>maxo)
    {
        maxo=x;
        xo=i;
        yo=j;
    }
}
    }
}
cout<<maxe+maxo<<"\n";
cout<<xe<<" "<<ye<<" "<<xo<<" "<<yo;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

 int a[2001][2001];
 int x;
 int cur,maxe,maxo;
map<int,int>mp;
map<int,int>mp1;

int main()
{
  //  ios::sync_with_stdio(0);
    int i,j,n,xe,xo,ye,yo;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
    for(j=1;j<=n;j++)
    {
      cin>>a[i][j];
    mp[i+j]+=a[i][j];
    mp1[i-j]+=a[i][j];
    }
}

maxe=-1;
maxo=-1;
for(i=1;i<=n;i++)
{
    for(j=1;j<=n;j++)
    {
x=mp[i+j]+mp1[i-j]-a[i][j];
if((i+j)%2==0)
{
    if(x>maxe)
    {
        maxe=x;
        xe=i;
        ye=j;
    }
}
else
if((i+j)%2==1)
{
    if(x>maxo)
    {
        maxo=x;
        xo=i;
        yo=j;
    }
}
    }
}
cout<<maxe+maxo<<"\n";
cout<<xe<<" "<<ye<<" "<<xo<<" "<<yo;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int NMAX = 2014;
 int a[NMAX][NMAX];
 long long int x;
 long long int maxe,maxo;
 long long mp[2*NMAX];
  long long mp1[2*NMAX];

int main()
{
    ios::sync_with_stdio(0);
int i,j,n,xe,xo,ye,yo;
cin>>n;
for(i=1;i<=n;i++)
{
    for(j=1;j<=n;j++)
    {
      cin>>a[i][j];
    mp[i+j]+=a[i][j];
    mp1[i-j+n]+=a[i][j];
    }
}

maxe=-1;
maxo=-1;
for(i=1;i<=n;i++)
{
    for(j=1;j<=n;j++)
    {
x=mp[i+j]+mp1[i-j+n]-a[i][j];
if((i+j)%2==0)
{
    if(x>maxe)
    {
        maxe=x;
        xe=i;
        ye=j;
    }
}
else
if((i+j)%2==1)
{
    if(x>maxo)
    {
        maxo=x;
        xo=i;
        yo=j;
    }
}
    }
}
cout<<maxe+maxo<<"\n";
cout<<xe<<" "<<ye<<" "<<xo<<" "<<yo;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int NMAX = 2014;
 int a[NMAX][NMAX];
 long long int x;
 long long int maxe,maxo;
 long long mp[2*NMAX];
  long long mp1[2*NMAX];

int main()
{
int i,j,n,xe,xo,ye,yo;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
    for(j=1;j<=n;j++)
    {
      cin>>a[i][j];
    mp[i+j]+=a[i][j];
    mp1[i-j+n]+=a[i][j];
    }
}

maxe=-1;
maxo=-1;
for(i=1;i<=n;i++)
{
    for(j=1;j<=n;j++)
    {
x=mp[i+j]+mp1[i-j+n]-a[i][j];
if((i+j)%2==0)
{
    if(x>maxe)
    {
        maxe=x;
        xe=i;
        ye=j;
    }
}
else
if((i+j)%2==1)
{
    if(x>maxo)
    {
        maxo=x;
        xo=i;
        yo=j;
    }
}
    }
}
cout<<maxe+maxo<<"\n";
printf("%d %d %d %d",xe,ye,xo,yo);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

 int a[2001][2001];
 int x;
 int cur,maxe,maxo;
map<int,int>mp;
map<int,int>mp1;

int main()
{
  //  ios::sync_with_stdio(0);
    int i,j,n,xe,xo,ye,yo;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
    for(j=1;j<=n;j++)
    {
      cin>>a[i][j];
    mp[i+j]+=a[i][j];
    mp1[i-j]+=a[i][j];
    }
}

maxe=-1;
maxo=-1;
for(i=1;i<=n;i++)
{
    for(j=1;j<=n;j++)
    {
x=mp[i+j]+mp1[i-j]-a[i][j];
if((i+j)%2==0)
{
    if(x>maxe)
    {
        maxe=x;
        xe=i;
        ye=j;
    }
}
else
if((i+j)%2==1)
{
    if(x>maxo)
    {
        maxo=x;
        xo=i;
        yo=j;
    }
}
    }
}
printf("%d\n",maxe+maxo);
printf("%d %d %d %d",xe,ye,xo,yo);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

long long int a[2001][2001];
long long int x;
long long int cur,maxe,maxo;
map<long long,long long>mp;
map<long long,long long>mp1;

int main()
{
  //  ios::sync_with_stdio(0);
    int i,j,n,xe,xo,ye,yo;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
    for(j=1;j<=n;j++)
    {
      cin>>a[i][j];
    mp[i+j]+=a[i][j];
    mp1[i-j]+=a[i][j];
    }
}

maxe=-1;
maxo=-1;
for(i=1;i<=n;i++)
{
    for(j=1;j<=n;j++)
    {
x=mp[i+j]+mp1[i-j]-a[i][j];
if((i+j)%2==0)
{
    if(x>maxe)
    {
        maxe=x;
        xe=i;
        ye=j;
    }
}
else
if((i+j)%2==1)
{
    if(x>maxo)
    {
        maxo=x;
        xo=i;
        yo=j;
    }
}
    }
}
cout<<maxe+maxo<<"\n";
cout<<xe<<" "<<ye<<" "<<xo<<" "<<yo;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

 int a[2001][2001];
 long long int x;
 long long int maxe,maxo;
 long long mp[4008];
  long long mp1[4008];

int main()
{
int i,j,n,xe,xo,ye,yo;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
    for(j=1;j<=n;j++)
    {
      cin>>a[i][j];
    mp[i+j]+=a[i][j];
    mp1[i-j+n]+=a[i][j];
    }
}

maxe=-1;
maxo=-1;
for(i=1;i<=n;i++)
{
    for(j=1;j<=n;j++)
    {
x=mp[i+j]+mp1[i-j+n]-a[i][j];
if((i+j)%2==0)
{
    if(x>maxe)
    {
        maxe=x;
        xe=i;
        ye=j;
    }
}
else
if((i+j)%2==1)
{
    if(x>maxo)
    {
        maxo=x;
        xo=i;
        yo=j;
    }
}
    }
}
printf("%d\n",maxe+maxo);
printf("%d %d %d %d",xe,ye,xo,yo);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int NMAX = 2014;
 int a[NMAX][NMAX];
 long long int x;
 long long int maxe,maxo;
 long long mp[2*NMAX];
  long long mp1[2*NMAX];

int main()
{
      cin.sync_with_stdio(false);
int i,j,n,xe,xo,ye,yo;
cin>>n;
for(i=1;i<=n;i++)
{
    for(j=1;j<=n;j++)
    {
      cin>>a[i][j];
    mp[i+j]+=a[i][j];
    mp1[i-j+n]+=a[i][j];
    }
}

maxe=-1;
maxo=-1;
for(i=1;i<=n;i++)
{
    for(j=1;j<=n;j++)
    {
x=mp[i+j]+mp1[i-j+n]-a[i][j];
if((i+j)%2==0)
{
    if(x>maxe)
    {
        maxe=x;
        xe=i;
        ye=j;
    }
}
else
if((i+j)%2==1)
{
    if(x>maxo)
    {
        maxo=x;
        xo=i;
        yo=j;
    }
}
    }
}
cout<<maxe+maxo<<"\n";
cout<<xe<<" "<<ye<<" "<<xo<<" "<<yo;
    return 0;
}


#include <iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<bitset>
#include<iomanip>
typedef long long int llint ;
using namespace std;

map<pair<int, int>, llint> rights;
map<pair<int, int>, llint> lefts;
int main() {
	int n,all[2002][2002];
	pair<int, int> maxe,maxo;
	llint maxen=-1, maxon=-1;
	cin >> n;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> all[i][j];
			pair<int, int> rightpair;
			pair<int, int>leftpair;
			if (i + j >= n) {
				rightpair.first = n-1;
				rightpair.second = i + j - n + 1;
			}
			else {
				rightpair.first = 0;
				rightpair.second = i + j;
			}
			if (j<=i) {
				leftpair.first = 0;
				leftpair.second = i-j;
			}
			else {
				leftpair.first = n-1;
				leftpair.second = n-1-j+i;
			}
			rights[rightpair]+=all[i][j];
			lefts[leftpair] += all[i][j];
		}

	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			pair<int, int> rightpair;
			pair<int, int>leftpair;
			if (i + j >= n) {
				rightpair.first = n - 1;
				rightpair.second = i + j - n + 1;
			}
			else {
				rightpair.first = 0;
				rightpair.second = i + j;
			}
			if (j <= i) {
				leftpair.first = 0;
				leftpair.second = i - j;
			}
			else {
				leftpair.first = n - 1;
				leftpair.second = n - 1 - j + i;
			}
			llint val = rights[rightpair] + lefts[leftpair] - all[i][j];
			if ((i + j) % 2) {
				if (val > maxon) {
					maxo = make_pair(i, j);
					maxon = val;
				}
			}
			else {
				if (val > maxen) {
					maxe = make_pair(i, j);
					maxen = val;
				}

			}
		}
	}
	cout << maxen + maxon << endl;
	cout << maxe.first+1 << ' ' << maxe.second+1<<' ';
	cout << maxo.first+1 << ' ' << maxo.second+1;
//	system("pause");
	return 0;
}


#include <iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<bitset>
#include<iomanip>
typedef long long int llint ;
using namespace std;

llint rights[2001][2001];
llint lefts[2001][2001];
int main() {
	int n,all[2001][2001];
	pair<int, int> maxe,maxo;
	llint maxen=-1, maxon=-1;
	cin >> n;
	if(n==2000){

    cout<<"IN";
}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> all[i][j];
			pair<int, int> rightpair;
			pair<int, int>leftpair;
			if (i + j >= n) {
				rightpair.first = n-1;
				rightpair.second = i + j - n + 1;
			}
			else {
				rightpair.first = 0;
				rightpair.second = i + j;
			}
			if (j<=i) {
				leftpair.first = 0;
				leftpair.second = i-j;
			}
			else {
				leftpair.first = n-1;
				leftpair.second = n-1-j+i;
			}
			rights[rightpair.first][rightpair.second]+=all[i][j];
			lefts[leftpair.first][leftpair.second] += all[i][j];
		}

	if(n==2000 &&i>1700){

    cout<<i;
}
	}
if(n==2000){

    cout<<"OUT";
}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			pair<int, int> rightpair;
			pair<int, int>leftpair;
			if (i + j >= n) {
				rightpair.first = n - 1;
				rightpair.second = i + j - n + 1;
			}
			else {
				rightpair.first = 0;
				rightpair.second = i + j;
			}
			if (j <= i) {
				leftpair.first = 0;
				leftpair.second = i - j;
			}
			else {
				leftpair.first = n - 1;
				leftpair.second = n - 1 - j + i;
			}
			llint val = rights[rightpair.first][rightpair.second] + lefts[leftpair.first][leftpair.second] - all[i][j];
			if ((i + j) % 2) {
				if (val > maxon) {
					maxo = make_pair(i, j);
					maxon = val;
				}
			}
			else {
				if (val > maxen) {
					maxe = make_pair(i, j);
					maxen = val;
				}

			}
		}
	}
	cout << maxen + maxon << endl;
	cout << maxe.first+1 << ' ' << maxe.second+1<<' ';
	cout << maxo.first+1 << ' ' << maxo.second+1;
//	system("pause");
	return 0;
}


#include <iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<bitset>
#include<iomanip>
typedef long long int llint ;
using namespace std;

llint rights[2001][2001];
llint lefts[2001][2001];
int main() {
	int n,all[2001][2001];
	pair<int, int> maxe,maxo;
	llint maxen=-1, maxon=-1;
	cin >> n;
	if(n==2000){

    cout<<"IN";
}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> all[i][j];
			pair<int, int> rightpair;
			pair<int, int>leftpair;
			if (i + j >= n) {
				rightpair.first = n-1;
				rightpair.second = i + j - n + 1;
			}
			else {
				rightpair.first = 0;
				rightpair.second = i + j;
			}
			if (j<=i) {
				leftpair.first = 0;
				leftpair.second = i-j;
			}
			else {
				leftpair.first = n-1;
				leftpair.second = n-1-j+i;
			}
			rights[rightpair.first][rightpair.second]+=all[i][j];
			lefts[leftpair.first][leftpair.second] += all[i][j];
		}

	if(n==2000 &&i>1200 && i%100==0){

    cout<<i;
}
	}
if(n==2000){

    cout<<"OUT";
}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			pair<int, int> rightpair;
			pair<int, int>leftpair;
			if (i + j >= n) {
				rightpair.first = n - 1;
				rightpair.second = i + j - n + 1;
			}
			else {
				rightpair.first = 0;
				rightpair.second = i + j;
			}
			if (j <= i) {
				leftpair.first = 0;
				leftpair.second = i - j;
			}
			else {
				leftpair.first = n - 1;
				leftpair.second = n - 1 - j + i;
			}
			llint val = rights[rightpair.first][rightpair.second] + lefts[leftpair.first][leftpair.second] - all[i][j];
			if ((i + j) % 2) {
				if (val > maxon) {
					maxo = make_pair(i, j);
					maxon = val;
				}
			}
			else {
				if (val > maxen) {
					maxe = make_pair(i, j);
					maxen = val;
				}

			}
		}
	}
	cout << maxen + maxon << endl;
	cout << maxe.first+1 << ' ' << maxe.second+1<<' ';
	cout << maxo.first+1 << ' ' << maxo.second+1;
//	system("pause");
	return 0;
}


#include <iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<bitset>
#include<iomanip>
typedef long long int llint ;
using namespace std;

llint rights[2001][2001];
llint lefts[2001][2001];
int main() {
	int n,all[2001][2001];
	pair<int, int> maxe,maxo;
	llint maxen=-1, maxon=-1;
	cin >> n;
	if(n==2000){

    cout<<"IN";
}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> all[i][j];
			pair<int, int> rightpair;
			pair<int, int>leftpair;
				if(n!=2000){
			if (i + j >= n) {
				rightpair.first = n-1;
				rightpair.second = i + j - n + 1;
			}
			else {
				rightpair.first = 0;
				rightpair.second = i + j;
			}
			if (j<=i) {
				leftpair.first = 0;
				leftpair.second = i-j;
			}
			else {
				leftpair.first = n-1;
				leftpair.second = n-1-j+i;
			}
			rights[rightpair.first][rightpair.second]+=all[i][j];
			lefts[leftpair.first][leftpair.second] += all[i][j];
				}
		}

	if(n==2000 &&i>1800){

    cout<<i;
}
	}
if(n==2000){

    cout<<"OUT";
}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			pair<int, int> rightpair;
			pair<int, int>leftpair;
			if (i + j >= n) {
				rightpair.first = n - 1;
				rightpair.second = i + j - n + 1;
			}
			else {
				rightpair.first = 0;
				rightpair.second = i + j;
			}
			if (j <= i) {
				leftpair.first = 0;
				leftpair.second = i - j;
			}
			else {
				leftpair.first = n - 1;
				leftpair.second = n - 1 - j + i;
			}
			llint val = rights[rightpair.first][rightpair.second] + lefts[leftpair.first][leftpair.second] - all[i][j];
			if ((i + j) % 2) {
				if (val > maxon) {
					maxo = make_pair(i, j);
					maxon = val;
				}
			}
			else {
				if (val > maxen) {
					maxe = make_pair(i, j);
					maxen = val;
				}

			}
		}
	}
	cout << maxen + maxon << endl;
	cout << maxe.first+1 << ' ' << maxe.second+1<<' ';
	cout << maxo.first+1 << ' ' << maxo.second+1;
//	system("pause");
	return 0;
}


#include <iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<bitset>
#include<iomanip>
typedef long long int llint ;
using namespace std;

map<pair<int, int>, llint> rights;
map<pair<int, int>, llint> lefts;
int main() {
	int n,all[200][200];
	pair<int, int> maxe,maxo;
	llint maxen=-1, maxon=-1;
	cin >> n;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> all[i][j];
			pair<int, int> rightpair;
			pair<int, int>leftpair;
			if (i + j >= n) {
				rightpair.first = n-1;
				rightpair.second = i + j - n + 1;
			}
			else {
				rightpair.first = 0;
				rightpair.second = i + j;
			}
			if (j<=i) {
				leftpair.first = 0;
				leftpair.second = i-j;
			}
			else {
				leftpair.first = n-1;
				leftpair.second = n-1-j+i;
			}
			rights[rightpair]+=all[i][j];
			lefts[leftpair] += all[i][j];
		}

	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			pair<int, int> rightpair;
			pair<int, int>leftpair;
			if (i + j >= n) {
				rightpair.first = n - 1;
				rightpair.second = i + j - n + 1;
			}
			else {
				rightpair.first = 0;
				rightpair.second = i + j;
			}
			if (j <= i) {
				leftpair.first = 0;
				leftpair.second = i - j;
			}
			else {
				leftpair.first = n - 1;
				leftpair.second = n - 1 - j + i;
			}
			llint val = rights[rightpair] + lefts[leftpair] - all[i][j];
			if ((i + j) % 2) {
				if (val > maxon) {
					maxo = make_pair(i, j);
					maxon = val;
				}
			}
			else {
				if (val > maxen) {
					maxe = make_pair(i, j);
					maxen = val;
				}

			}
		}
	}
	cout << maxen + maxon << endl;
	cout << maxe.first+1 << ' ' << maxe.second+1<<' ';
	cout << maxo.first+1 << ' ' << maxo.second+1;
//	system("pause");
	return 0;
}