Problem:
 Score : 500 points    Problem Statement Snuke has two boards, each divided into a grid with N rows and N columns.
For both of these boards, the square at the i -th row from the top and the j -th column from the left is called Square (i,j) .  There is a lowercase English letter written in each square on the first board. The letter written in Square (i,j) is S_{i,j} . On the second board, nothing is written yet.  Snuke will write letters on the second board, as follows:   First, choose two integers A and B ( 0 \leq A, B < N ).  Write one letter in each square on the second board.
Specifically, write the letter written in Square ( i+A, j+B ) on the first board into Square (i,j) on the second board.
Here, the k -th row is also represented as the (N+k) -th row, and the k -th column is also represented as the (N+k) -th column.   After this operation, the second board is called a good board when, for every i and j ( 1 \leq i, j \leq N ), the letter in Square (i,j) and the letter in Square (j,i) are equal.  Find the number of the ways to choose integers A and B ( 0 \leq A, B < N ) such that the second board is a good board.      Constraints  1 \leq N \leq 300  S_{i,j} ( 1 \leq i, j \leq N ) is a lowercase English letter.         Input Input is given from Standard Input in the following format:  N  S_{1,1}S_{1,2}..S_{1,N}  S_{2,1}S_{2,2}..S_{2,N}  :  S_{N,1}S_{N,2}..S_{N,N}       Output Print the number of the ways to choose integers A and B ( 0 \leq A, B < N ) such that the second board is a good board.        Sample Input 1 2
ab
ca      Sample Output 1 2  For each pair of A and B , the second board will look as shown below:   The second board is a good board when (A,B) = (0,1) or (A,B) = (1,0) , thus the answer is 2 .       Sample Input 2 4
aaaa
aaaa
aaaa
aaaa      Sample Output 2 16  Every possible choice of A and B makes the second board good.       Sample Input 3 5
abcde
fghij
klmno
pqrst
uvwxy      Sample Output 3 0  No possible choice of A and B makes the second board good.

Solution (Python):
n = int(input())
s = [list(input()) for _ in range(n)]

res = 0
for b in range(n):
    judge = True
    d = [['']*n for _ in range(n)]
    for i in range(n):
        for j in range(n):
            d[i][(j+b)%n] = s[i][j]
    
    for i in range(n):
        for j in range(n):
            if d[i][j] != d[j][i]:
                judge = False
    
    if judge:
        res += n

print(res)

Solution (Python):
N = int(input())
S = []
for i in range(N):
  Ss = input()
  S.append(Ss)
r = 0
for i in range(N):
  T = S[i:]+S[:i]
  ok = True
  for i in range(N):
    for j in range(i+1, N):
      if T[i][j] != T[j][i]:
        ok = False
        break
  if ok:
    r += 1
r *= N
print(r)

Solution (Python):



import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def check(x):
    for i in range(n):
        for j in range(n):
            if x[i][j] == x[j][i]:
                continue
            return False
    return True

n = I()
s = [list(input()) for _ in range(n)]
ans = 0
for b in range(n):
    flg = True
    for i in range(n):
        for j in range(n):
            if s[(i+b)%n][j] == s[(j+b)%n][i]:
                continue
            else:
                flg = False
                break
    if flg:
        ans += n
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    state = [list(input()) for _ in range(N)]

    ans = 0
    for i in range(N):
        ok = True
        for x in range(N):
            for y in range(N):
                if state[(x+i)%N][y] != state[(i+y)%N][x]:
                    ok = False
                    break
        if ok:
            ans += N
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
S = [''] * N
for i in range(N):
  S[i] = input()
cnt = 0
for a in range(N):
  for i in range(N):
    _i = (i - a) % N
    for j in range(i):
      if S[_i][j] != S[(j - a) % N][i]:
        break
    else:
      continue
    break
  else:
    cnt += N
print(cnt)

