#include <bits/stdc++.h>
using namespace std;
const int N = 305;
const long long P = 37, Q = 89;
int n, ans;
long long a[N][N], b[N][N], p[N][N], q[N][N], d[N];
char c[N][N];
void work(long long a[][N], long long p[][N]) {
  for (int i = 1; i <= n; i++) {
    for (int k = 1; k <= n; k++) d[k] = a[1][k];
    for (int j = 1; j < n; j++)
      for (int k = 1; k <= n; k++) a[j][k] = a[j + 1][k];
    for (int k = 1; k <= n; k++) a[n][k] = d[k];
    memset(d, 0, sizeof(d));
    for (int j = 1; j <= n; j++)
      for (int k = 1; k <= n; k++) d[j] = d[j] * P + a[k][j];
    for (int j = 1; j <= n; j++) {
      p[i][j] = 0;
      for (int k = 0; k < n; k++)
        p[i][j] = p[i][j] * Q + d[(j + k - 1) % n + 1];
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%s", c[i] + 1);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) a[i][j] = c[i][j];
  work(a, p);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) b[i][j] = c[j][i];
  work(b, q);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      if (p[i][j] == q[j][i]) ans++;
  printf("%d\n", ans);
  return 0;
}
