Language: C++

#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>
 
using namespace std;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
 
 
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
 
//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
 
void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

template<typename T>
struct RollingHash {
	static const int base = 1007;
	vector<long long> hash, power;

	static const uint64_t MASK30 = (1UL << 30) - 1;
	static const uint64_t MASK31 = (1UL << 31) - 1;
	static const uint64_t MOD = (1UL << 61) - 1;

	constexpr uint64_t Mul(ulong a, ulong b) {
		uint64_t au = a >> 31;
		uint64_t ad = a & MASK31;
		uint64_t bu = b >> 31;
		uint64_t bd = b & MASK31;
		uint64_t mid = ad * bu + au * bd;
		uint64_t midu = mid >> 30;
		uint64_t midd = mid & MASK30;
		return au * bu * 2 + midu + (midd << 31) + ad * bd;
	}

	constexpr uint64_t CalcMod(uint64_t val) {
		val = (val & MOD) + (val >> 61);
		if (val >= MOD) val -= MOD;
		return val;
	}

	// construct
	RollingHash(const T& S) {
		int n = (int)S.size();
		hash.assign(n + 1, 0);
		power.assign(n + 1, 1);
		for (int i = 0; i < n; ++i) {
			hash[i + 1] = CalcMod(Mul(hash[i], base) + S[i]));
			power[i + 1] = CalcMod(Mul(power[i], base) + S[i]));
        }
	}
 
	static const uint64_t POSITIVIZER = MOD * 3;	
	// get hash of S[left:right]
	inline uint64_t get(int l, int r) const {
		return CalcMod(hash[r] + POSITIVIZER - Mul(hash[l], power[r - l]))
	}
};




int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	
	ll n;
	cin>>n;
	assert(n != 2);
	vector<string> s(n);
	REP(i,n) cin>>s[i];

	vector<string> t(n,string(n,'.'));
	REP(i,n){
		REP(j,n){
			t[j][i]=s[i][j];
		}
	}

	vector<RollingHash<string> > rhs,rht;
	REP(i,n) rhs.push_back(RollingHash<string>(s[i]+s[i]));
	REP(i,n) rht.push_back(RollingHash<string>(t[i]+t[i]));
	REP(i,n) {
		rhs.push_back(rhs[i]);
		rht.push_back(rht[i]);
	}

	ll ans=0;
	REP(a,n){
		REP(b,n){
			bool flag=true;
			REP(i,n){
				if(rhs[i+a].get(b+i,b+n)!=rht[i+b].get(a+i,a+n)){
					flag=false;
					break;
				}
				
			}
			if(flag) ans++;
		}
	}

	cout<<ans<<endl;

	return 0;
}


Compiler output:
a.cc:67:22: error: 'uint64_t' does not name a type
   67 |         static const uint64_t MASK30 = (1UL << 30) - 1;
      |                      ^~~~~~~~
a.cc:16:1: note: 'uint64_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
   15 | #include<unordered_map>
  +++ |+#include <cstdint>
   16 | 
a.cc:68:22: error: 'uint64_t' does not name a type
   68 |         static const uint64_t MASK31 = (1UL << 31) - 1;
      |                      ^~~~~~~~
a.cc:68:22: note: 'uint64_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
a.cc:69:22: error: 'uint64_t' does not name a type
   69 |         static const uint64_t MOD = (1UL << 61) - 1;
      |                      ^~~~~~~~
