#include <bits/stdc++.h>
using namespace std;
namespace SHENZHEBEI {
static const int GYN = 2333333;
char SZB[GYN], *S = SZB, *T = SZB;
inline char gc() {
  if (S == T) {
    T = (S = SZB) + fread(SZB, 1, GYN, stdin);
    if (S == T) return '\n';
  }
  return *S++;
}
inline long long read() {
  long long x = 0, g = 1;
  char ch = gc();
  for (; !isdigit(ch); ch = gc())
    if (ch == '-') g = -1;
  for (; isdigit(ch); ch = gc()) x = x * 10 - 48 + ch;
  return x * g;
}
inline void write(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10) write(x / 10);
  putchar(x % 10 + '0');
}
inline char readchar() {
  char ch = gc();
  for (; isspace(ch); ch = gc())
    ;
  return ch;
}
inline long long readstr(char *s) {
  char ch = gc();
  int cur = 0;
  for (; isspace(ch); ch = gc())
    ;
  for (; !isspace(ch); ch = gc()) s[cur++] = ch;
  s[cur] = '\0';
  return cur;
}
void Print(long long *a, int s, int t) {
  for (int i = int(s); i <= int(t); ++i) printf("%lld ", a[i]);
}
void Print(int *a, int s, int t) {
  for (int i = int(s); i <= int(t); ++i) printf("%d ", a[i]);
}
void Print(char *a, int s, int t) {
  for (int i = int(s); i <= int(t); ++i) putchar(a[i]);
}
void writeln(long long x) {
  write(x);
  puts("");
}
}  // namespace SHENZHEBEI
using namespace SHENZHEBEI;
const long long N = 310;
long long answ, n, ans[N];
char s[N][N], t[N][N];
int main() {
  n = read();
  for (int i = int(1); i <= int(n); ++i) readstr(s[i] + 1);
  for (int i = int(0); i < int(n); ++i) ans[i] = 1;
  for (int i = int(1); i <= int(n); ++i)
    for (int j = int(1); j <= int(n); ++j) {
      for (int k = int(0); k < int(n); ++k) {
        long long x = i + k, y = j - k + n + n;
        for (; x > n; x -= n)
          ;
        for (; y > n; y -= n)
          ;
        ans[(i - j - k + n * 10) % n] &= s[i][j] == s[x][y];
      }
    }
  for (int i = int(0); i < int(n); ++i) answ += ans[i] * n;
  writeln(answ);
}
