#include <bits/stdc++.h>

using ll = long long;
#define int long long

namespace ext {
	template <class T>
	struct vec_type;
	template <class T>
	constexpr bool is_vec_v;
	using namespace std;
	template<class T>
	struct Vector : std::vector<T> {
		using std::vector<T>::vector;
		char dil = ' ';
		Vector<T> accum() {
			Vector<T> res(this->size() + 1);
			for (size_t i = 0; i < this->size(); i++) {
				res[i+1] = (*this)[i] + res[i];
			}
			return res;
		}
		template<class U = T>
		typename enable_if<is_vec_v<U>, Vector<T>>::type accum2D() {
			const size_t H = this->size();
			const size_t W = (*this)[0].size();
			using S = typename vec_type<U>::type;
			Vector<T> res(H + 1, Vector<S>(W + 1));
			for (size_t i = 0; i < H; i++) {
				for (size_t j = 0; j < W; j++) {
					res[i+1][j+1] = (*this)[i][j];
					res[i+1][j+1] += res[i][j+1];
					res[i+1][j+1] += res[i+1][j];
					res[i+1][j+1] -= res[i][j];
				}
			}
			return res;
		}
		Vector<T> zaatsu() {
			map<T, int> m;
			for (auto& e: *this) m[e] = 1;
			int count = 0;
			for (auto& e: m) e.second = count++;
			Vector<T> res = *this;
			for (auto& e: res) e = m[e];
			return res;
		}
		friend istream& operator>>(istream& is, Vector<T>& t) {
			for (auto& e: t) cin >> e;
			return is;
		}
		friend ostream& operator<<(ostream& os, Vector<T>& t) {
			t.print(' ', os);
			return os;
		}
		void print(char del = ' ', ostream& os = cout) {
			for (size_t i = 0; i < this->size(); i++) {
				os << (*this)[i];
				if (i + 1 != this->size()) os << del;
				os.flush();
			}
		}
		void println(char del = ' ', ostream& os = cout) {
			print(del, os);
			cout << endl;
		}
		long long crossing_merge() {
			auto t = *this;
			return t.crossing_merge_sub();
		}
		// [min_v, max_v)
		long long crossing_bit(T min_v = -1, T max_v = -1) {
			if (min_v == -1) min_v = this->min();
			if (max_v == -1) max_v = this->max() + 1;
			Vector<T> bit(max_v - min_v + 1, 0);
			long long res = 0;
			for (auto e: *this) {
				e = max_v - e;
				for (size_t x = e - 1; x; x -= x & -x) {
					res += bit[x];
				}
				for (size_t x = e; x < bit.size() ; x += x & -x) {
					bit[x]++;
				}
			}
			return res;
		}
		bool permutation() {
			return next_permutation(this->begin(), this->end());
		}
		T& max() {
			return *max_element(this->begin(), this->end());
		}
		T& min() {
			return *min_element(this->begin(), this->end());
		}
private:
		long long crossing_merge_sub() {
			if (this->size() == 1) return 0;
			int x = this->size() / 2;
			Vector<T> left(this->begin(), this->begin() + x);
			Vector<T> right(this->begin() + x, this->end());
			long long res = left.crossing_merge_sub() + right.crossing_merge_sub();
			left.push_back(numeric_limits<T>::max()); right.push_back(numeric_limits<T>::max());
			size_t l = 0, r = 0;
			while (l + r < this->size()) {
				if (left[l] < right[r]) {
					(*this)[l+r] = left[l];
					l++;
				} else {
					(*this)[l+r] = right[r];
					r++;
					res += x - l;
				}
			}
			return res;
		}
	};
	template <class T>
	struct vec_type : std::false_type {};
	template <class T>
	struct vec_type<Vector<T>> : std::true_type {
		using type = T;
	};
	template <class T>
	constexpr bool is_vec_v = vec_type<T>::value;
}

// [a -> b-1]
#define reps(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
// [0 -> a-1]
#define rep(i, a) reps(i, 0, (a))
// [a-1 -> b]
#define rreps(i, a, b) for (int i = (int)((a)-1); i >= (int)(b); i--)
// [a-1 -> 0]
#define rrep(i, a) rreps(i, a, 0)
#define all(v) (v).begin(), (v).end()
// next_permutation(all(v))
#define PERM(v) next_permutation(all(v))
/*sort(all(v));
 * (v).erase(unique(all(v)), v.end())*/
#define UNIQUE(v)\
	sort(all(v));\
	(v).erase(unique(all(v)), v.end())
