Language: C++

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <map>
using namespace std;

#define rep(i,j,k) for(register int i=j;i<=k;++i)
#define dow(i,j,k) for(register int i=j;i<=k;--i)

inline int read(){
	char ch='*';int f=1;
	while(!isdigit(ch=getchar())) if(ch=='-') f=-1;int num=ch-'0';
	while(isdigit(ch=getchar())) num=num*10+ch-'0';
	return num*f;
}
const int N= 700;
char m[N][N];
char tmp[N][N];
int n;
int val,vis[N];
int main(){
	n=read();
	rep(i,1,n){
		scanf("%s",m[i]+1);
		rep(j,1,n) m[i+n][j]=m[i+n][j+n]=m[i][j+n]=m[i][j],val+=vis[m[I][j]^1,vis[m[I][j]]=1;
	}

if(val==1) {cout<<n*n<<endl;return 0;}
	int ans=0;
	rep(a,0,n-1)rep(b,0,n-1){
		int f=1;
		rep(i,1,n) rep(j,1,n) tmp[i][j]=m[i+a][j+b];
		rep(i,1,n) rep(j,1,n) if(tmp[i][j]!=tmp[j][i]) {f=0;break;}
		ans+=f;
		//cout<<ans<<endl;
	}
	cout<<ans<<endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:24:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   24 |         rep(i,1,n){
      |             ^
a.cc:8:37: note: in definition of macro 'rep'
    8 | #define rep(i,j,k) for(register int i=j;i<=k;++i)
      |                                     ^
a.cc:26:21: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   26 |                 rep(j,1,n) m[i+n][j]=m[i+n][j+n]=m[i][j+n]=m[i][j],val+=vis[m[I][j]^1,vis[m[I][j]]=1;
      |                     ^
a.cc:8:37: note: in definition of macro 'rep'
    8 | #define rep(i,j,k) for(register int i=j;i<=k;++i)
      |                                     ^
a.cc:26:79: error: 'I' was not declared in this scope
   26 |                 rep(j,1,n) m[i+n][j]=m[i+n][j+n]=m[i][j+n]=m[i][j],val+=vis[m[I][j]^1,vis[m[I][j]]=1;
      |                                                                               ^
a.cc:26:101: error: expected ']' before ';' token
   26 |                 rep(j,1,n) m[i+n][j]=m[i+n][j+n]=m[i][j+n]=m[i][j],val+=vis[m[I][j]^1,vis[m[I][j]]=1;
      |                                                                                                     ^
      |                                                                                                     ]
a.cc:31:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   31 |         rep(a,0,n-1)rep(b,0,n-1){
      |             ^
a.cc:8:37: note: in definition of macro 'rep'
    8 | #define rep(i,j,k) for(register int i=j;i<=k;++i)
      |                                     ^
a.cc:31:25: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   31 |         rep(a,0,n-1)rep(b,0,n-1){
      |                         ^
a.cc:8:37: note: in definition of macro 'rep'
    8 | #define rep(i,j,k) for(register int i=j;i<=k;++i)
      |                                     ^
a.cc:33:21: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   33 |                 rep(i,1,n) rep(j,1,n) tmp[i][j]=m[i+a][j+b];
      |                     ^
a.cc:8:37: note: in definition of macro 'rep'
    8 | #define rep(i,j,k) for(register int i=j;i<=k;++i)
      |                                     ^
a.cc:33:32: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   33 |                 rep(i,1,n) rep(j,1,n) tmp[i][j]=m[i+a][j+b];
      |                                ^
a.cc:8:37: note: in definition of macro 'rep'
    8 | #define rep(i,j,k) for(register int i=j;i<=k;++i)
      |                                     ^
a.cc:34:21: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   34 |                 rep(i,1,n) rep(j,1,n) if(tmp[i][j]!=tmp[j][i]) {f=0;break;}
      |                     ^
a.cc:8:37: note: in definition of macro 'rep'
    8 | #define rep(i,j,k) for(register int i=j;i<=k;++i)
      |                                     ^
a.cc:34:32: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   34 |                 rep(i,1,n) rep(j,1,n) if(tmp[i][j]!=tmp[j][i]) {f=0;break;}
      |                                ^
a.cc:8:37: note: in definition of macro 'rep'
    8 | #define rep(i,j,k) for(register int i=j;i<=k;++i)
      |                                     ^