Solution (Python):
N = int(input())
S = [list(input()) for _ in range(N)]
T = [list(_) for _ in zip(*S)]
cnt = 0
for i in range(N):
    f = 1
    for j in range(N):
        if S[i + j - N] != T[j][i:] + T[j][:i]:
            f = 0
            break
    cnt += f
print(cnt * N)

Solution (Python):

N = int(input())
S = [list(str(input())) for i in range(N)]

A = 0
B = 0

ans = 0
for i in range(N):
    A = i
    flag = 0
    for j in range(N):
        for k in range(N):
            if S[(j+A)%N][k] != S[(k+A)%N][j]:
                flag = 1
    
    if flag == 0:
        ans+=1
        
print(ans*N)

Solution (Python):
n = int(input())
data = [input() for i in range(n)]
ans = 0
for a in range(n):
    b = 0
    t = True
    for i in range(n):
        for j in range(n):
            if data[(i + a) % n][(j + b) % n] != data[(j + a) % n][(i + b) % n]:
                t = False
                break

    if t:
        ans += n

print(ans)

Solution (Python):
n = int(input())
a = [list(input()) for _ in range(n)]
ans = 0
for s in range(n):
  f = 1
  for i in range(n):
    if not f:
      break
    for j in range(n):
      if a[(i+s)%n][j] != a[(j+s)%n][i]:
        f = 0
        break
  if f:
    ans += n
print(ans)

Solution (Python):
n = int(input())
s = [input() for i in range(n)]
MOD = n

def solve(add):
    for i in range(n):
        for j in range(n):
            if s[(i+add) % MOD][j] != s[(j+add) % MOD][i]:
                return False
    return True

ans = 0
for i in range(n):
    if solve(i):
        ans += n
print(ans)

Solution (Python):
N=int(input())
S=[input() for i in range(N)]
St=list(map(''.join,zip(*S)))
r=0
for k in range(N):
    f=1
    for i in range(N):
        if S[i][k:]+S[i][:k]!=St[i+k-N]:
            f=0
            break
    if f:
        r+=N
print(r)

Solution (Python):
import sys

import numpy as np

N = int(sys.stdin.buffer.readline())
S = np.frombuffer(sys.stdin.buffer.read(),dtype='S1').reshape(N,-1)[:,:N]


S = np.concatenate([S,S])

answer = 0
for x in range(N):
    T = S[x:x+N]
    if (T == T.T).all():
        answer += N

print(answer)

Solution (Python):
import sys
import heapq
from operator import itemgetter
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7

def sol():
    N = int(input())
    S = [0] * N

    for i in range(N):
        S[i] = input().rstrip()

    def isSame(a):
        for i in range(N):
            for j in range(N):
                if S[(i + a) % N][j] != S[(j + a) % N][i]:
                    return False
        return True

    ans = 0
    for a in range(N):
        if isSame(a):
            ans += N

    print(ans)

sol()

Solution (Python):
N=int(input())
S=[input()for _ in'_'*N]
z=0
for k in range(-N,0):
	for t in range(N*N):
		i=t//N
		j=t%N
		if S[i][j+k]!=S[j][i+k]:
			break
	else:
		z+=N
print(z)

Solution (Python):
n,*s=open(0)
n=int(n)
c=0
for _ in range(n):
  for i in range(n*n):
    i,j=i//n,i%n
    if s[i][j]!=s[j][i]:
      break
  else:
    c+=n    
  s=s[1:]+s[:1]
print(c)

Solution (Python):
n,*s=[t[:-1]for t in open(0)]
n=int(n)
c=0
for _ in range(n):
  c+=all(x==''.join(y)for x,y in zip(s,zip(*s)))*n
  s=s[1:]+s[:1]
print(c)

Solution (Python):
import numpy as np
N=int(input())
S = np.array([list(input()) for _ in [0]*N])
ans = 0
for i in range(N):
    t = np.vstack((S[i:],S[:i]))
    if np.all(t==t.T):ans += 1
