#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
int n, a[2001][2001], st = 1, end = 0, sz = 0, ok = 0;
void in()
{ scanf("%d", &n);
  for (int i = 0; i < n; i++)
  for (int j = 0; j < n; j++)
  scanf("%d", &a[i][j]);
}

void Check(int s, int e, int szi)
{ //cout << "s = " << s << " e = " << e << " szi = " << szi << endl;
  //int ch = 0;
//  if (s == 2 && e == 1) ch++;
  for (int i = s; i < szi + s; i++)
  for (int j = e; j < szi + e; j++)
  { if (i > s && a[i][j] == a[i - 1][j]) continue;
    if (i < szi + s - 1 && a[i][j] == a[i + 1][j]) continue;
    if (j > e && a[i][j] == a[i][j - 1]) continue;
    if (j < szi + e - 1 && a[i][j] == a[i][j + 1]) continue;
    
    //if (ch != 0) cout << "i = " << i << " j = " << j << endl;
    ok++;
    return;
   }
}
    

void TestThisSize(int size)
{ for (int st = 1; st < n - size; st += size)
  for (int end = 1; end < n - size; end += size)
  { Check(st, end, size);
    if (ok == 0)
    { printf("%d %d %d\n", size, st + 1, end + 1); ok = -1; return; }
    
    else ok = 0;
   }
}

void make()
{ if (n % 2 == 0) sz = n - 2;
  else sz = n - 1;
  
  for (int i = sz; i > 1; i -= 2)
  { TestThisSize(i);
    if (ok == -1) return;
   }
}

int main()
{ 
  in();
  make();
  
  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
*/
