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: Wrong Answer

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).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])

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()
print(count)

Submission status: Wrong Answer

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

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


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

Submission status: Wrong Answer

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

def check(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(0, i)
print(cnt * N)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

result = 0
for offset in range(n):
    is_symmetry = True
    for i in range(n):
        for j in range(i+1, n):
            if s[i%n][(j+offset)%n] != s[(j+offset)%n][i%n]:
                is_symmetry = False
                break
        if not is_symmetry:
            break
    if is_symmetry:
        result += n

print(result)

Submission status: Wrong Answer

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(int(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: Wrong Answer

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


#=2
#s=[['a','b'],['c','a']]
t=[["" for i in range(n)] for i in range(n)]

c=0
for a in range(n):
  f=0
  for i in range(n):
    ia=i+a
    if ia>=n:
      ia-=n
    for j in range(i+1,n):
      if s[j][ia]!=s[ia][j]:
        f=1
        break
  if f==0:
    c+=1
print(c*n)

Submission status: Wrong Answer

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

cnt = 0

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

print(cnt*n)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = [input() for _ in range(n)]
AT = list(map(''.join,zip(*A)))
count = 0
for a in range(n):
    arr = A[a:][:] + A[:a][:]
    arrT = AT[a:][:] + AT[:a][:]
    for i in range(n):
        if arr[i][i+1:] != arrT[i][i+1:]:
            break
    else:
        count += n
print(count)

Submission status: Wrong Answer

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

def isok(b):
    for i in range(N-1):
        for j in range(i+1, N):
            j2 = (j+b)%N
            if src[i][j2] != src[j2][i]:
                return False
    return True

ans = 0
for i in range(-N+1,N):
    if isok(i):
        ans += N-abs(i)
print(ans)

Submission status: Wrong Answer

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

def isok(b):
    for i in range(N-1):
        for j in range(i+1, N):
            j2 = (j+b)%N
            if src[i][j2] != src[j2][i]:
                return False
    return True

ans = 0
for i in range(N):
    if isok(i):
        ans += N if i==0 else 2*(N-i)
print(ans)

Submission status: Wrong Answer

Solution code:
def is_symmetric(board):
    for i in range(N):
        for j in range(N):
            if board(j, i) != board(i, j):
                return False
    return True


def translate(board, a, b):
    def get(i, j):
        return board[(i + a) % N][(j + b) % N]
    
    return get


def solve(board):
    ans = 0
    for a in range(N):
        if is_symmetric(translate(board, a, 0)):
            ans += N - a
    for b in range(N):
        if b == 0:
            continue
        if is_symmetric(translate(board, 0, b)):
            ans += N - b
    return ans


N = int(input())
board = []
for i in range(N):
    board.append(input())

Submission status: Wrong Answer

Solution code:
N=int(input())
B=[]
for i in range(N):
  s=input()
  s*=2
  B.append(s)
for i in range(N):
  B.append(B[i])

def solve(a,b):
  for i in range(N):
    for j in range(i+1,N):
      if B[a+i][b+j]!=B[b+j][a+i]:
        return False
  return True

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

Submission status: Wrong Answer

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)]
##    center = [0 for i in range(N)]
##
##    for i in range(N):
##        if i == 0 and N > 1:
##            center[i] = 0
##        else:
##            center[i] = (center[i - 1] + (N/2 + 1)) % N
##        for j in range(N):
##            judge_arr[i][j] = field[(i - j) % N][j]

    count = 0
    for k in range(N):
        is_good = True
        for i in range(N):
            for j in range(N):
                if i != j:
                    if field[i][(j + k) % N] != field[(j + k) % N][i]:
                        is_good = False
                        break;
            if is_good == False:
                break
        if is_good == True:
            count += 1
    print count * N




##    good_list = set([])
##    for i in range(N):
##        is_good = True
##        if N %
##        for k in range(1, N):
##            if judge_arr[i][(center[i] + k) % N] != judge_arr[i][(center[i] - k) % N]:
##                is_good== False;
##                break;
##
##
##        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.add(i)
##    count = 0
##    for A in range(N):
##        for B in range(N):
##            if (A - B) % N in good_list:
##                count += 1
##    print count



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

cnt = 0

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

print(cnt*2)

Submission status: Wrong Answer

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)
    exit()

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: Wrong Answer

