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.



Sample input:
2
ab
ca


Sample output:
2

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
lisS = [list(map(ord, list(input()))) for _ in range(N)]
arS = np.array(lisS)
arExt = np.tile(arS, [2,2])[:-1,:-1]

cnt = 0
for i in range(N):
    ar = arExt[i:i+N, 0:N]
    cnt += N * (ar == ar.T).all()

print(cnt)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from itertools import combinations
def inpl(): return map(int, input().split())

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

for k in range(N):
    for i, j in combinations(range(N), 2):
        if S[i][(j+k)%N] != S[j][(i+k)%N]:
            break
    else:
        ans += N

print(ans)

Submission status: Accepted

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

def check(a):
    t = s[a:] + s[:a]
    t_t = list(map(list, zip(*t)))
    
    return t == t_t

ans = [check(a) for a in range(n)]
print(ans.count(True) * n)

Submission status: Accepted

Solution code:
N = int(input())
m = [input() for _ in range(N)]
mt = list(map(''.join, zip(*m)))

ans = 0
for z in range(N): #ずらし
  for y in range(N):
    if m[y][y+1:] != mt[y][y+1:]:
      break
  else:
    ans += N
  m = [l[-1]+l[:-1] for l in m]
  mt = [mt[-1]] + mt[:-1]

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
import numpy as np
N = int(input())
alphabets = list('abcdefghijklmnopqrstuvwxyz')
A = np.zeros((N, N), dtype=int)
for i in range(N):
    for j, c in enumerate(input()):
        A[i,j] = alphabets.index(c)

B = np.concatenate([A, A], axis=0)
cnt = 0
for i in range(N):
    C = B[i:i+N, :]
    if (C==C.T).all():
        cnt += 1
print(cnt*N)

Submission status: Accepted

Solution code:
N = int(input())
board = []

def isGoodBoard(b):
	for i in range(N):
		for j in range(i,N):
			if b[i][j] != b[j][i]:
				return False
	return True
for i in range(N):
	board.append(list(input()))

ans = 0
for i in range(N):
	board2 = [board[(x+i) % N] for x in range(N)]
	if isGoodBoard(board2):
		ans += N
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys, math, copy
# import fractions, itertools
import numpy as np
# import scipy

HUGE = 2147483647
HUGEL = 9223372036854775807
ABC = "abcdefghijklmnopqrstuvwxyz"

def main():
    n = int(input())
    sl = [[c for c in input()] for i in range(n)]

    s = np.char.array(sl)
    assert s.shape == (n, n)

    res = 0
    for i in range(n):
        sr = np.roll(s, i, axis=1)
        if np.all(sr.T == sr):
            res += n

    print(res)

main()

Submission status: Accepted

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

def solve(N, S):
    cs1 = [tuple(x) for x in S]
    cs2 = list(zip(*cs1))
    r = 0
    for d in range(N):
        if cs1 == cs2:
            r += 1
        cs1 = cs1[-1:] + cs1[:-1]
        cs2 = [row[-1:] + row[:-1] for row in cs2]
    return r * N

print(solve(N, S))

Submission status: Accepted

Solution code:
n = int(input())
ban = []
for i in range(n):
    ban.append(input())
def hantei(data):
    for i in range(1,n):
        for k in range(i):
            if data[i][k] != data[k][i]:
                return(0)
    return(1)
ans = 0
for _ in range(n):
    tmp = ban[_:] + ban[:_]
    ans += hantei(tmp)
print(ans * n)

Submission status: Accepted

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

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

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

Submission status: Runtime Error

Solution code:
n = int(input())
s = [list(input()) for i in range(h)]
s += s

def ok(array):
    for i in range(1,n):
        for j in range(i):
            if array[i][j] != array[j][i]:
                return False
    return True
ans = 0
for i in range(n-1):
    if ok(s[i:i+n]):
        ans += n
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

def is_symmetric(a):
    return np.array_equal(a, a.T)

def main():
    N = int(input())
    S = [[] for _ in range(N)]
    for i in range(N):
        for s in list(input()):
            S[i].append(ord(s) - ord("a"))

    S = np.array(S)

    ans = 0
    for A in range(N):
        for B in range(N):
            if is_symmetric(np.roll(S, (A, B), axis=(0,1))):
                ans += 1

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
N, *S = open('0').read().split()
N = int(N)
ans = 0
for p in range(N):
  flag = False
  for i in range(N):
    for j in range(N):
     x = i
     y = (j-p)%N
     a,b = y, (x+p)%N
     if S[i][j] != S[a][b]:
       flag = True
       break
    if flag:
      break
  else:
    ans+= N
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
arr = []
for i in range(n):
    a = list(map(ord,list(input())))
    arr.append(a)

