#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main() {
int N; 
cin >> N; 
char C[610][610]; 
for(int i = 0; i < N; i++){
  for(int j = 0; j < N; j++){
cin >> C[i][j]; 
C[i+N][j] = C[i][j];
  }
}
int count = 0; 
for(int K = 0; K < N; K++){
int ans = 1; 
 for(int i = 0; i < N; i++){
  for(int j = i+1; j < N; j++){
 if(C[i+K][j] != C[j+K][i]){
 ans = 0; 
}
}
}
count += ans; 
}
cout << N * count << endl; 
}