ans *= N
print(ans)

Solution (Python):
n = int(input())

s = []

for i in range(n):
    s.append(input()*2)

ans = 0

for i in range(n):
    flag = True
    for j in range(n):
        for k in range(n):
            if s[j][k+i]!=s[k][j+i]:
                flag = False
                break
        if not flag:
            break
    if flag:
        ans += n

print(ans)

Solution (Python):
def check(b):
  for i in range(n):
    for j in range(i+1,n):
      if b[i][j]!=b[j][i]:
        return False
  return True

n=int(input())
board=[list(input()) for _ in range(n)]
cnt=0
for i in range(n):
  if check(board[i:]+board[:i]):
    cnt+=1
print(cnt*n)

Solution (Python):
n=int(input())
arr=[list(input()) for _ in range(n)]
ans=0
for k in range(n):
  flag=True
  for i in range(1,n//2+1):
    for j in range(n):
      if arr[(j)%n][(k+j+i)%n]!=arr[(j+i)%n][(k+j+n)%n]:
        flag=False
        break
    if flag==False:
      break
  else:
    ans+=n
print(ans)

Solution (Python):
def check(N, S, bi, bj):
    for i in range(N):
        for j in range(i+1, N):
            if S[(bi+i) % N][(bj+j) % N] != S[(bi+j) % N][(bj+i) % N]:
                return False
    return True


def main():
    N = int(input())
    S = [input() for _ in range(N)]
    ans = 0
    for i in range(N):
        if check(N, S, i, 0):
            ans += N
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):

n = int(input())
board = [input() for i in range(n)]

def check(a, b):
    for i in range(n):
        for j in range(n):
            if board[(i-a)%n][(j-b)%n] != board[(j-a)%n][(i-b)%n]:
                return False
    return True

ans = 0
for i in range(n):
    if check(i,0):
        ans += n-i
    if check(0,i) and i >0:
        ans += n-i
print(ans)

Solution (Python):
N = int(input())
S = []
for i in range(N):
    S.append(input())

def check(S):
    for i in range(N):
        for j in range(i+1, N):
            if S[i][j] != S[j][i]:
                return 0
    return 1

cnt = 0
for i in range(N):
    cnt += check(S[i:] + S[:i])
print(cnt * N)

Solution (Python):
N = int(input())
S = []
for i in range(N):
    S.append(input())

def check(S, A, B):
    for i in range(N):
        for j in range(i+1, N):
            if S[i][j] != S[j][i]:
                return 0
    return 1

cnt = 0
for i in range(N):
    cnt += check(S[i:] + S[:i], 0, 0)
print(cnt * N)

Solution (Python):


import sys


INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n = II()
    B = [SI() for _ in range(n)]

    BT = list(zip(*B))
    res = 0
    for a in range(n):
        is_good = True
        for i in range(n):
            if B[i][n - a:] + B[i][:n - a] != ''.join(BT[(i - a) % n]):
                is_good = False

        if is_good:
            res += n

    return res


print(main())

Solution (Python):


import sys


INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n = II()
    B = [tuple(SI()) for _ in range(n)]

    BT = list(zip(*B))
    res = 0
    for a in range(n):
        is_good = True
        for i in range(n):
            if B[i][n - a:] + B[i][:n - a] != BT[(i - a) % n]:
                is_good = False

        if is_good:
            res += n

    return res


print(main())

Solution (Python):

N = int(input())
S = [list(input()) for _ in range(N)]


ans = N * sum(
    all(
        S[i][j] == S[(j - A) % N][(i + A) % N]
        for i in range(N)
        for j in range(N)
    )
    for A in range(N)
)


print(ans)

Solution (Python):
n = int(input())
s = [input() for _ in range(n)]

ans = 0
a = 0
for b in range(n):
    flag = 0
    for i in range(n):
        if flag == 1:
            break
        for j in range(n):
            if s[(i+a)%n][(j+b)%n] != s[(j+a)%n][(i+b)%n]:
                flag = 1
                break
    else:
        ans += n