import numpy as np
# print(np.array(arr))

ans = 0

for i in range(n):
    ok = True
    for j in range(n):
        for k in range(n):
            if j == k:
                continue
            l = j + i
            if l > n-1:
                l = l-n
            m = k + i
            if m > n-1:
                m = m-n
            # print(l,k,i)
            # print(arr[l][k],arr[k][l])
            if arr[l][k] != arr[m][j]:
                ok = False
                break

    # print("####")
    if ok:
        ans += n



print(ans)

Submission status: Runtime Error

Solution code:
(n,),*s=[t.rstrip()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)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from collections import*
(n,),*s=[tuple(t[:-1])for t in open(0)]
s=deque(s)
n=int(n)
c=0
for _ in range(n):
  c+=all(x==y for x,y in zip(s,zip(*s)))*n
  s.rotate(1)
print(c)

Submission status: Runtime Error

Solution code:
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
    else return 1

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

Submission status: Runtime Error

Solution code:
n = int(input())
a = []
for i in range(n):
    a.append(input())
for i in range(n):
    a[i].extend(a[i])
for i in range(n):
    a.append(a[i])


x = 0

for i in range(n):
    for j in range(n):
        for k in range(j+1):
            if a[i+j][k]==a[i+k][j]:
                continue
            else:
                break
        else:
            continue
        break
    else:
        x += 1

print(n*x)

Submission status: Runtime Error

Solution code:
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())

import numpy as np

n = ni()
grid1 = [lc() for _ in range(n)]

grid1 = np.tile(grid1, (2, 2)).tolist()
grid1trans = list(zip(*grid1))

row = [[""]*n for _ in range(n)]
col = [[""]*n for _ in range(n)]

for r in range(n):
    cur = grid1[r][:n]
    
    for st in range(n):
        row[r][st] = cur
        
        cur = cur[1:]
        cur.append(grid1[r][st])
        
for c in range(n):
    cur = list(grid1trans[c][:n])
    
    for st in range(n):      
        col[c][st] = cur
        
        cur = cur[1:]
        cur.append(grid1trans[c][st])
        
ans = 0

for r in range(n):
    for c in range(n):
        ok = True
        
        for check in range(n):
            if row[(r+check)%n][(c+check)%n] != col[(c+check)%n][(r+check)%n]:
                ok = False
                
        if ok:
            ans += 1
            
print(ans)

Submission status: Runtime Error

Solution code:
from math import factorial
from collections import Counter

N = int(input())
A = list(map(int, input().split()))

S = [0]

for i in A:
    S.append(S[-1] + i)

count = 0
count_dict = Counter(S)
for i in count_dict.values():
    if i == 1:
        continue
    count += factorial(i) // (factorial(i - 2) * factorial(2))
print(count)

Submission status: Runtime Error

Solution code:
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, dtype=int) % self.height), :]
        temp2 = temp1[:, list(np.linspace(-right, -right + self.width - 1, self.width, dtype=int) % 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])

count = np.array([[shift(array_int).is_sym(i,j) for i in range(N)] for j in range(N)])
print(count.sum())

Submission status: Runtime Error

Solution code:
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, dtype=int) % self.height), :]
        temp2 = temp1[:, list(np.linspace(-right, -right + self.width - 1, self.width, dtype=int) % 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])

count = np.array([[shift(array_int).is_sym(i,j) for i in range(N)] for j in range(N)])
print(count)
print(count.sum())

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
S = [str(input()) for _ in range(N)]


def isGoodTable(table, A, B):
    for i in range(N):
        for j in range(i, N):
            if table[i][j] != table[j][i]:
                return False
    return True


def shiftTable(table, A, B):
    shifted = []
    for i in range(N):
        shifted.append([])
        for j in range(N):
            shifted[i].append(table[(i + A) % N][(j + B) % N])
    return shifted


def countGoodShift(table):
    count = 0
    for a in range(N):
        shifted = shiftTable(table, a, b)
        if isGoodTable(shifted, a, b):
            count += 1
    return count * N


print(countGoodShift(S))

Submission status: Runtime Error

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


def check

def yoi(s, b):
  for i in range(n):
    for j in range(i+1, n):
      if s[i % n][(j + b) % n] != s[j % n][(i + b) % n]:
        return 0
  return 1

sol = sum(yoi(s, b) for b in range(n))
print(sol * n)

Submission status: Runtime Error

Solution code:
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+B-N] != S[j][i+B-N]:
                return 0
    return 1

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

Submission status: Runtime Error

