#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int n,N=1;
int A[2048][2048];
vector<int> tree[4096];
inline void push(int r,int L,int R)
{
	L+=N;R+=N;
	while(L<R)
	{
		int sz=min(__builtin_ctz(L),__builtin_ctz(R-L));
		tree[L>>sz].push_back(r);
		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)
		for(int j=0;j<n;++j)
			cin>>A[i][j];
	for(int len=n-2;len>0;len-=2)
	{
		for(int r=1;r+len<n;++r)
		{
			int L,R=0;
			while(R<n-1)
			{
				L=++R;
				while(R<n-1&&A[r][R]!=A[r-1][R]&&A[r+len][R]!=A[r+len-1][R])
					++R;
				if(R-L>=len)
					push(r,L,R-len+1);
			}
		}
		for(int c=1;c+len<n;++c)
		{
			int L,R=0;
			while(R<n-1)
			{
				L=++R;
				while(R<n-1&&A[R][c]!=A[R][c-1]&&A[R][c+len]!=A[R][c+len-1])
					++R;
				if(R-L>=len)
				{
					int q=check(c,L,R-len+1);
					if(q>=0)
					{
						cout<<len<<' '<<q+1<<' '<<c+1<<'\n';
						return 0;
					}
				}
			}
		}
		for(int i=0;i<2*N;++i)
			tree[i].clear();
	}
}