print(ans)

Solution (Python):


import sys


INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n = II()
    B = [SI() for _ in range(n)]

    res = 0
    for i in range(n):
        is_good = 1
        for h in range(n):
            for w in range(h + 1, n):
                if B[h][(w + i) % n] != B[w][(h + i) % n]:
                    is_good = 0
                    break

            if not is_good:
                break

        if is_good:
            res += n

    return res


print(main())

Solution (Python):
N = int(input())
T = [[] for i in range(N)]
for i in range(N):
    a = list(input())
    T[i] = a
num = 0
for i in range(N):
    flag = True
    for j in range(N):
        for k in range(N):
            q = k + i
            p = j + i
            if q >= N:
                q -= N
            if p >= N:
                p -= N
            if j == q:
                continue
            if T[j][q] != T[k][p]:
                flag = False

    if flag:
        num += 1

print(num * N)

Solution (Python):
N = int(input())
s = [input() for _ in range(N)]

ans = 0
a = 0
for b in range(N):
    if all(s[(i - a) % N][(j - b) % N] == s[(j - a) % N][(i - b) % N] for i in range(N) for j in range(i + 1, N)):
        ans += N
print(ans)

Solution (Python):
N=int(input())
S=[input() for i in range(N)]
ans=0
for k in range(N):
    flag=1
    for i in range(N):
        for j in range(N):
            if S[(i+k)%N][j]!=S[(j+k)%N][i]:
                flag=0
                break
        if flag==0:
            break
    if flag==1:
        ans+=N
print(ans)

Solution (Python):
N = int(input())
S = [input() for _ in range(N)]

Total = 0
for i in range(N):
    Synmmetry = True
    for a in range(N):
        for b in range(a, N):
            if S[a][(b + i) % N] != S[b][(a + i) % N]:
                Synmmetry = False
                break
        if not Synmmetry: break
    else: Total += 1
print(Total * N)

Solution (Python):
import numpy as np
n=int(input())
l=np.array([list(input()) for _ in range(n)])
ans=0

for _ in range(n):
    l=np.roll(l,1,axis=1)
    if (l==l.T).all():ans+=n

print(ans)

Solution (Python):
N = int( input())
S = [ input() for _ in range(N)]
ans = 0
for k in range(N):
    check = True
    for i in range(N):
        for j in range(i+1,N):
            if not S[i][(j+k)%N] == S[j][(i+k)%N]:
                check = False
                break
        if not check:
            break
    if check:
        ans += N
print(ans)

Solution (Python):
N=int(input())
ans,flag=0,0
S=[list(input()) for i in range(N)]
for k in range(N):
  flag=0
  for i in range(N):
    for j in range(N):
      if S[i][j]!=S[(j+k)%N][(i-k)%N]:
        flag=1
        break
    if flag==1:
      break
  if flag==0:
    ans+=N
print(ans)

Solution (Python):


if __name__ == '__main_sample__':
    """
        (A, B)と(A+1, B+1)の結果は同じになる.
        (0, 0), (0, 1) ... (0, N-1)をチェックすれば良くなる.
    """
    N = int(input())
    rows = [input() for _ in range(N)]
    ans = 0
    for n in range(N):
        flag = False
        for i in range(N):
            for j in range(N):
                num = j - n if j - n >= 0 else N + (j - n)
                a = i - n if i - n >= 0 else N + (i - n)
                if rows[i][num] != rows[j][a]:
                    flag = True
                    break
            if flag == True:
                break
        if flag == False:
            ans += 1
    print(ans * N)

if __name__ == '__main__':
    """
        高速化された開放
    """
    N = int(input())
    Sss = [input() for _ in range(N)]
    Sss_tr = list(map(''.join, zip(*Sss))) 
    ans = 0
    for k in range(N):
        for i in range(N):
            if (Sss[i][-k:] + Sss[i][:-k]) != Sss_tr[i - k]:
                break
        else:
            ans += N
    
    print(ans)

