#include<cstdio>

int main(){
	int N;
	scanf("%d", &N);
	char S[N][N];
	for (int i = 0; i < N; ++i){
		scanf("\n");
		for (int j = 0; j < N; ++j)	scanf("%c", &S[i][j]);
	}
	int answer = 0;
	for (int i = 0; i < N; ++i){
		bool flag = true;
		for (int j = 0; j < N - 1; ++j){
			for (int k = j + 1; k < N; ++k){
				if(S[(j + i) % N][k] != S[(k + i) % N][j]){
					flag = false;
					break;
				}
			}
			if(!flag) break;
		}
		if(flag) answer += N;
	}
	printf("%d\n", answer);
	return 0;
}