Solution code:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
n=i1()
s=[]
g=[0 for i in range(n)]
for i in range(n):
 s.append(input())
k=[]
for i in range(n):
  for jj in range(1,n):
   for j in range(jj+1):
    if s[(jj-j+i)%n][j]!=s[(j+i)%n][jj-j]:
        g[i]=1
        break

dd=0
for i in range(n):
 for j in range(n):
  if g[(i+j)%n]==0 :
    dd+=1
print(dd)

Submission status: Wrong Answer

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-1):
                    a-=(N-1)
                if (j+B)>=(N-1):
                    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: Wrong Answer

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

def is_ok(mat):
    n = len(mat)
    for i in range(n):
        for j in range(n - i):
            if mat[i][j] != mat[j][i]:
                return False
    return True

count = 0
A = 1
for B in range(N):
    next_S = [S[(i+B) % N] for i in range(N)]
    if is_ok(next_S):
        count += 1

print(count * N)

Submission status: Wrong Answer

Solution code:

def solve():
    N = int(input())
    field = []
    for _ in range(N):
        field.append(input())
    ans = 0
    for horizontal in range(N):
        for vertical in range(N):
            break_flag = False
            for i in range(1, N):
                if not break_flag:
                    for j in range(i + 1):
                        if ((vertical + j) % N - vertical) == ((horizontal + i - j) % N - horizontal):
                            continue
                        if field[(vertical + j) % N][(horizontal + i - j) % N] != field[vertical][(horizontal + i) % N]:
                            break_flag = True
            if not break_flag:
                # print(horizontal, vertical)
                ans += 1
    print(ans)


solve()

Submission status: Wrong Answer

Solution code:
N=int(input())
B=[]
for i in range(N):
  s=input()
  s*=2
  B.append(s)
for i in range(N):
  B.append(B[i])

def solve(a,b):
  for i in range(N):
    for j in range(i+1,N):
      if B[a+i][b+j]!=B[b+j][a+i]:
        return False
  return True

ans=0
for i in range(N):
  for j in range(N):
    if solve(i,j):
      ans+=1
print(ans)

Submission status: Wrong Answer

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

def match(s,k):
    for i in range(n):
        for j in range(n):
            if s[i][j]!=s[(j-k+n)%n][(i+k+n)%n]:
                return False
    return True

ans=0
for k in range(n):
    if match(s,k):
        if k==0:
            ans+=n-k
        elif k<0:
            ans+=2*(n+k)
        else:
            ans+=2*(n-k)

print(ans)

Submission status: Wrong Answer

Solution code:

def solve():
    N = int(input())
    field = []
    for _ in range(N):
        field.append(input())
    ans = 0
    for horizontal in range(N):
        for vertical in range(N):
            break_flag = False
            for i in range(1, N):
                if not break_flag:
                    for j in range(i+1):
                        if (vertical+j)%N == (horizontal+i-j)%N:
                            continue
                        # print(field[(vertical+j)%N][(horizontal-j)%N], field[vertical][horizontal])
                        if field[(vertical+j)%N][(horizontal+i-j)%N] != field[vertical][(horizontal+i)%N]:
                            break_flag = True
            if not break_flag:
                # print(horizontal, vertical)
                ans += 1
    print(ans)


solve()

Submission status: Wrong Answer

Solution code:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
n=i1()
s=[]
g=[0 for i in range(n)]
for i in range(n):
 s.append(input())
k=[]
for i in range(n):
  for jj in range(1,n):
   for j in range(jj+1):
    if s[(jj-j+i)%n][j]!=s[(jj+i)%n][0]:
        g[i]=1
        break