Solution (Python):
import numpy as np
N = int(input())
S = np.array([list(input()) for _ in range(N)]) 
ans = 0
for i in range(N):
    S = np.roll(S, 1, axis = 1)
    if (S != S.T).any():
        continue
    ans += 1
print(ans * N)

Solution (Python):

from sys import stdin
import numpy as np

s_in = lambda: stdin.readline()[:-1]  
d_in = lambda: int(stdin.readline())  
ds_in = lambda: list(map(int, stdin.readline().split()))  


N = d_in()
S_LIST = []
for _ in range(N):
    s = list(s_in())
    S_LIST.append(list(map(ord, s)))
S_LIST = np.array(S_LIST, dtype=int)

ans = 0
for i in range(N):
    check_array = np.concatenate((S_LIST[:, i:], S_LIST[:, :i]), axis=1)
    if np.array_equal(check_array, check_array.T):
        ans += 1
print(ans*N)

Solution (Python):
N = int(input())
Sss = [input() for _ in range(N)]
Sss_tr = list(map(''.join, zip(*Sss))) 

ans = 0
for k in range(N):
    for i in range(N):
        if (Sss[i][-k:] + Sss[i][:-k]) != Sss_tr[i - k]:
            break
    else:
        ans += N

print(ans)

Solution (Python):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())
 
n = ni()
grid = []
 
for _ in range(n):
    s = ns()
    s = s+s
    grid.append(s)
    
for i in range(n):
    grid.append(grid[i])
    
vert = []
hrzn = []
 
for i in range(2*n):
    hrzn.append(grid[i])
    
for j in range(2*n):
    temp = ""
    for i in range(2*n):
        temp += grid[i][j:j+1]
        
    vert.append(temp)
    
    
ans = 0
b = 0 

for a in range(n):
        
    ok = True
    for i in range(n-1):
 
        if vert[b+i][a+i:a+n] != hrzn[a+i][b+i:b+n]:
            ok = False
            break
            
    if ok:
        ans += 1
            
print(ans*n)

Solution (Python):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())
 
n = ni()
grid = []
 
for _ in range(n):
    s = ns()
    s = s+s
    grid.append(s)
    
for i in range(n):
    grid.append(grid[i])
    
vert = []
hrzn = []
 
for i in range(2*n):
    hrzn.append(grid[i])
    
for j in range(2*n):
    temp = ""
    for i in range(2*n):
        temp += grid[i][j:j+1]
        
    vert.append(temp)
    
    
ans = 0
b = 0 

for a in range(n):
        
    ok = True
    for i in range(n-1):
 
        if vert[b+i][a+i:a+n] != hrzn[a+i][b+i:b+n]:
            ok = False
            break
            
    if ok:
        ans += 1
            
print(ans*n)

Solution (Python):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())
 
n = ni()
grid = []
 
for _ in range(n):
    s = ns()
    s = s+s
    grid.append(s)
    
for i in range(n):
    grid.append(grid[i])
    
vert = []
hrzn = []
 
for i in range(2*n):
    hrzn.append(grid[i])
    
for j in range(2*n):
    temp = ""
    for i in range(2*n):
        temp += grid[i][j:j+1]
        
    vert.append(temp)
    
    
ans = 0
 
for a in range(n):
    for b in range(1):
        
        ok = True
        for i in range(n-1):
 
            if vert[b+i][a+i:a+n] != hrzn[a+i][b+i:b+n]:
                ok = False
                break
                
        if ok:
            ans += 1
            
print(ans*n)

Solution (Python):
import numpy as np
n=int(input())
a=[list(input()) for i in range(n)]
a=np.array(a)
c=0
for i in range(n):
    a=np.roll(a,1,axis=0)
    if len(a[a!=a.T])==0:c+=n