Solution code:
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 j + B < N:
            #     b = j + B
            # else:
            #     b = j + B - N
            # if i + B < N:
            #     d = i + B
            # else:
            #     d = i + B - N
            if S[i][j+B] != S[j][i+B]:
                return 0
    return 1

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

Submission status: Runtime Error

Solution code:
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 j + B < N:
                b = j + B
            else:
                b = j + B - N
            if i + B < N:
                d = i + B
            else:
                d = i + B - N
            if S[a][b] != S[c][d]:
                return 0
    return 1

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

Submission status: Runtime Error

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

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


count=0

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


    if JUDGE==1:
        count+=1
    

print(count*N)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-


def inp():
    N = int(input())
    S = []
    for i in range(N):
        s = str(input())
        s = [str(ss) for ss in s]
        S.append(s)
    return N, S

def change(S, N, b):
    T = []
    for i in range(N):
        t = []
        s = S[i]
        for j in range(N):
            if j + b >= N:
                t.append(s[j+b-N])
            else:
                t.append(s[j+b])
        T.append(t)
    return T


def check(S, N):
    for i in range(N/2):
        for j in range(i, N):
            if S[i][j] == S[j][i]:
                continue
            else:
                return False
    return True

def main():
    N, S = inp()
    count = 0
    for i in range(N):
        T = change(S, N, i)
        if check(T, N):
            count += 1
    print(count*N, end='')


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
A = [[ord(i) for i in input()] for j in range(n)]
count = 0
for a in range(n):
    arr = np.roll(A, a, axis=0)
    arrT = arr.T
    for i in range(n):
        if arr[i][i:] != arrT[i][i:]:
            break
    else:
        count += n
print(count)

Submission status: Runtime Error

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

cnt = 0

def is_symmetry():


for i in range(n):
    i_ = (n+i)%n
    s_ = s[i_:] + s[:i_]
    for k in range(n):
        for l in range(k+1, n):
            if s_[k][l] != s_[l][k]:
                break
        else:
            continue
        break
    else:
        cnt += 1

print(cnt*n)

Submission status: Runtime Error

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

cnt = 0

def is_symmetry(s_):
    for k in range(n):
        for l in range(k+1, n):
            if s_[k][l] != s_[l][k]:
                return false
    return true

for i in range(n):
    i_ = (n+i)%n
    s_ = s[i_:] + s[:i_]
    if is_symmetry(s_):
        cnt += 1

print(cnt*n)

Submission status: Runtime Error

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

cnt = 0

def is_symmetry():
    for k in range(n):
        for l in range(k+1, n):
            if s_[k][l] != s_[l][k]:
                return false
    return true

for i in range(n):
    i_ = (n+i)%n
    s_ = s[i_:] + s[:i_]
    if is_symmetry():
        cnt += 1

print(cnt*n)

Submission status: Runtime Error

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

cnt = 0

def is_symmetry():
    for k in range(n):
        for l in range(k+1, n):
            if s_[k][l] != s_[l][k]:
                return false
    return true

for i in range(n):
    i_ = (n+i)%n
    s_ = s[i_:] + s[:i_]
    if is_symmetry()
        cnt += 1

print(cnt*n)

Submission status: Runtime Error

Solution code:
N = int(raw_input())
S = [list(raw_input()) for t in range(N)]
ans = 0
for n in range(N):
  t = s[a:]+s[:a]
  t_t = list(map(list, zip(*t)))
  if t == t_t:
    ans += 1
#for n in range(N):
#  isSym = True
#  for i in range(N):
#    for j in range(i,N):
#      if S[i][j] != S[j][i]:
#        isSym = False
#        break
#    if not isSym:
#      break
#  ans += 1 if isSym else 0
#  s = S.pop()
#  S.insert(0, s)
print ans*N

Submission status: Runtime Error

Solution code:
N = int(input())
chars1 = []
for i in range(N):
    chars1.append(list(input()))
chars2 = chars1
suman = 0

for A in range(N):
    for B in range(N):
        for i in range(N):
            for j in range(A,N):
                cha1 = chars1
                cha2 = chars2
                a = A
                b = B
                if (i+A)>N:
                    a-=(N-1)
                if (j+B)>N:
                    b-=(N-1)
                cha2[i][j] = cha1[i+a][j+b]
                ans = 1
        for k in range(N):
            for l in range(k,N):
                if not cha2[k][l]==cha2[l][k]:
                    ans = 0
        suman += ans

print(suman)

Submission status: Runtime Error

Solution code:
import numpy as np
n=int(input())
s=[chr(i) for i in range(97, 97+26)]
 
aa_cij=np.array([[s.index(i)+1  for i in list(input())] for _ in range(n)],dtype='int8')