a.cc:69:22: note: 'uint64_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
a.cc:71:19: error: 'uint64_t' does not name a type
   71 |         constexpr uint64_t Mul(ulong a, ulong b) {
      |                   ^~~~~~~~
a.cc:71:19: note: 'uint64_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
a.cc:82:19: error: 'uint64_t' does not name a type
   82 |         constexpr uint64_t CalcMod(uint64_t val) {
      |                   ^~~~~~~~
a.cc:82:19: note: 'uint64_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
a.cc:99:22: error: 'uint64_t' does not name a type
   99 |         static const uint64_t POSITIVIZER = MOD * 3;
      |                      ^~~~~~~~
a.cc:99:22: note: 'uint64_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
a.cc:101:16: error: 'uint64_t' does not name a type
  101 |         inline uint64_t get(int l, int r) const {
      |                ^~~~~~~~
a.cc:101:16: note: 'uint64_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
a.cc: In constructor 'RollingHash<T>::RollingHash(const T&)':
a.cc:94:47: error: there are no arguments to 'Mul' that depend on a template parameter, so a declaration of 'Mul' must be available [-fpermissive]
   94 |                         hash[i + 1] = CalcMod(Mul(hash[i], base) + S[i]));
      |                                               ^~~
a.cc:94:47: note: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)
a.cc:94:73: error: expected ';' before ')' token
   94 |                         hash[i + 1] = CalcMod(Mul(hash[i], base) + S[i]));
      |                                                                         ^
a.cc:95:48: error: there are no arguments to 'Mul' that depend on a template parameter, so a declaration of 'Mul' must be available [-fpermissive]
   95 |                         power[i + 1] = CalcMod(Mul(power[i], base) + S[i]));
      |                                                ^~~
a.cc:95:75: error: expected ';' before ')' token
   95 |                         power[i + 1] = CalcMod(Mul(power[i], base) + S[i]));
      |                                                                           ^
a.cc: In function 'int main()':
a.cc:140:45: error: '__gnu_cxx::__alloc_traits<std::allocator<RollingHash<std::__cxx11::basic_string<char> > >, RollingHash<std::__cxx11::basic_string<char> > >::value_type' {aka 'struct RollingHash<std::__cxx11::basic_string<char> >'} has no member named 'get'
  140 |                                 if(rhs[i+a].get(b+i,b+n)!=rht[i+b].get(a+i,a+n)){
      |                                             ^~~
a.cc:140:68: error: '__gnu_cxx::__alloc_traits<std::allocator<RollingHash<std::__cxx11::basic_string<char> > >, RollingHash<std::__cxx11::basic_string<char> > >::value_type' {aka 'struct RollingHash<std::__cxx11::basic_string<char> >'} has no member named 'get'
  140 |                                 if(rhs[i+a].get(b+i,b+n)!=rht[i+b].get(a+i,a+n)){
      |                                                                    ^~~
a.cc: In instantiation of 'RollingHash<T>::RollingHash(const T&) [with T = std::__cxx11::basic_string<char>]':
a.cc:128:54:   required from here
  128 |         REP(i,n) rhs.push_back(RollingHash<string>(s[i]+s[i]));
      |                                                             ^
a.cc:94:50: error: 'Mul' was not declared in this scope
   94 |                         hash[i + 1] = CalcMod(Mul(hash[i], base) + S[i]));
      |                                               ~~~^~~~~~~~~~~~~~~
a.cc:94:46: error: 'CalcMod' was not declared in this scope
   94 |                         hash[i + 1] = CalcMod(Mul(hash[i], base) + S[i]));
      |                                       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:95:51: error: 'Mul' was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation
   95 |                         power[i + 1] = CalcMod(Mul(power[i], base) + S[i]));
      |                                                ~~~^~~~~~~~~~~~~~~~
a.cc:94:50: note: 'Mul' declared here, later in the translation unit
   94 |                         hash[i + 1] = CalcMod(Mul(hash[i], base) + S[i]));
      |                                               ~~~^~~~~~~~~~~~~~~
a.cc:95:47: error: 'CalcMod' was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation
   95 |                         power[i + 1] = CalcMod(Mul(power[i], base) + S[i]));
      |                                        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:94:46: note: 'CalcMod' declared here, later in the translation unit
   94 |                         hash[i + 1] = CalcMod(Mul(hash[i], base) + S[i]));
      |                                       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~