print(c)

Solution (Python):





"""
AGC023 B
"""

from itertools import product

n = int(input())
sli = [input() for i in range(n)]

ans = 0
for k in range(n):
    if all((sli[i][j] == sli[(j+k) % n][(i-k) % n] for i, j in product(range(n), repeat=2))):
        ans += n

print(ans)

Solution (Python):
from itertools import combinations
N = int(input())
grid = tuple(tuple(input()) for _ in range(N))

res = 0
for d in range(N):
  for x,y in combinations(range(N), 2):
    if grid[(x+d)%N][y] != grid[(y+d)%N][x]:
      break
  else:
    res += 1
print(res*N)

Solution (Python):
n=input()
s=[raw_input() for i in range(n)]
t=[]
for i in range(n):
	t+=[s[j][i] for j in xrange(n)]*2
s+=s
s=''.join(s)

t=''.join(t)

result=0
for shift in xrange(n):
	ok=True
	for i in xrange(n):
		if s[(i+shift)*n: (i+shift)*n+n]!=t[i*n*2+shift: i*n*2+shift+n]:
			ok=False
			break
	if ok:
		result+=n
print result

Solution (Python):
N = int(input())
S = [input() for _ in range(N)]
ans = 0
for k in range(N):
    f = True
    for i in range(N):
        for j in range(i + 1, N):
            if S[i][(j + k) % N] != S[j][(i + k) % N]:
                f = False
                break

        if not f:
            break
    if f:
        ans += N
print(ans)

Solution (Python):
N=int(input())
S=[list(input()) for i in range(N)]
def issym(IL):
    for i in range(N):
        for j in range(i+1,N):
            if IL[i][j]!=IL[j][i]:
                return False
    return True
def changelist(A,B):
    T=[["" for i in range(N)] for j in range(N)]
    for i in range(N):
        for j in range(N):
            T[i][j]=S[(i+A)%N][(j+B)%N]
    return T
ans=0
for i in range(N):
    L=changelist(i,0)
    if issym(L):
        ans+=N
print(ans)

Solution (Python):
n = int(input())
A = [input() for _ in range(n)]
A_t = [''] * n
for c in A:
    for i in range(n):
        A_t[i] += c[i]

def checkTable(shift):
    for i in range(n):
        if A_t[(i + shift) % n] != A[i][shift:] + A[i][:shift]:
            return False
    return True

count = 0
for i in range(n):
    if checkTable(i):
        count += 1
print(count * n)

Solution (Python):
from collections import deque


def main():
  def check(mp):
    for i in range(n):
      for j in range(i, n):
        if mp[i][j] != mp[j][i]: return 0
    return 1
  n = int(input())
  mp = deque([deque(list(input())) for _ in range(n)])
  ans = 0
  for a in range(n):
    mp.rotate()
    ans += check(mp)
  print(ans * n)
  
main()

Solution (Python):
N = int(input())
S = [input() for i in range(N)]
r = N*(N-1)//2
ans = 0
for i in range(N):
    g = 0
    for j in range(N):
        ji = (j+i) % N
        for k in range(j+1, N):
            if S[j][k+i-N] == S[k][ji]:
                g += 1
    if g == r:
        ans += 1
    for j in range(N-1):
        ji = (j+i) % N
        for k in range(N-1):
            if S[1+k+j-N][ji] == S[j][ji+k+1-N]:
                g += 1
            if S[j+k-N][ji] == S[j][ji+k-N]:
                g -= 1
        if g == r:
            ans += 1
print(ans)

Solution (Python):
N = int(input())
S=[]
for i in range(N):
    s =list(input())
    S.append(s)
num=0
for a in range(N):
    t =1
    flag = True
    for i in range(N):
        if not flag:
            break
        for j in range(N):
            if i==j:
                continue
            
            
            if S[(j+a)%N][i]!=S[(i+a)%N][j]:
                t=0
                flag=False
                break
    if t:
        num+=1
