#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long int n;
  cin >> n;
  string s;
  char data[1000][1000] = {0};
  for (long long int i = 0; i < n; i++) {
    cin >> s;
    for (long long int j = 0; j < n; j++) {
      data[i][j] = s.at(j);
      data[i][j + n] = s.at(j);
      data[i + n][j] = s.at(j);
      data[i + n][j + n] = s.at(j);
    }
  }
  long long int cnt = 0;
  for (long long int a = 0; a < n; a++) {
    long long int b = 0;
    if (0) cout << "a=" << a << " b=" << b << endl;
    long long int flag = 0;
    for (long long int y = 0; y < n; y++) {
      for (long long int x = 0; x < n; x++) {
        long long int nextI = y + b;
        long long int nextJ = x + a;
        long long int targetI = x + b;
        long long int targetJ = y + a;
        if (0) {
          cout << "nextI=" << nextI << " nextJ=" << nextJ << endl;
          cout << "data[i][j]=" << data[nextI][nextJ]
               << " data[j][i]=" << data[targetI][targetJ] << endl;
        }
        if (data[nextI][nextJ] != data[targetI][targetJ]) {
          flag = 1;
          break;
        }
      }
      if (flag) break;
    }
    if (flag == 0) cnt += n;
  }
  cout << cnt << endl;
  return 0;
}
