#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int main() {
  long long n;
  cin >> n;
  vector<int> a(n, 0);
  char c;
  int otv = 0;
  vector<vector<int> > b(n, a);
  vector<vector<int> > bb;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> c;
      b[i][j] = c - 'a';
    }
  }
  bb = b;
  for (int i = 0; i < n; i++) {
    int f = 1;
    for (int j = 0; j < n; j++) {
      for (int q = 0; q < n; q++) {
        bb[j][(q + 1) % n] = b[j][q];
      }
    }
    b = bb;
    for (int j = 0; j < n; j++) {
      if (f == 0) break;
      for (int q = 0; q < n; q++) {
        if (b[j][q] != b[q][j]) {
          f = 0;
          break;
        }
      }
    }
    if (f) otv++;
  }
  cout << otv * n;
  return 0;
}