dd=0
for i in range(n):
 for j in range(n):
  if g[(i+j)%n]==0 :
    dd+=1
print(dd)

Submission status: Wrong Answer

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


import numpy as np


def main():
    N = int(input())
    input_list = []
    for n in range(N):
        input_list.append([c for c in input()])
    S = np.array(input_list)
    newS = S.copy()

    c = 0

    for A in range(N):
        for B in range(N):
            if A:
                newS[:, -A:], newS[:, :-A] = newS[:, :A], newS[:, A:]
            if B:
                newS[-B:, :], newS[:-B, :] = newS[:B, :], newS[B:, :]
            if np.all(newS == newS.T):
                c += 1
    print(c)

    return 0


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


import numpy as np


def main():
    N = int(input())
    input_list = []
    for n in range(N):
        input_list.append([c for c in input()])
    S = np.array(input_list)
    newS = S.copy()

    c = 0

    for A in range(N):
        for B in range(N):
            if A:
                newS[:, -A:] = S[:, :A]
                newS[:, :-A] = S[:, A:]
            if B:
                _ = newS.copy()
                newS[-B:, :] = _[:B, :]
                newS[:-B, :] = _[B:, :]
            if np.all(newS == newS.T):
                c += 1
    print(c)

    return 0


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
# B
N = int(input())
S_list = list()
for _ in range(N):
    S_list.append(list(input()))

res = 0

def is_symmetric(M):
    res = True
    for i in range(N):
        for j in range(i+i, N):
            if M[i][j] != M[j][i]:
                return False
    return True

for _ in range(N):
    if is_symmetric(S_list):
        res += 1
    for i in range(N):
        S_list[i] = S_list[i][1:] + S_list[i][:1]
    
print(res*N)

Submission status: Wrong Answer

Solution code:
N = int(input())

ss = []
for i in range(N):
    s = input()
    ss.append(s*2)
for i in range(N):
    ss.append(ss[i])

r = 0

for A in range(N):
    for B in range(N):
        f = True
        for i in range(1,N):
            if ss[A][B] != ss[i+A][i+B]:
                f = False
                break
        if f:
            r += 1

print(r)

Submission status: Wrong Answer

Solution code:
N = int(input())

ss = []
for i in range(N):
    s = input()
    ss.append(s*2)
for i in range(N):
    ss.append(ss[i])

r = 0

print(ss)

for A in range(N):
    for B in range(N):
        f = True
        for i in range(1,N):
            if ss[A][B] != ss[i+A][i+B]:
                f = False
                break
        if f:
            r += 1

print(r)

Submission status: Wrong Answer

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 and N > 1:
            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 = set([])
    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.add(i)
    count = 0
    for A in range(N):
        for B in range(N):
            if (A - B) % N in good_list:
                count += 1
    print count



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import itertools
n = int(input())
ban = [input() for i in range(n)]
ans = 0
for a in range(n):
    for b in range(n):
        flag = a
        for (i,j) in list(itertools.product(range(n),repeat=2)):
            if i+a >= n:
                x = i+a-n
            else:
                x = i+a
            if j+b >= n:
                y = j+b-n
            else:
                y = j+b
            if j+a >= n:
                X = j+a-n
            else:
                X = j+a
            if i+b >= n:
                Y = i+b-n
            else:
                Y = i+b
            #print(a,b,x,y,ban[x][y],ban[X][Y])
            if ban[x][y] != ban[X][Y]:
                flag = -1
                break
        #print(a,b)
        if flag == a:
            ans = n
            #print(a,b)
            break
    if flag == a:
        break
if [ban[0][0]*n for x in range(n)] == ban:
    print(ans*n)
else:
    print(ans)

Submission status: Wrong Answer

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 and N > 1:
            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 = set([])
    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.add(i)
    count = 0
    for A in range(N):
        for B in range(N):
            if (A + B) % N in good_list:
                count += 1
    print count



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
S = []
for _ in range(N):
    S.append(list(input()))
