#include <bits/stdc++.h>
using namespace std;
vector<long long int> v;
void printDivisors(int n) {
  for (int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      if (n / i == i)
        v.push_back(i);
      else {
        v.push_back(i);
        v.push_back(n / i);
      };
    }
  }
  sort((v).begin(), (v).end());
}
void primeFactors(int n) {
  while (n % 2 == 0) {
    v.push_back(2);
    n = n / 2;
  }
  for (int i = 3; i <= sqrt(n); i = i + 2) {
    while (n % i == 0) {
      v.push_back(i);
      n = n / i;
    }
  }
  if (n > 2) v.push_back(n);
}
string HexToBin(char hexdec) {
  switch (hexdec) {
    case '0':
      return "0000";
      break;
    case '1':
      return "0001";
      break;
    case '2':
      return "0010";
      break;
    case '3':
      return "0011";
      break;
    case '4':
      return "0100";
      break;
    case '5':
      return "0101";
      break;
    case '6':
      return "0110";
      break;
    case '7':
      return "0111";
      break;
    case '8':
      return "1000";
      break;
    case '9':
      return "1001";
      break;
    case 'A':
    case 'a':
      return "1010";
      break;
    case 'B':
    case 'b':
      return "1011";
      break;
    case 'C':
    case 'c':
      return "1100";
      break;
    case 'D':
    case 'd':
      return "1101";
      break;
    case 'E':
    case 'e':
      return "1110";
      break;
    case 'F':
    case 'f':
      return "1111";
      break;
  }
}
bool check(long long *a, long long n, long long t) {
  bool flag = true;
  for (long long i = 1; i <= n; i = i + t) {
    for (long long j = 1; j <= n; j = j + t) {
      long long temp = *(a + i * n + j);
      for (long long int k = i; k < i + t; k++) {
        for (long long int l = j; l < j + t; l++) {
          if (*(a + k * n + l) != temp) {
            flag = false;
            break;
          }
        }
        if (flag == false) break;
      }
      if (flag == false) break;
    }
    if (flag == false) break;
  }
  return flag;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  while (TESTS--) {
    long long n;
    cin >> n;
    v.clear();
    primeFactors(n);
    long long a[n + 1][n + 1];
    char c;
    for (long long int i = 1; i < n + 1; i++) {
      for (long long int j = 1; j < n / 4 + 1; j++) {
        cin >> c;
        string s = HexToBin(c);
        a[i][4 * (j - 1) + 1] = s[0] - 48;
        a[i][4 * (j - 1) + 2] = s[1] - 48;
        a[i][4 * (j - 1) + 3] = s[2] - 48;
        a[i][4 * (j - 1) + 4] = s[3] - 48;
      }
    }
    long long i, j;
    long long ans = 1;
    long long l = 0, r = v.size() - 1;
    for (long long int i = 0; i < v.size(); i++) {
      cout << v[i] << '\n';
      if (check((long long int *)a, n, ans * v[i]) == true) ans = ans * v[i];
    }
    cout << ans << '\n';
  }
  return 0;
}