print(N*num)

Solution (Python):
N = int(input())
S=[]
for i in range(N):
    s =list(input())
    S.append(s)
num=0
for a in range(N):
    t =1
    
    for i in range(N):
        
           
        for j in range(N):
            if i==j:
                continue
            
            
            if S[(j+a)%N][i]!=S[(i+a)%N][j]:
                t=0
                
                
    if t:
        num+=1
print(N*num)

Solution (Python):



n=int(input())
S=[]
for i in range(n):
    S.append(input())

a=0

for i in range(n):
    S=[S[-1]]+S[:-1]

    flag=1
    for j in range(n):
        for k in range(j):
            if S[j][k] != S[k][j]:
                flag=0
                break
    if flag == 1:
        a = a+1

print(a*n)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    a = [[c for c in S()] for _ in range(n)]
    r = 0
    for i in range(n):
        b = [[a[ii][(j+i)%n] for j in range(n)] for ii in range(n)]
        f = True
        for ii in range(n):
            for jj in range(ii+1,n):
                if b[ii][jj] != b[jj][ii]:
                    f = False
                    break
            if not f:
                break
        if f:
            r += 1

    return r * n




print(main())

Solution (Python):
N = int(input())
S = []
for i in range(N):
    S.append(input())
T = []
for i in range(N):
    tmp = ''
    for j in range(N):
        tmp += S[j][i]
    T.append(tmp[:])



ans = 0
for i in range(N):
    
    flag = True
    for y in range(N):
        
        
            
            
            
            
        
        if T[(y+i)%N]!=S[y][i:]+S[y][:i]:
            flag = False
            break
    if flag:
        ans += 1

print(ans*N)

Solution (Python):
import numpy as np
from scipy.ndimage.interpolation import shift as scipy_shift

class shift:
    def __init__(self,a):
        self.arr = a
        self.height = a.shape[0]
        self.width = a.shape[1]
    def shifted(self,down,right):
        temp1 = self.arr[list(np.linspace(-down, -down + self.height - 1, self.height).astype(np.int32) % self.height), :]
        temp2 = temp1[:, list(np.linspace(-right, -right + self.width - 1, self.width).astype(np.int32) % self.width)]
        return temp2
    def shifted_zero(self,down,right):
        index_vertical = np.arange(self.height)
        index_horizontal = np.arange(self.width)
        temp1 = self.arr[list(scipy_shift(index_vertical, down, output = int, mode = 'constant')),:]
        temp2 = temp1[:,list(scipy_shift(index_horizontal, right, output = int, mode = 'constant'))]
        return temp2
    def is_sym(self,down,right):
        temp = self.shifted(down,right)
        delta = temp - temp.T
        return(not (delta*delta).sum())



N = int(input())
array = [list(input()) for i in range(N)]
array_int = np.array([[ord(i) for i in j] for j in array])

if N >= 2:
    count = np.array([shift(array_int).is_sym(0,i)*(N-i) for i in range(N)]).sum() + np.array([shift(array_int).is_sym(i,0)*(N-i) for i in range(1,N)]).sum()
else:
    count =  int(shift(array_int).is_sym(0,0))
print(count)

Solution (Python):
n = int(input())
s = [input() for i in range(n)]
st = [str().join(s_) for s_ in zip(*s)]

sol = 0

for i in range(n):
    for k in range(n):
        if s[k] != st[k]:
            break
    else:
        sol += 1
    
    s = [s_l[1:]+s_l[0] for s_l in s]
    st = st[1:] + [st[0]]
    
print(sol * n)

Solution (Python):
N=input()
S=[ list(raw_input()) for i in range(N)]

A=0
ans=0
for B in range(N):
	flag=0
	for i in range(N):
		if flag==-1: break
		for j in range(N):
			x1=(N+i-A)%N
			y1=(N+j-B)%N

			x2=(N+j-A)%N
			y2=(N+i-B)%N

			if S[x1][y1]==S[x2][y2]:
				pass
			else:
				flag=-1
				break
	else:
		ans+=1*N


