#include "bits/stdc++.h"
#define ff first
#define ss second
#define szof(_x) ((int) (_x).size())
#define TASK_NAME ""

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9 + 7;
const ll INFL = 1e18 + 123;
const double PI = atan2(0, -1);
mt19937 tw(960172);
ll rnd(ll x, ll y) { static uniform_int_distribution<ll> d; return d(tw) % (y - x + 1) + x; }

template<int prime, int phi>
struct mod_int {
  static int const modulo = prime;
  static int const phi_modulo = phi;

  mod_int(int value)
    : value(value)
    , inv_(-1)
  {
    assert(value >= 0 && value < prime);
  }

  mod_int(long long value)
    : value((value % prime + prime) % prime)
    , inv_(-1)
  {}

  mod_int()
    : value(0)
    , inv_(-1)
  {}

  mod_int<prime, phi> &operator+=(mod_int<prime, phi> const &a) {
    value += a.value;
    if (value >= prime) {
      value -= prime;
    }
    inv_ = -1;
    return *this;
  }

  mod_int<prime, phi> &operator-=(mod_int<prime, phi> const &a) {
    value -= a.value;
    if (value < 0) {
      value += prime;
    }
    inv_ = -1;
    return *this;
  }

  mod_int<prime, phi> &operator*=(mod_int<prime, phi> const &a) {
    value = (long long) value * a.value % prime;
    if (inv_ != -1 && a.inv_ != -1) {
      inv_ = (long long) inv_ * a.inv_ % prime;
    } else {
      inv_ = -1;
    }
    return *this;
  }

  mod_int<prime, phi> &operator/=(mod_int<prime, phi> a) {
    assert(a.value != 0);
    value = (long long) value * a.inv().value % prime;
    if (inv_ != -1) {
      inv_ = (long long) inv_ * a.value % prime;
    }
    return *this;
  }

  mod_int<prime, phi> inv() const {
    if (inv_ == -1 && value != 0) {
      inv_ = pow(phi - 1).value;
    }
    return inv_;
  }

  mod_int<prime, phi> pow(long long ind) const {
    int res = 1;
    int a = value;
    for (; ind > 0; ind >>= 1) {
      if (ind & 1) {
        res = (long long) res * a % prime;
      }
      a = (long long) a * a % prime;
    }
    return mod_int<prime, phi>(res);
  }

  explicit operator int() const {
    return value;
  }

  int value;
  mutable int inv_;
};

template<int p, int q> mod_int<p, q> operator+(mod_int<p, q> a, mod_int<p, q> const &b) { return a += b; }
template<int p, int q> mod_int<p, q> operator-(mod_int<p, q> a, mod_int<p, q> const &b) { return a -= b; }
template<int p, int q> mod_int<p, q> operator*(mod_int<p, q> a, mod_int<p, q> const &b) { return a *= b; }
template<int p, int q> mod_int<p, q> operator/(mod_int<p, q> a, mod_int<p, q> const &b) { return a /= b; }
template<int p, int q> bool operator==(mod_int<p, q> const &a, mod_int<p, q> const &b) { return a.value == b.value; };
template<int p, int q> bool operator!=(mod_int<p, q> const &a, mod_int<p, q> const &b) { return a.value != b.value; };
template<int p, int q> ostream &operator<<(ostream &os, mod_int<p, q> const &m) { return os << m.value; }
template<int p, int q> istream &operator>>(istream &is, mod_int<p, q> &m) { m.inv_ = -1; return is >> m.value; }

typedef mod_int<1000000007, 1000000007 - 1> mint;

const mint P1 = 239, P2 = 179;

vector<vector<mint>> arrh[2];
vector<mint> p1pow, p2pow;

mint get_hash(int t, int x1, int y1, int x2, int y2) {
	if (t == 0) {
		return arrh[0][x2][y2] - arrh[0][x1][y2] * p1pow[x2 - x1] - arrh[0][x2][y1] * p2pow[y2 - y1] + arrh[0][x1][y1] * p1pow[x2 - x1] * p2pow[y2 - y1];
	}
	return arrh[1][x2][y2] - arrh[1][x1][y2] * p2pow[x2 - x1] - arrh[1][x2][y1] * p1pow[y2 - y1] + arrh[1][x1][y1] * p2pow[x2 - x1] * p1pow[y2 - y1];
}

void solve() {
	int n;
	cin >> n;

	p1pow.push_back(1);
	p2pow.push_back(1);
	for (int i = 0; i < n + 4; ++i) {
		p1pow.push_back(p1pow.back() * P1);
		p2pow.push_back(p2pow.back() * P2);
	}
	
	arrh[0] = vector<vector<mint>>(n + 1, vector<mint>(n + 1));
	arrh[1] = vector<vector<mint>>(n + 1, vector<mint>(n + 1));
	for (int i = 0; i < n; ++i) {
		string s;
		cin >> s;
		for (int j = 0; j < n; ++j) {
			int cur = s[j] - 'a' + 1;
			arrh[0][i + 1][j + 1] = arrh[0][i][j + 1] * P1 + arrh[0][i + 1][j] * P2 - arrh[0][i][j] * P1 * P2 + mint(cur);
			arrh[1][i + 1][j + 1] = arrh[1][i][j + 1] * P2 + arrh[1][i + 1][j] * P1 - arrh[1][i][j] * P1 * P2 + mint(cur);
		}
	}

	//cerr << get_hash(0, 0, 1, 2, 2) << " " << get_hash(0, 0, 0, 2, 1) << " " << get_hash(0, 0, 1, 0, 2) << " " << get_hash(0, 0, 0, 0, 1) << endl;

	int ans = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			//cerr << get_hash(0, i, j, n, n) * p1pow[i] * p2pow[j] << " " << get_hash(0, i, 0, n, j) * p2pow[j] << " " << get_hash(0, 0, j, i, n) * p1pow[i] << " " << get_hash(0, 0, 0, i, j) << endl;
			//cerr << j << " " << p2pow[j] << " " << get_hash(0, i, 0, n, j) << endl;
			mint h1 = get_hash(0, i, j, n, n) * p1pow[i] * p2pow[j] + get_hash(0, i, 0, n, j) * p1pow[i] + get_hash(0, 0, j, i, n) * p2pow[j] + get_hash(0, 0, 0, i, j);
			mint h2 = get_hash(1, i, j, n, n) * p2pow[i] * p1pow[j] + get_hash(1, i, 0, n, j) * p2pow[i] + get_hash(1, 0, j, i, n) * p1pow[j] + get_hash(1, 0, 0, i, j);
			//cerr << i << " " << j << " " << h1 << " " << h2 << endl;
			if (h1 == h2) {
				++ans;
			}
		}
	}
	cout << ans << "\n";
}


int main() {
	//freopen(TASK_NAME ".in", "r", stdin);
	//freopen(TASK_NAME ".out", "w", stdout);
	cerr << fixed << setprecision(15);
	cout << fixed << setprecision(15);
	ios::sync_with_stdio(false);

	int tests = 1;
	// cin >> tests;
	for (int it = 1; it <= tests; ++it) {
		solve();
	}
	
	#ifdef LOCAL
		cerr << "time: " << clock() << " ms\n";
	#endif
	return 0;
}

Measured memory_bytes: 1664