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

#define inf_ll (int64)1e18
#define inf (int32)1e9
#define rep(i, n) for(int64 i = 0;i < (n);i++)
#define for(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using pii = pair<int32, int32>;
using pll = pair<int64, int64>;

const double eps = 1e-10;

template<typename a, typename b>inline void chmin(a &a, b b){if(a > b) a = b;}
template<typename a, typename b>inline void chmax(a &a, b b){if(a < b) a = b;}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int32 n;
	cin >> n;
	vector<string> s(n*2);
	rep(i, n){
		cin >> s[i];
		s[i] += s[i];
		s[n+i] = s[i];
	}
	vector<vector<int32>> r(2*n, vector<int32>(2*n, 0));
	rep(i, 2*n){
		rep(j, 2*n){
			int32 cnt = 0;
			for(int32 k = 0;i+k < 2*n && j+k < 2*n;k++){
				if(s[i][j+k] == s[j][i+k]) cnt++;
				else break;
			}
			r[i][j] = cnt;
		}
	}
	int64 res = 0;
	REP(i, N){
		REP(j, N){
//			deque<PLL> deq;
//			deq.push_front(PLL(0, 2*N-max(i, j)));
			int64 mini = INF;
			for(int32 k = N-1;k >= 0;k--){
				int64 x = r[i+k][j+k];
				mini = min(mini, x+(int64)k);
				/*
				while(deq.size() && deq.front().sc-k > N-1) deq.pop_front();
				while(deq.size() && deq.back().fs+(deq.back().sc-k) > x) deq.pop_back();
				deq.push_back(PLL(x, k));
				cout << "(" << deq.front().fs << " " << deq.front().sc << " " << k << ") ";
				if(deq.front().fs+deq.front().sc-k >= N) res++;
				*/
			}
			if(mini >= N) res++;
		}
	}
	cout << res << endl;
}