ans=0
for i in range(n):
  aa_cij=np.concatenate( [ aa_cij[1:,:], aa_cij[[0],:] ], axis=0)
  if np.allclose(aa_cij 、aa_cij.T):
    ans+=1 
print(ans*n)

Submission status: Runtime Error

Solution code:
N = int(input())
S = []
for i in range(N):
    s = list(map(int, input().split()))
    S += [s + s]

cnt = 0
for k in range(N):
    for l in range(N):
        if [[S(k + m, l + n) for m in range(N)] for n in range(N)] == [[S(o, p) for o in range(N)] for p in range(N)]:
            cnt += 1
print(cnt)

Submission status: Runtime Error

Solution code:
N = int(input())
S = [input() for _ in range(N)]
count = 0
check = S[0][0]
fl = 0
for i in range(N):
    for j in range(N):
        if S[i][j] != check:
            fl = -1
            break
    if fl == -1:
        break
if fl == 0:
    print(N**2)
    edit()

for i in range(N):
    flag = 0
    for j in range(N):
        if S[j-i-1][j-1] != S[j-i][j]:
            flag = -1
            break
    if flag == 0:
        count += 1

print(count*2)

Submission status: Runtime Error

Solution code:
N = int(input())
S = [input() for _ in range(N)]
count = 0
check = S[0[0]]
fl = 0
for i in range(N):
    for j in range(N):
        if S[i,j] != check:
            fl = -1
            break
    if fl == -1:
        break
if fl == 0:
    print(N**2)
    edit()

for i in range(N):
    flag = 0
    for j in range(N):
        if S[j-i-1][j-1] != S[j-i][j]:
            flag = -1
            break
    if flag == 0:
        count += 1

print(count*2)

Submission status: Runtime Error

Solution code:
n = int(input())
s1 = [[i for i in input()] for j in range(n)]
count = int(0)
s = []
for b in range(n):
  if s1[0][(1+b)%n] == s1[1][(b)%n]:
    s.append(b)
for a in s:
  flag = 0
  for i in range(n):
    for j in range(n):
      if s1[i][(j+a)%n] != s1[j][(i+a)%n]:
        flag += 1
        break
    if flag == 1:
      break
  if flag == 0:
    count += 1
print(count* n)

Submission status: Runtime Error

Solution code:
def solve():
    global S, N
    N = int(input())

    S = []
    for n in range(N):
        S.append(list(input()))


    res = 0
    for n in range(N):
        if check(n):
            res += N

    print(res)

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


if __name__ == "__main__":
    solve()


def solve():
    global S, N
    N = int(input())

    S = []
    for n in range(N):
        S.append(list(input()))


    res = 0
    for n in range(N):
        if check(n):
            res += N

    print(res)

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


if __name__ == "__main__":
    solve()

Submission status: Runtime Error

Solution code:
def solve():
    global S, N
    N = int(input())

    S = []
    for n in range(N):
        S.append(list(input()))


    res = 0
    for n in range(N):
        if check(n):
            res += N

    print(res)

def check(move):
    for i in range(N):
        for j in range(i+1, N):
            if S[(i-move)%Nj] != S[(j-move)%N][i]:
                return False
    return True


if __name__ == "__main__":
    solve()

Submission status: Runtime Error

Solution code:
import sys
from collections import deque
import copy

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    field = []
    for i in range(N):
        input_raw = read_func().strip()
        field.append(input_raw)

    judge_ij = []
    judge_arr = [[0 for i in range(N)] for j in range(N)]

    for i in range(N):
        if i == 0:
            judge_ij.append((i + 1, N - 1))
        else:
            judge_ij.append((0, i))
        for j in range(N):
            judge_arr[i][j] = field[(i - j) % N][j]

    good_list = []
    for i in range(N):
        is_good = True
        for k in range(N):
            if judge_arr[k][judge_ij[(i + k) % N][0]] != judge_arr[k][judge_ij[(i + k) % N][1]]:
                is_good = False
                break;
        if is_good == True:
            good_list.append(i)

    print len(good_list) * N






if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
count=0
for A in range(N):
    judge=1
    for i in range(N):
        for j in range(i+1,N):
            if S[(i+A)%N][j]!=S[(j+A)%N][i]:
                judge=0
    if judge==1:
        count+=1
print(N*count)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
import numpy as np
N = int(input())
alphabets = 'abcdefghijklmnopqrstuvwxyz'
A = np.zeros((N, N))
for i in range(N):
    for j, c in enumerate(input()):
        A[i,j] = alphabets.index(c)

cnt = 0
for i in range(N):
    for j in range(N):
        B = np.roll(A, (i, j), (0, 1))
        if (B==B.T).all():
            cnt += 1
print(cnt)