print ans

Solution (Python):
N=input()
S=[ list(raw_input()) for i in range(N)]

A=0
ans=0
for B in range(N):
	flag=0
	for i in range(N):
		if flag==-1: break
		for j in range(N):
			x1=(N+i-A)%N
			y1=(N+j-B)%N

			x2=(N+j-A)%N
			y2=(N+i-B)%N

			
			if S[x1][y1]==S[x2][y2]:
				pass
			else:
				flag=-1
				
	else:
		ans+=1*N


print ans

Solution (Python):
n = int(input())

s = []
for _ in range(n):
    s.append(input())
s = s + s

def check(a):
    flag = True
    n = len(a)
    i, j_start = 0, 1
    while flag:
        if i == n - 1:
            break
        for j in range(j_start, n):
            if a[i][j] != a[j][i]:
                flag = False
        i += 1
        j_start += 1
    return flag

ans = 0
for i in range(n):
    if check(s[i:i+n]):
        ans += n
    else:
        pass
print(ans)

Solution (Python):
N = int(input())
S = []
for i in range(N):
    S.append(input())

def check(S, A, B):
    for i in range(N):
        for j in range(i+1, N):
            if S[i][j] != S[j][i]:
                return 0
    return 1

cnt = 0
for i in range(N):
    cnt += check(S[i:] + S[:i], 0, i)
print(cnt * N)

Solution (Python):
N=int(input())
S=["" for i in range(N)]

for i in range(N):
    S[i]=input()

count=0

for l in range(N):
    JUDGE=1
    for j in range(N):
        for k in range(j+1,N):
            
            if S[j][k-l]!=S[k][j-l]:
                JUDGE=0
                break
        if JUDGE==0:
            break

    if JUDGE==1:
        count+=1

print(count*N)

Solution (Python):
import numpy

N = int(input())

S = [[x for x in input()] for _ in range(N)] 

S_mat = numpy.mat(S)

ret = 0
for A in range(N):
    A_change_list = list(range(A, N))
    A_change_list.extend(list(range(A)))
    moved = S_mat[A_change_list, :]
    if numpy.all(moved == moved.T):
        ret +=1
print(N*ret)

Solution (Python):
n = int(input())

s = []
for i in range(n):
    s.append(input())

result = 0

def judge(board):
    for i in range(n):
        for j in range(i+1, n):
            if board[i][j] != board[j][i]:
                return 0
    return 1

result = 0
for i in range(n):
    board = s[i:] + s[:i]
    result += n * judge(board)

print(result)

Solution (Python):
N=int(input())
S=[input() for _ in range(N)]

def solve(N,S):
  st=[tuple(x) for x in S]
  ch=list(zip(*st))
  ans=0
  for i in range(N):
    if st==ch:
      ans+=N
    st=st[-1:]+st[:-1]
    ch=[row[-1:] + row[:-1] for row in ch]
  return ans

print(solve(N,S))

Solution (Python):
N = int(input())
S_list = [input() for _ in range(N)]
cnt = 0


def count_symmetry(S_symmetry):
    for i in range(N):
        for j in range(i + 1, N):
            if S_symmetry[i][j] != S_symmetry[j][i]:
                return False
    return True


for k in range(N):
    S_symmetry = S_list[k:] + S_list[:k]
    if count_symmetry(S_symmetry):
        cnt += 1

print(cnt * N)

Solution (Python):
N = int(input())
S = [input() for i in range(N)]
T = [list(s[i] for s in S) for i in range(N)]

def check(B):
    b = B-N
    for i in range(N):
        si = S[i]
        ti = T[b+i]
        if any(si[b+j] != ti[j] for j in range(i)):
            return 0
    return 1

ans = 0
for i in range(N):
    ans += N*check(i)
print(ans)