#include "bits/stdc++.h"
using namespace std;

template<int MOD>
struct ModInt {
	static const int Mod = MOD;
	unsigned x;
	ModInt() : x(0) { }
	ModInt(signed sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
	ModInt(signed long long sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
	int get() const { return (int)x; }

	ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }

	ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
	ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
	ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
};

struct PolynomialHashKD {
	static const int D = 2;
	static const int NumMods = 5;
	static const unsigned Mods[NumMods];
	typedef unsigned long long ull;
	struct Hash {
		unsigned hs[NumMods];
		Hash() { for (int k = 0; k < NumMods; ++ k) hs[k] = 0; }
		Hash(unsigned x) {
			if (x < Mods[NumMods - 1]) {
				for (int k = 0; k < NumMods; ++ k) hs[k] = x;
			} else {
				for (int k = 0; k < NumMods; ++ k) hs[k] = x % Mods[k];
			}
		}
		bool operator==(const Hash &that) const {
			bool res = true;
			for (int k = 0; k < NumMods; ++ k)
				res &= hs[k] == that.hs[k];
			return res;
		}
		bool operator<(const Hash &that) const {
			for (int k = 0; k < NumMods; ++ k)
				if (hs[k] != that.hs[k])
					return hs[k] < that.hs[k];
			return false;
		}
		Hash &operator+=(const Hash &that) {
			for (int k = 0; k < NumMods; ++ k)
				if ((hs[k] += that.hs[k]) >= Mods[k])
					hs[k] -= Mods[k];
			return *this;
		}
		Hash operator+(const Hash &that) const { return Hash(*this) += that; }
		Hash &operator-=(const Hash &that) {
			for (int k = 0; k < NumMods; ++ k)
				if ((hs[k] += Mods[k] - that.hs[k]) >= Mods[k])
					hs[k] -= Mods[k];
			return *this;
		}
		Hash operator-(const Hash &that) const { return Hash(*this) -= that; }
		Hash operator*(const Hash &that) const {
			Hash res;
			for (int k = 0; k < NumMods; ++ k)
				res.hs[k] = (ull)hs[k] * that.hs[k] % Mods[k];
			return res;
		}
	};
	static Hash seeds[D];
	static std::vector<Hash> powh[D];

	static void initSeeds() {
		random_device rd;
		for (int d = 0; d < D; ++ d)
			for (int k = 0; k < NumMods; ++ k) {
				unsigned x;
				do x = rd(); while (x == 0 || x >= Mods[k]);
				seeds[d].hs[k] = x;
			}
	}
	static void precomputePowerTable(int newSize) {
		if ((int)powh[0].size() >= newSize) return;
		if (seeds[0].hs[0] == 0) initSeeds();
		for (int d = 0; d < D; ++ d) {
			int oldSize = powh[d].size();
			powh[d].resize(newSize);
			if (oldSize == 0)
				for (int k = 0; k < NumMods; ++ k) powh[d][0].hs[k] = 1;
			for (int i = std::max(1, oldSize); i < newSize; i ++) for (int k = 0; k < NumMods; ++ k)
				powh[d][i].hs[k] = (ull)powh[d][i - 1].hs[k] * seeds[d].hs[k] % Mods[k];
		}
	}
};
const unsigned PolynomialHashKD::Mods[PolynomialHashKD::NumMods] = { 2147483647U, 2147483629U, 2147483587U, 2147483579U, 2147483563U };
PolynomialHashKD::Hash PolynomialHashKD::seeds[PolynomialHashKD::D];
std::vector<PolynomialHashKD::Hash> PolynomialHashKD::powh[PolynomialHashKD::D];

struct SubrectangleHash : PolynomialHashKD {
	std::vector<std::vector<Hash> > preh;

	template<typename V>
	void init(const V &v, int n, int m) {
		precomputePowerTable(std::max(n, m) + 1);
		preh.assign(n + 1, std::vector<Hash>(m + 1));
		for (int i = 0; i < n; i ++) for (int j = 0; j < m; ++ j) {
			Hash t(v[i][j]);
			t += preh[i][j + 1] * seeds[0];
			t += preh[i + 1][j] * seeds[1];
			t -= preh[i][j] * seeds[0] * seeds[1];
			preh[i + 1][j + 1] = t;
		}
	}

	Hash hash(int i, int j) const {
		return preh[i][j];
	}
	Hash hash(int il, int jl, int iu, int ju) const {
		Hash res;
		res += preh[iu][ju];
		res -= preh[il][ju] * powh[0][iu - il];
		res -= preh[iu][jl] * powh[1][ju - jl];
		res += preh[il][jl] * powh[0][iu - il] * powh[1][ju - jl];
		return res;
	}
};


int main() {
	int N;
	while (~scanf("%d", &N)) {
		vector<string> S(N * 2);
		for (int i = 0; i < N; ++ i) {
			cin >> S[i];
			S[i] += S[i];
			S[N + i] = S[i];
		}
		vector<string> T(N * 2, string(N * 2, 0));
		for (int i = 0; i < N * 2; ++ i)
			for (int j = 0; j < N * 2; ++ j)
				T[i][j] = S[j][i];
		SubrectangleHash hS, hT;
		hS.init(S, N * 2, N * 2);
		hT.init(T, N * 2, N * 2);
		int ans = 0;
		for (int i = 0; i < N; ++ i)
			for (int j = 0; j < N; ++ j)
				ans += hS.hash(i, j, N + i, N + j) == hT.hash(j, i, N + j, N + i);
		printf("%d\n", ans);
	}
}


Measured memory_bytes: 15360