#define MINV(v) min_element(all(v))
#define MAXV(v) max_element(all(v))
#define MIN3(a, b, c) min(min(a, b), c)
#define MIN4(a, b, c, d) min(MIN3(a, b, c), d)
#define MIN5(a, b, c, d, e) min(MIN4(a, b, c, d), e)
#define MIN6(a, b, c, d, e, f) min(MIN5(a, b, c, d, e), f)
#define MAX3(a, b, c) max(max(a, b), c)
#define MAX4(a, b, c, d) max(MAX3(a, b, c), d)
#define MAX5(a, b, c, d, e) max(MAX4(a, b, c, d), e)
#define MAX6(a, b, c, d, e, f) max(MAX5(a, b, c, d, e), f)
// b is [a, c)
#define RANGE(a, b, c) ((a) <= (b) && (b) < (c))
// c is [a, e) && d is [b, f)
#define RANGE2D(a, b, c, d, e, f) (RANGE((a), (c), (e)) && RANGE((b), (d), (f)))
#define chmin(a, b) a = min(a, (b))
#define chmin3(a, b, c) a = MIN3(a, (b), (c))
#define chmin4(a, b, c, d) a = MIN4(a, (b), (c), (d))
#define chmin5(a, b, c, d, e) a = MIN5(a, (b), (c), (d), (e))
#define chmin6(a, b, c, d, e, f) a = MIN6(a, (b), (c), (d), (e), (f))
#define chmax(a, b) a = max(a, (b))
#define chmax3(a, b, c) a = MAX3(a, (b), (c))
#define chmax4(a, b, c, d) a = MAX4(a, (b), (c), (d))
#define chmax5(a, b, c, d, e) a = MAX5(a, (b), (c), (d), (e))
#define chmax6(a, b, c, d, e, f) a = MAX6(a, (b), (c), (d), (e), (f))
#define fcout cout << fixed << setprecision(15)
#define YES(f) cout << ((f) ? YES_STR : NO_STR) << endl;

using namespace std;
using namespace ext;


#define cin input
#define cout output

namespace mylib {
template<int mod>
struct ModInt {
	using ll = long long;
	int x;
	constexpr static int M = mod;
	ModInt(ll x_) {
		x = x_ % mod;
		if (x < 0) x += mod;
	}
	ModInt() : ModInt(0) {}
	inline ModInt& operator+=(const ModInt rhs) {
		ll t = (ll) x + rhs.x;
		if (t >= mod) x = t - mod;
		else x = t;
		return (*this);
	}
	inline ModInt& operator-=(const ModInt rhs) {
		ll t = (ll) x + mod - rhs.x;
		x += mod - rhs.x;
		if (t >= mod) x = t - mod;
		else x = t;
		return *this;
	}
	inline ModInt& operator*=(const ModInt rhs) {
		x = ((ll) x * rhs.x) % mod;
		return *this;
	}
	inline ModInt& operator/=(ModInt rhs) {
		return *this *= rhs.inv();
	}
	inline ModInt powerer(ll p) {
		ModInt res = 1;
		ModInt a = x;
		for (; p; res = p & 1 ? res * a : res, a *= a, p >>= 1);
		return res;
	}
	inline ModInt inv() {
		int z, w;
		extgcd(mod, x, z, w);
		return ModInt(w);
	}
	inline ModInt& operator=(const ModInt& rhs) {
		this->x = rhs.x;
		return *this;
	}
	inline int operator==(const ModInt& rhs) const {
		return this->x == rhs.x;
	}
	inline int operator!=(const ModInt& rhs) const {
		return !(*this == rhs);
	}
	inline ModInt operator++(signed unused) {
		ModInt res(*this);
		++(*this);
		return res;
	}
	inline ModInt& operator++() {
		(*this) += 1;
		return (*this);
	}
	inline ModInt operator--(signed unused) {
		ModInt res(*this);
		--(*this);
		return res;
	}
	inline ModInt& operator--() {
		(*this) -= 1;
		return (*this);
	}
	inline ModInt operator+() const {
		return (*this);
	}
	inline ModInt operator-() const {
		return (*this).x ? ModInt(mod - (*this).x) : ModInt(0);
	}
	friend const ModInt operator+(const ModInt& lhs, const ModInt& rhs) {return ModInt(lhs) += rhs;}
	friend const ModInt operator-(const ModInt& lhs, const ModInt& rhs) {return ModInt(lhs) -= rhs;}
	friend const ModInt operator*(const ModInt& lhs, const ModInt& rhs) {return ModInt(lhs) *= rhs;}
	friend const ModInt operator/(const ModInt& lhs, const ModInt& rhs) {return ModInt(lhs) /= rhs;}
	explicit operator int() const {return x;}
	friend ostream& operator<<(ostream& lhs, const ModInt& rhs) {
		lhs << rhs.x;
		return lhs;
	}
	friend istream& operator>>(istream& lhs, ModInt& rhs) {
		long long t;
		lhs >> t;
		rhs = ModInt(t);
		return lhs;
	}
	int extgcd(int a, int b, int& x, int& y) {
		int d = a;
		if (b == 0) {
			x = 1;
			y = 0;
		} else {
			d = extgcd(b, a%b, y, x);
			y -= a / b * x;
		}
		return d;
	}
};
}; // mylib
using namespace mylib;
//using modint = ModInt<1000000007>;
//using modint = ModInt<998244353>;

