#include<iostream>
using namespace std;

struct brick{
            int pi,pj;
            bool t; // kude e vtorata chast , 0->otdolu 1->vdqsno
            }b[200001];
int a[2001][2001];
int c[2000][2000];
int pr[2001][2001];
int maxw;
int n,m;

int curw,ci,cj;
int jump;
void checka()
{
    int i,j;

    for(i=1;i<=n;i++)
    {
        for(j=1;j<=n;j++)
            cout<<a[i][j]<<' ';
        cout<<endl;
    }
}
void checkpr()
{
    int i,j;

    for(i=1;i<=n;i++)
    {
        for(j=1;j<=n;j++)
            cout<<pr[i][j]<<' ';
        cout<<endl;
    }
}
void checkc()
{
     int i,j;

    for(i=1;i<=m;i++)
    {
        for(j=1;j<=m;j++)
            cout<<c[i][j]<<' ';
        cout<<endl;
    }

}
void findmore()
{
    jump=curw;
    if(jump<m /*&& curw*2<maxw*/ )
    {
    int i,j;
    for(i=1;i<=m-2;i++)
        for(j=1;j<=m-2;j++)
        {
            if(c[i][j]==1 && c[i+jump][j]==1 && c[i][j+jump]==1 && c[i+jump][j+jump]==1)
            {
                if(curw==jump)
                {
                    c[i][j]=1;
                    curw=curw*2;
                    ci=i+1;
                    cj=i+1;
                }
            }
            else c[i][j]=0;
        }

    m=m-jump;
    findmore();
    }
}
int main()
{

    cin>>n;
    maxw=n-2;
    int i,j;
    for(i=1;i<=n;i++)
        for(j=1;j<=n;j++)
        {
            cin>>a[i][j];
            pr[i][j]=1;

            if(a[i][j]==a[i-1][j])
            {
                b[a[i][j]].pi=i-1;
                b[a[i][j]].pj=j;
                b[a[i][j]].t=0;
                pr[i][j]=0;
               // cout<<"CP"<<endl;
            }

            if(a[i][j]==a[i][j-1])
            {
                b[a[i][j]].pi=i;
                b[a[i][j]].pj=j-1;
                b[a[i][j]].t=1;
                pr[i][j]=0;
              //  cout<<"CP"<<endl;
            }
        }

    //for(i=1;i<=n*n/2;i++)
    //    cout<<b[i].t<<' ';
   // cout<<endl;
     //  checkpr();
 ///////////////////////////////////////////////////
    for(i=2;i<=n-1;i++)
        for(j=2;j<=n-1;j++)
            if(pr[i][j]==1)
        {
        //cout<<"YES : "<< i <<' '<<j<<endl;

        if(pr[i][j+1]==1 && b[a[i][j]].t==0 && b[a[i][j+1]].t==0)
        {
           // cout<<"right"<<endl;
            c[i-1][j-1]=1;
            if(curw==0){curw=2;ci=i;cj=j;}
        }
        if(pr[i+1][j]==1 && b[a[i][j]].t==1 && b[a[i+1][j]].t==1)
        {
            //cout<<"down"<<endl;
            c[i-1][j-1]=1;
            if(curw==0){curw=2;ci=i;cj=j;}
        }

    }

   // checka();
  //  cout<<curw<<endl;
    //checkc();

    m=n-curw-1;
    findmore();
    cout<<curw<<' '<<ci<<' '<<cj<<endl;
    return 0;
}

/*
6
1 1 4 4 13 14
2 3 3 5 13 14
2 6 7 5 12 12
9 6 7 10 10 15
9 8 8 11 11 15
16 16 17 17 18 18
*/
