#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<string> line;
  line.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> line[i];
  }
  int a = 0;
  int cnt = 0;
  for (int a = 0; a < n; a++) {
    int init = 1;
    for (int i = 0; i < n; i++) {
      for (int j = init; j < n; j++) {
        if ((j + a) % n != 0) {
          if (line[i][(j + a) % n] != (line[(j + a) % n][i])) {
            goto L_NEXT;
          }
        }
      }
    }
    cnt++;
  L_NEXT:
    init++;
  }
  cout << cnt * n;
  return 0;
}
