#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int n,N=1;
int A[2048][2048];
vector<int> rows[2048];
vector<int> cols[2048];
vector<int> tree[4096];
inline int next(vector<int> &A,int &i,vector<int> &B,int &j)
{
	if(i>=A.size())
	{
		if(j>=B.size())
			return -1;
		return B[j++];
	}
	if(j>=B.size())
		return A[i++];
	if(A[i]<B[j])
		return A[i++];
	if(A[i]==B[j])
		++i;
	return B[j++];
}
inline void push(int r,int L,int R)
{
	//cout<<"push1 "<<L<<' '<<R<<'\n';
	L+=N;R+=N;
	//cout<<"push2 "<<L<<' '<<R<<'\n';
	while(L<R)
	{
		int sz=min(__builtin_ctz(L),__builtin_ctz(R-L));
		tree[L>>sz].push_back(r);
		//cout<<"push "<<(L>>sz)<<' '<<r<<'\n';
		L+=1<<sz;
	}
}
inline int check(int c,int L,int R)
{
	for(c+=N;c>0;c>>=1)
	{
		vector<int>::iterator it=lower_bound(tree[c].begin(),tree[c].end(),L);
		if(it!=tree[c].end()&&(*it)<R)
			return *it;
	}
	return -1;
}
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(0);
	cin>>n;
	while(N<n)N<<=1;
//	for(int i=0;i<n;++i)
//		rows[i].push_back(-1);
//	for(int i=0;i<n;++i)
//		cols[i].push_back(-1);
	for(int i=0;i<n;++i)
		for(int j=0;j<n;++j)
		{
			cin>>A[i][j];
			if(i>0&&A[i][j]==A[i-1][j]) // vertical
				rows[i].push_back(j);
			else if(j>0&&A[i][j]==A[i][j-1]) // horizontal
				cols[j].push_back(i);
		}
	for(int i=0;i<n;++i)
		rows[i].push_back(n-1);
	for(int i=0;i<n;++i)
		cols[i].push_back(n-1);
	for(int len=n-2;len>0;len-=2)
	{
		for(int r=1;r+len<n;++r)
		{
			int i=0,j=0;
			int L=0,R=next(rows[r],i,rows[r+len],j);
			while(R>=0)
			{
				//if(R-L>=len)cout<<len<<' '<<r<<' '<<L<<' '<<R<<'\n';
				if(R-L>=len)
					push(r,L,R-len+1);
				L=R+1;
				R=next(rows[r],i,rows[r+len],j);
			}
		}
		for(int c=1;c+len<n;++c)
		{
			int i=0,j=0;
			int L=0,R=next(cols[c],i,cols[c+len],j);
			while(R>=0)
			{
				if(R-L>=len)
				{
					int q=check(c,L,R);
					if(q>=0)
					{
						cout<<len<<' '<<q+1<<' '<<c+1<<'\n';
						return 0;
					}
				}
				L=R+1;
				R=next(cols[c],i,cols[c+len],j);
			}
		}
		for(int i=0;i<2*N;++i)
			tree[i].clear();
	}
}
