#include <bits/stdc++.h>
using namespace std;
int n, A[500][500], temp[500], ans, base[500];
int Hash[305][305][305][2];
void Get_hash(int x, int y) {
  int i;
  for (i = 1; i <= n; i++) {
    int pos = i + y;
    if (pos > n) pos -= n;
    temp[pos] = A[x][i];
  }
  int sum1 = 0, sum2 = 0;
  for (i = 1; i <= n; i++) sum1 = (sum1 + base[i] * temp[i]) % (983706);
  for (i = n; i >= 1; i--) sum2 = (sum2 + base[i] * temp[i]) % (983706);
  for (i = 1; i <= n; i++) Hash[x][i][y][0] = sum1 - temp[i] * base[i];
  for (i = n; i >= 1; i--) Hash[x][i][y][1] = sum2 - temp[i] * base[i];
}
int main() {
  srand(time(0));
  scanf("%d", &n);
  int i, j, a, b;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= n; j++) {
      char ch;
      cin >> ch;
      A[i][j] = ch - 'a';
    }
  for (i = 1; i <= n; i++) base[i] = 107 + rand() % 207;
  for (i = 1; i <= n; i++)
    for (j = 0; j < n; j++) Get_hash(i, j);
  for (a = 0; a < n; a++)
    for (b = 0; b < n; b++) {
      for (i = 1; i <= n; i++) {
        int pos1 = i + a;
        if (pos1 > n) pos1 -= n;
        int pos2 = n + 1 - pos1;
        int pos = pos2 - a;
        if (pos < 1) pos += n;
        if (Hash[i][pos1][b][0] == Hash[pos][pos2][b][1] &&
            Hash[i][pos1][b][1] == Hash[pos][pos2][b][0])
          continue;
        else
          break;
      }
      if (i > n) ans++;
    }
  cout << ans;
}
