#include "bits/stdc++.h"

using namespace std;

using ll = long long;

int n;

bool check(const vector<string> &ban, int k) {
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < i; ++j) {
      if (ban[i][(j + k) % n] != ban[j][(i + k) % n])
        return 0;
    }
  }
  return 1;
}

int main() {
  cin >> n;
  vector<string> ban(n);
  for (int i = 0; i < n; ++i) {
    cin >> ban[i];
  }
  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    if (check(ban, i)) {
      ans += n;
    }
  }
  cout << ans << endl;
}