S2 = [e for inner_list in S for e in inner_list]
Tr = []
for i in range(N):
    a = []
    for j in range(N):
        a.append(S[j][(i+j)%N])
    Tr.append(a)
c = collections.Counter(S2)
o = []
for l in c.keys():
    if c[l]%2 == 1:
        o.append(l)
n = []
for t in range(len(Tr)):
    if set(Tr[t]) >= set(o):
        n.append(t)
def taikaku(A):
    n = len(A)
    b = True
    for i in range(n):
        for j in range(n):
            if A[j][i] != A[i][j]:
                b = False
                break
        if not b:
            break
    return(b)
ans = 0
for i in n:
    if taikaku(S[i:]+S[:i]):
        ans += N
print(ans)

Submission status: Wrong Answer

Solution code:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
n=i1()
s=[]
for i in range(n):
 s.append(input())
k=[]
for i in range(n):
  for j in range(n):
    if s[(2*n-1-j-i)%n][j]!=s[n-1-i][0]:
        k.append(i)
        break

dd=0
for i in range(n):
 for j in range(n):
  if not (i+j)%n in k:
    dd+=1
print(dd)

Submission status: Wrong Answer

Solution code:
n = int(input())
ss = list()
for _ in range(n):
    ss.append(input())
ans = 0
for i in range(n):
    for j in range(n):
        flag = True
        for k in range(n):
            if ss[(i + k) % n][j] != ss[(j + k) % n][i]:
                flag = False
                break
        if flag:
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import combinations, product
n=int(input())
s=[["a" for _ in range(n)] for _ in range(n)]
for i in range(n):
  s[i]=list(input())

res=0
for a,b in product(range(n),range(n)):
  for i,j in combinations(range(n),2):
    if(s[(i+a)%n][(j+b)%n]!=s[(j+b)%n][(i+a)%n]):
      break
  else:
    res+=1

print(res)

Submission status: Wrong Answer

Solution code:
import numpy

n = int(input())
s = []

alpha_dict = {}
for i,c in enumerate(range(ord('a'),ord('z')+1)):
    alpha_dict[chr(c)] = i + 1

for i in range(n):
	s.append([alpha_dict[i] for i in list(input())])
count = 0

for a in range(n):
	for b in range(n):
		s2 = s[b:] + s[:b]
		for c in range(n):
			s2[c] = s2[c][a:] + s2[c][:a]
		s2 = numpy.array(s2)

		if numpy.allclose(s2, s2.T):
			if a == b:
				count += 1
			else:
				count += 2

		if a == b:
			break


print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np

def shift(xs, n):
    e = np.empty_like(xs)
    if n > 0:
        e[:n] = xs[-n:]
        e[n:] = xs[:-n]
    elif n < 0:
        e[n:] = xs[:-n]
        e[:n] = xs[-n:]
    else:
        return xs
    return e

d = {chr(x):x for x in range(ord('a'), ord('z')+1)}
n = int(input())
stemp = ''
temp = []
for i in range(n):
    s = input()
    for c in s:
        stemp+=str(d[c])+' '
    stemp = stemp[:-1] + ';'

m = np.matrix(stemp[:-1])
for i in range(n):
    temp.append(shift(m, i))

w = len(temp)
for l in temp[:w-1]:
    q = np.rot90(l)
    for i in range(n):
        temp.append(shift(q, i))

ans = 0
for matrix in temp:
    if np.all(matrix == matrix.T):
        ans += 1


print(ans)
"""
2
ab
ca


4
aaaa
aaaa
aaaa
aaaa


5
abcde
fghij
klmno
pqrst
uvwxy


"""

Submission status: Wrong Answer

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 and N > 1:
            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: Wrong Answer

Solution code:
N = int(input())
s = ["0" for i in range(N)]
d = 0
for i in range(N):
	s[i]=input()
for i in range(N):
	flug = 1
	for k in range(N):
		for l in range(k+1,N):
			if s[(i+k)%N][(l)%N]!=s[(l)%N][(i+k)%N]:
				flug = 0
				break
		if flug == 0:
			break
			
	d = d + flug
