#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
inline void write(int x) {
  if (x >= 10) write(x / 10);
  putchar('0' + x % 10);
}
int n;
char s[777][777];
int main() {
  n = read();
  for (int i = 1; i <= n; ++i) scanf(" %s", s[i] + 1);
  int ans = 0, f = 0;
  for (register int a = 0; a < n; ++a)
    for (register int b = 0; b < a; ++b) {
      f = 0;
      for (register int i = 1; i <= n; ++i) {
        for (register int j = 1; j <= n; ++j) {
          if (s[(i - 1 + a) % n + 1][(j - 1 + b) % n + 1] !=
              s[(j - 1 + a) % n + 1][(i - 1 + b) % n + 1]) {
            f = 1;
            break;
          }
        }
        if (f) break;
      }
      if (!f) ++ans;
    }
  ans *= 2;
  for (register int a = 0; a < n; ++a) {
    f = 0;
    for (register int i = 1; i <= n; ++i) {
      for (register int j = 1; j <= n; ++j) {
        if (s[(i - 1 + a) % n + 1][(j - 1 + a) % n + 1] !=
            s[(j - 1 + a) % n + 1][(i - 1 + a) % n + 1]) {
          f = 1;
          break;
        }
      }
      if (f) break;
    }
    if (!f) ++ans;
  }
  write(ans);
  puts("");
  return 0;
}
