#include <bits/stdc++.h>
using namespace std;
char s[1500][1500];
int b[1500][1500];
int main() {
  int n, i, j, k;
  map<char, string> mp;
  mp['0'] = "00";
  mp['1'] = "01";
  mp['2'] = "01";
  mp['3'] = "02";
  mp['4'] = "10";
  mp['5'] = "11";
  mp['6'] = "11";
  mp['7'] = "12";
  mp['8'] = "10";
  mp['9'] = "11";
  mp['A'] = "11";
  mp['B'] = "12";
  mp['C'] = "20";
  mp['D'] = "21";
  mp['E'] = "21";
  mp['F'] = "22";
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> s[i];
  }
  for (i = 0; i < n; i += 2) {
    for (j = 0; j < n / 4; j++) {
      int x1, x2, y1, y2;
      x1 = mp[s[i][j]][0] - '0';
      x2 = mp[s[i][j]][1] - '0';
      y1 = mp[s[i + 1][j]][0] - '0';
      y2 = mp[s[i + 1][j]][1] - '0';
      b[i / 2][j * 2] = x1 + y1;
      b[i / 2][j * 2 + 1] = x2 + y2;
    };
  }
  for (i = n / 2; i >= 1; i--) {
    for (j = n / 2; j >= 1; j--) {
      b[i][j] = b[i - 1][j - 1];
    }
  }
  for (int i = 1; i <= n / 2; i++) {
    for (int j = 1; j <= n / 2; j++) {
      cout << b[i][j];
    }
    cout << endl;
  }
  n = n / 2;
  for (i = n; i >= 1; i--) {
    if (n % i != 0) continue;
    int flag = 1;
    for (j = i; j <= n; j += i) {
      for (k = i; k <= n; k += i) {
        int sum = b[j][k] - b[j - i][k] - b[j][k - i] + b[j - i][k - i];
        if (sum != 0 && sum != i * i) {
          flag = 0;
          break;
        }
      }
    }
    if (flag == 1) {
      cout << i * 2 << endl;
      return 0;
    }
  }
  cout << 1 << endl;
}