d=d*N
print(d)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
s = ["0" for i in range(N)]
t = ["0" for i in range(N)]
d = 0
for i in range(N):
	s[i]=input()
for i in range(N):
	for j in range(N):
		flug = 1
		for k in range(N):
			for l in range(k+1,N):
				if s[(i+k)%N][(j+l)%N]!=s[(j+l)%N][(i+k)%N]:
					flug = 0
					break
			if flug == 0:
				break
			
		d = d + flug
print(d)

Submission status: Wrong Answer

Solution code:
def is_sym(n, ss, a, b):
    for i in range(n - 1):
        ii = (i + a) % n
        for j in range(i + 1, n):
            jj = (j + b) % n
            if ss[ii][jj] != ss[jj][ii]:
                return False
    return True


def t(n, ss):
    ret = []
    for i in range(n):
        row = tuple(ss[j][i] for j in range(n))
        ret.append(row)
    return ret


def it_a(n, ss):
    d = {}
    for i in range(n):
        a = tuple(ss[i:] + ss[:i])
        if a in d:
            d[a][1] += 1
        else:
            d[a] = [i, 1]
    return list(d.values())


def main():
    n = int(input())
    ss = []
    for _ in range(n):
        row = []
        for c in input().strip():
            row.append(ord(c))
        ss.append(tuple(row))
    ans = 0
    aa = it_a(n, ss)
    bb = it_a(n, t(n, ss))
    for a, ac in aa:
        for b, bc in bb:
            if is_sym(n, ss, a, b):
                ans += ac * bc
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def isGood(s, t):
    for i in range(N):
        for j in range(N):
            if s[i][j] != t[j][i]:
                return False
    return True

N = int(input())
s = [['' for i in range(N)]for i in range(N)]
t = [['' for i in range(N)]for i in range(N)]
for i in range(N):
    line = input()
    for j in range(N):
        s[i][j] = line[j]

count = 0
for A in range(N):
    for B in range(N):
        for i in range(N):
            for j in range(N):
                t[(i+A)%N][(j+B)%N] = s[i][j]
        if isGood(s, t):
            count += 1

print (count)

Submission status: Wrong Answer

Solution code:
n = int(input())
ss = list()
for _ in range(n):
    ss.append(input())
ans = 0
for a in range(n):
    for b in range(n):
        flag = True
        for i in range(n):
            for j in range(i + 1, n):
                x, y = (i - a) % n, (j -  b) % n
                if ss[x][y] != ss[y][x]:
                    flag = False
                    break
            if not flag:
                break
        if flag:
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
def check(A, B):
    func = lambda x:x if N > x else x - N
    frag = True
    for i in range(N):
        for j in range(i + 1, N):
            x = func(i + A)
            y = func(j + B)
            if S[x][y] != S[y][x]:
                frag = False
        if not frag:
            break
    return frag

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

Submission status: Wrong Answer

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 = [l[-1]+l[:-1] for l in mt]

print(ans)

Submission status: Wrong Answer

Solution code:
def can_be_pair(row, col, A, B):
    for k in range(N):
        s1 = s[row][(k-B)%N]
        s2 = s[(k-A)%N][col]
        if s1 != s2:
            return False
    return True

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

ret = 0
A = 0
for B in range(N):
    valid = True
    for row in range(N):
        col = (row + A - B)%N
        if not(can_be_pair(row, col, A, B)):
            valid = False
            break
    if valid:
        print(A, B)
        ret += N
print(ret)

Submission status: Wrong Answer

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


#print(n)
#print(e)
answer = 0

for a in range(n):
    for b in range(n):
        bad=0
        for p in range(n):
            for q in range(p):
                if e[(a+p)%n][(b+q)%n] != e[(b+q)%n][(a+p)%n] :
                    bad=1
                    break
            if bad == 1:
                break
        if bad == 0:
            answer += 1

print(answer)