#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream& operator<<(ostream& out, const vector<T>& vec) {
  out << "[";
  for (int x : vec) out << x << ", ";
  out << "]";
  return out;
}
int n;
char g[700][700];
int s[700][700];
int calc(int x, int y) {
  for (int i = x - 1; i < 2 * n; i++)
    for (int j = y - 1; j < 2 * n; j++) s[i][j] = 0;
  for (int i = x; i < 2 * n && i < 2 * n + x - y; i++)
    for (int j = y; j < 2 * n && y < 2 * n + y - x; j++) {
      s[i][j] = (g[i][j] == g[j - y + x][i - x + y]) + s[i - 1][j] +
                s[i][j - 1] - s[i - 1][j - 1];
    }
  int ans = 0;
  for (int i = n - 1; x + i < 2 * n && y + i < 2 * n; i++) {
    if (s[x + i][y + i] - s[x + i - n][y + i] - s[x + i][y + i - n] +
            s[x + i - n][y + i - n] ==
        n * n)
      ans++;
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) cin >> g[i][j];
  for (int i = 1; i < 2 * n; i++)
    for (int j = n + 1; j < 2 * n; j++) g[i][j] = g[i][j - n];
  for (int i = n + 1; i < 2 * n; i++)
    for (int j = 1; j < 2 * n; j++) g[i][j] = g[i - n][j];
  int ans = calc(1, 1);
  for (int x = 2; x <= n; x++) ans += calc(x, 1);
  for (int y = 2; y <= n; y++) ans += calc(1, y);
  cout << ans << '\n';
  return 0;
}