namespace rolling_hash {
template<uint_fast32_t max_size, uint_fast64_t mod = (1UL << 61) - 1, uint_fast64_t MASK30 = (1UL << 30) - 1, uint_fast64_t MASK31 = (1UL << 31) - 1>
struct RollingHash {
	using hash_type = uint_fast64_t;
	uint_fast32_t base;
	int sz;
	vector<hash_type> hash;
	static vector<hash_type> power;
	RollingHash(const string& s) : base(10009), sz(s.length()), hash(sz + 1, 0) {
		for (int i = 0; i < sz; i++) {
			hash[i+1] = calc_mod(mul(hash[i], base) + s[i]);
		}
		if (power[0] == 0) {
			power[0] = 1;
			for (uint_fast32_t i = 0; i < max_size; i++) {
				power[i+1] = calc_mod(mul(power[i], base));
			}
		}
	}
	inline hash_type mul(hash_type a, hash_type b) {
		hash_type au = a >> 31;
		hash_type ad = a & MASK31;
		hash_type bu = b >> 31;
		hash_type bd = b & MASK31;
		hash_type mid = ad * bu + au * bd;
		return ((au * bu) << 1) + ad * bd + ((mid & MASK30) << 31) + (mid >> 30);
	}
	inline hash_type calc_mod(hash_type a) {
		a = (a & mod) + (a >> 61);
		if (a >= mod) a -= mod;
		return a;
	}
	inline hash_type get(int l, int r) {
		return calc_mod(hash[r] + mod * 7 - mul(hash[l], power[r-l]));
	}
	inline hash_type connect(hash_type h1, hash_type h2, int h2_len) {
		return calc_mod(mul(h1, power[h2_len]) + h2);
	}
	inline hash_type connect(int l1, int r1, int l2, int r2) {
		return connect(get(l1, r1), get(l2, r2), r2 - l2);
	}
};
template<uint_fast32_t a, uint_fast64_t b, uint_fast64_t c, uint_fast64_t d>
vector<typename RollingHash<a, b, c, d>::hash_type> RollingHash<a, b, c, d>::power(a+1);
} 
using namespace rolling_hash;

void solve(istream& input, ostream& output) {
	int N; cin >> N;
	vector<string> R(N);
	vector<string> C(N);
	vector<RollingHash<300>> RR;
	vector<RollingHash<300>> RC;
	rep(i, N) {
		cin >> R[i];
		RR.emplace_back(R[i]);
	}
	rep(i, N) {
		rep(j, N) {
			C[i] += R[j][i];
		}
		RC.emplace_back(C[i]);
	}
	int res = 0;
	rep(i, N) {
		rep(j, N) {
			bool f = true;
			// cout << i << " " << j << endl;
			int r = i, c = j;
			rep(k, N) {
				// if (++cnt % 10000 == 0) cout << cnt << endl;
				// cout << k << endl;
				f &= RR[r].connect(j, N, 0, j) == RC[c].connect(i, N, 0, i);
				// reps(l, j, N) cout << R[k][l];
				// reps(l, 0, j) cout << R[k][l];
				// cout << endl;
				// reps(l, i, N) cout << C[k][l];
				// reps(l, 0, i) cout << C[k][l];
				// cout << endl;
				if (++r == N) r -= N;
				if (++c == N) c -= N;
			}
			res += f;
		}
	}
	// cout << cnt << endl;
	cout << res << endl;
}

#undef cin
#undef cout

#ifndef CHECK_CPP

signed main() {
	solve(cin, cout);
}

#endif


Measured memory_bytes: 2048