#include <bits/stdc++.h>
int main(void) {
  int N;
  scanf("%d", &N);
  char s[N][N];
  int i, j, k;
  for (i = 0; i < N; i++) {
    scanf("%s", s[i]);
  }
  int A, B, count = 0;
  bool ch;
  int a, b;
  for (i = 0; i < N; i++) {
    if (N == 1) break;
    if (s[0][(N + i) % N] == s[1][(N + i - 1) % N]) {
      for (k = 0; k < N; k++) {
        for (j = k + 1; j < N; j++) {
          ch = (s[k][(N + j + i - 1) % N] == s[(j) % N][(N + k + i - 1) % N]);
          if (!ch) break;
        }
        if (!ch) break;
      }
      if (ch) count += N;
    }
  }
  printf("%d", count);
}
