#include <bits/stdc++.h>
using namespace std;
set<pair<int, int> > ab;
int main() {
  int counts[26] = {0};
  vector<int> rs[26];
  vector<int> cs[26];
  int n;
  cin >> n;
  string board[305];
  for (int i = 0; i < n; i++) {
    cin >> board[i];
    for (int j = 0; j < n; j++) {
      counts[board[i][j] - 'a']++;
      rs[board[i][j] - 'a'].push_back(i);
      cs[board[i][j] - 'a'].push_back(j);
    }
  }
  for (int j = 0; j < n; j++) {
    ab.insert(make_pair(0, j));
  }
  for (int i = 0; i < 26; i++) {
    set<pair<int, int> > new_ab;
    for (set<pair<int, int> >::iterator it = ab.begin(); it != ab.end(); it++) {
      int a = it->first;
      int b = it->second;
      set<pair<int, int> > complements;
      for (int j = 0; j < counts[i]; j++) {
        int r = rs[i][j];
        int c = cs[i][j];
        int r2 = (r + a) % n;
        int c2 = (c + b) % n;
        if (r2 == c2) continue;
        if (complements.find(make_pair(c2, r2)) != complements.end()) {
          complements.erase(make_pair(c2, r2));
        } else {
          complements.insert(make_pair(r2, c2));
        }
      }
      if (complements.size() == 0) {
        new_ab.insert(*it);
      }
    }
    ab = new_ab;
  }
  cout << ab.size();
}
