#include <bits/stdc++.h>
using namespace std;
const int maxn = 7e2 + 10;
int n;
char str[maxn][maxn];
bool judge(int x, int y) {
  int num = 1e8 / n;
  for (int k = 0; k < num; k++) {
    int i = rand() % n;
    int j = rand() % n;
    if (str[x + i][y + j] != str[x + j][y + i]) return false;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (str[i + x][j + y] != str[x + j][y + i]) return false;
    }
  }
  return true;
}
void solve() {
  int ans = 0;
  for (int j = 0; j < n; j++) {
    if (judge(0, j)) ans += n;
  }
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  srand(time(NULL));
  cin >> n;
  for (int i = 0; i < n; i++) cin >> str[i];
  for (int i = 0; i < n + n; i++) {
    for (int j = 0; j < n + n; j++) {
      if (i < n && j < n) continue;
      str[i][j] = str[i % n][j % n];
    }
  }
  solve();
  return 0;
}
