#include <bits/stdc++.h>
using namespace std;
#define BS 313
#define ull unsigned long long
#define rint register int
#define gc() getchar()
inline int read(int r=0,int s=0,int c=gc()){for(;c<48||c>57;s=c,c=gc());for(;c>=48&&c<=57;(r*=10)+=c-48,c=gc());return s^'-'?r:-r;}
ull H[605][605], R[605][605], B[605]; char S[605][605]; int n, Ans;
inline ull HH(int i, int l, int r){return H[i][r]-H[i][l-1]*B[r-l+1];}
inline ull HR(int j, int l, int r){return R[r][j]-R[l-1][j]*B[r-l+1];}
inline bool Check(int a, int b)
{
	for(rint i = 1, x = a, y = b; i <= n; i++, x = x%n+1, y = y%n+1)
		if(HH(x,y,y+n-1) != HR(y,x,x+n-1)) return false; return true;
}
int main()
{
	n = read(); for(rint i = 1, j; i <= n; i++) for(scanf("%s",S[i]+1), j = 1; j <= n; S[i+n][j] = S[i][j+n] = S[i+n][j+n] = S[i][j], j++);
	B[0] = 1; B[1] = BS; for(rint i = 2; i <= n<<1; B[i] = B[i-1]*BS, i++);
	for(rint i = 1, j; i <= n<<1; i++) for(j = 1; j <= n<<1; H[i][j] = H[i][j-1]*BS+S[i][j], j++);
	for(rint j = 1, i; j <= n<<1; j++) for(i = 1; i <= n<<1; R[i][j] = R[i-1][j]*BS+S[i][j], i++);
	for(rint A = 1, B; A <= n; A++) for(B = 1; B <= n; B++) Ans += Check(A,B); printf("%d\n",Ans); return 0;
}