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:
N = int(input())
S = [tuple(input()) for i in range(N)]
ans = 0
for A in range(N):
    for B in range(N):
        flag = True
        for i in range(N):
            for j in range(N):
                y = i + A
                x = j + B
                if y >= N:
                    y -= N-1
                if x >= N:
                    x -= N-1

                if S[y][x] == S[x][y]:
                    continue
                else:
                    flag = False
                    break
            if flag == False:
                break
        if flag:
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = [tuple(input()) for i in range(N)]
ans = 0
for A in range(N):
    for B in range(N):
        flag = True
        for i in range(N):
            for j in range(N):
                y = i + A
                x = j + B
                if y >= N:
                    y -= N
                if x >= N:
                    x -= N

                if S[y][x] == S[x][y]:
                    continue
                else:
                    flag = False
                    break
            if flag == False:
                break
        if flag:
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = [input().strip() for _ in range(N)]
cnt = 0
for k in range(N):
    flag = 0
    T = [S[i][k:]+S[i][:k] for i in range(N)]
    for i in range(N-1):
        for j in range(i+1,N):
            if T[i][j]!=T[j][i]:
                flag = 1
                break
        if flag==1:break
    if flag==0:
        cnt += 1
print(cnt**2)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = [input().strip() for _ in range(N)]
cnt = 0
for k in range(N):
    flag = 0
    T = [S[i][k:]+S[i][:k] for i in range(N)]
    for i in range(N-1):
        for j in range(i+1,N):
            if T[i][j]!=T[j][i]:
                flag = 1
                break
        if flag==1:break
    if flag==0:
        cnt += 1
if cnt==0:
    print(0)
elif cnt==1:
    print(N)
else:
    print(N**2)

Submission status: Wrong Answer

Solution code:
def examA():
    N = I()
    A = LI()
    d = defaultdict(int)
    d[0] = 1; cur = 0
    for i in A:
        cur +=i
        d[cur] +=1
#    print(d)
    ans = 0
    for i in d.values():
        ans +=i*(i-1)//2
    print(ans)
    return

def examB():
    N = I()
    S = [SI() for _ in range(N)]
    cur = 0
    for k in range(N):
        flag = True
        for i in range(N):
            for j in range(i+1,N):
                if S[i][j-k]!=S[j-k][i]:
                    flag = False
                    break
            if not flag:
                break
        if flag:
            cur +=1
    ans = cur*N
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examB()

Submission status: Wrong Answer

Solution code:
N = int(input())

S = []

ans = 0

for i in range(N):

    s = list(input())
    S.append(s)


for A in range(N):

    flag = True

    for i in range(N):

        for j in range(i):

            if S[(i+A) % N][j % N] != S[j % N][(i+A) % N]:
                flag = False
                break

        if not flag:
            break

    if flag:
        ans += N

print (ans)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
import copy

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

#実際に書き込む
N = ri()
S = [rs() for _ in range(N)]
S = np.array(S + S)
answer = 0
for a in range(N):
    for b in range(N):
        bool = True
        temp_S = S[a:a+N]
        temp_S2 = []
        for x in temp_S:
            y = x[b:] + x[:b]
            temp_S2.append(y)
        temp_S2 = np.array(temp_S2)
        if all(temp_S2 == temp_S2.T):
            answer += 1

print(answer)

#16

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
import copy

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

#実際に書き込む
N = ri()
S = [rs() for _ in range(N)]
S = np.array(S + S)
answer = 0
for a in range(N):
    for b in range(N):
        bool = True
        temp_S = S[a:a+N]
        temp_S2 = []
        for x in temp_S:
            y = x[b:] + x[:b]
            temp_S2.append(y)
        temp_S2 = np.array(temp_S2)
        if all(temp_S == temp_S2.T):
            answer += 1

print(answer)

#16

Submission status: Wrong Answer

Solution code:
import sys

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

#実際に書き込む
N = ri()
S = [rs() for _ in range(N)]
answer = 0
for a in range(N):
    for b in range(a+1, N):
        bool = True
        for i in range(N):
            for j in range(i+1, N):
                y1 = (i+a)%(N)
                x1 = (j+b)%(N)
                y2 = (j+a)%(N)
                x2 = (i+b)%(N)
                
                if S[y1][x1] != S[y2][x2]:
                    
                    bool = False
                    break
            else:
                continue
            break
        else:
            if bool:
                #print(a, b, i, j, y1, x1, y2, x2)
                answer += 1
answer *= 2
for a in range(N):
    bool = True
    for i in range(N):
        for j in range(i+1, N):
            y1 = (i+a)%(N)
            x1 = (j+a)%(N)
            y2 = (j+a)%(N)
            x2 = (i+a)%(N)
            
            if S[y1][x1] != S[y2][x2]:
                
                bool = False
                break
        else:
            continue
        break
    else:
        if bool:
            #print(a, b, i, j, y1, x1, y2, x2)
            answer += 1
print(answer)
#16

Submission status: Wrong Answer

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

# print(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
            # print(l,k,i)
            # print(arr[l][k],arr[k][l])
            if arr[l][k] != arr[k][l]:
                ok = False

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



print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [input() for _ in range(n)]
ans = 0
for j in range(n):
    for k in range(j + 1, n):
        if s[j][k] != s[k][j]:
            break
    else:
        continue
    break
else:
    ans += n
for i in range(1, n):
    for j in range(n):
        for k in range(j + 1, n):
            if s[j + i - n][k] != s[k + i - n][j]:
                break
        else:
            continue
        break
    else:
        ans += (n - i) * 2
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [input() for _ in range(n)]
ans = 0
for j in range(n):
    for k in range(n):
        if s[j][k] != s[k][j]:
            break
    else:
        continue
    break
else:
    ans += n
for i in range(1, n):
    for j in range(n):
        for k in range(n):
            if s[(j + i) % n][k] != s[(k + i) % n][j]:
                break
        else:
            continue
        break
    else:
        ans += (n - i) * 2
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    n=int(input())
    s=[input() for _ in [0]*n]
    cnt=0
    for a in range(n):
        flag=0
        for i in range(n):
            ia_n=(i+a)%n
            for j in range(i,n-a):
                if s[i][j+a]!=s[j][ia_n]:
                    flag=1
                    break
                else:
                    for j in range(n-a,n):
                        if s[i][j+a-n]!=s[j][ia_n]:
                            flag=1
                            break
            if flag==1:
                break
        else:
            cnt+=1
    print(n*cnt)
main()

Submission status: Wrong Answer

Solution code:
def main():
    n=int(input())
    s=[input() for _ in [0]*n]
    def check(a):
        for i in range(n):
            for j in range(i):
                if s[i%n][(j+a)%n]!=s[(j+a)%n][i%n]:
                    return 0
        return 1
    print(n*sum([check(i) for i in range(n)]))
main()

Submission status: Wrong Answer

Solution code:
def main():
    n=int(input())
    s=[input() for _ in [0]*n]
    s=[i+i[:-1] for i in s]+[i+i[:-1] for i in s][:-1]
    ans=[[True]*n for _ in [0]*n]
    for i in range(1,2*n-1):
        for j in range(2*n-2):
            for k in range(1,n):
                if i-k>=0 and j+k<2*n-1:
                    if s[i][j]!=s[i-k][j+k]:
                        if i-k<n and j<n:
                            ans[i-k][j]=False
                        if i-n-1>=0 and j+k-n-1>=0:
                            ans[i-n-1][j+k-n-1]=False
    print(sum([sum(a) for a in ans]))
main()

Submission status: Wrong Answer

Solution code:
def is_good_grid(sft):
    for r in range(n):
        for c in range(r):
            c_ = (c - sft) % n # 減算に直した
            if s[r][c_] != s[c_][r]:
                return False
    return True


n = int(input())
s = tuple(input() for _ in range(n))

# (0,0)==(1,1)==...==(n-1,n-1)
# colのオフセットだけ変化させる
# それぞれのループで、n個の状態(0,k)==(1,k+1)==...を扱う

ans = 0
for k in range(n):
    if is_good_grid(k):
        ans += n
print(ans)

Submission status: Wrong Answer

Solution code:
def is_good_grid(sft):
    for r in range(n):
        for c in range(r):
            c_ = (c + sft) % n
            if s[r][c_] != s[c_][r]:
                return False
    return True


n = int(input())
s = tuple(input() for _ in range(n))

# (0,0)==(1,1)==...==(n-1,n-1)
# colのオフセットだけ変化させる
# それぞれのループで、n個の状態(0,k)==(1,k+1)==...を扱う

ans = 0
for k in range(n):
    if is_good_grid(k):
        ans += n
print(ans)

Submission status: Wrong Answer

Solution code:
def is_good_grid(sft):
    for r in range(n):
        r_ = (r + sft) % n
        for c in range(r):
            if s[r_][c] != s[c][r_]:
                return False
    return True


n = int(input())
s = tuple(input() for _ in range(n))

# (0,0)==(1,1)==...==(n-1,n-1)
# rowのオフセットだけ変化させる
# それぞれのループで、n個の状態(0,k)==(1,k+1)==...を扱う

ans = 0
for k in range(n):
    if is_good_grid(k):
        ans += n
print(ans)

Submission status: Wrong Answer

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

def allequal(s):
    for i in range(n):
        for j in range(n):
            if s[i][j] != s[0][0]:
                return False
    return True

def val(s,k):
    global n
    for i in range(n):
        if i+k >= n:
            ni = i+k-n
        else:
            ni = i+k
        for j in range(n):
            if s[i][j] != s[j][ni]:
                return False
    return True

if allequal(s):
    print(n**2)
else:
    res = 0
    for k in range(0,n):
        if val(s,k):
            res += n
    print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = []
for _ in range(n):
    sw = input()
    s.append([c for c in sw])

def allequal(s):
    for i in range(n):
        for j in range(n):
            if s[i][j] != s[0][0]:
                return False
    return True

def val(s,k):
    global n
    for i in range(n):
        for j in range(n):
            if i+k >= n:
                ni = i+k-n
            else:
                ni = i+k
            if j-k < 0:
                nj = j-k+n
            else:
                nj = j-k
            if s[i][j] != s[nj][ni]:
                return False
    return True

if allequal(s):
    print(n**2)
else:
    res = 0
    for k in range(0,n):
        if val(s,k):
            res = n
            break
    print(res)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = [''] * N
for i in range(N):
  S[i] = input()
cnt = 0
for a in range(N):
  for i in range(1 - a, N - a):
    _i = i % 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)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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][(i+s)%n]:
        f = 0
        break
  if f:
    ans += n
print(ans)

Submission status: Wrong Answer

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

    ans = 0
    for a in range(N):
        for b in range(N):
            for i in range(N):
                for j in range(N):
                    if i == j:
                        continue
                    if S[(i - a) % N][(j - b) % N] != S[(j - b) % N][(i - a) % N]:
                        break
                else:
                    continue
                break
            else:
                ans += 1

    print(ans)

sol()

Submission status: Wrong Answer

Solution code:
def check(N, S, bi, bj):
    for i in range(N):
        for j in range(i+1, N):
            ii = (bi+i) % N
            jj = (bj+j) % N
            if S[ii][jj] != S[jj][ii]:
                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()

Submission status: Wrong Answer

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

# 解は、B = 0として、A = 0, 1, ..., N - 1 のうち、よい盤面になるものの個数のN倍
ans = N * sum(
    all(
        S[i][j] == S[(j - A) % N][(i + A) % N]
        for i in range(N)
        for j in range(i + 1)
    )
    for A in range(N)
)

# 出力
print(ans)

Submission status: Wrong Answer

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][(r+check)%n] != col[(c+check)%n][(c+check)%n]:
                ok = False
                
        if ok:
            ans += 1
            
print(ans)

Submission status: Wrong Answer

Solution code:
# coding:utf-8

import sys
# from collections import Counter, defaultdict

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(n):
                if B[h][w] != B[(w + i) % n][(h + i) % n]:
                    is_good = 0
                    break

            if not is_good:
                break

        if is_good:
            res += n

    return res


print(main())

Submission status: Wrong Answer

Solution code:
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+k)%N][j] == S[j][(i+k)%N]:
                check = False
                break
        if not check:
            break
    if check:
        ans += N
print(ans)

Submission status: Wrong Answer

Solution code:
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+k)%N][j] == S[j][(i+k)%N]:
                check = False
                break
        if not check:
            break
    if check:
        ans += N-k

for k in range(1,N):
    check = True
    for i in range(N):
        for j in range(i+1,N):
            if not S[i][(j+k)%N] == S[(j+k)%N][i]:
                check = False
                break
        if not check:
            break
    if check:
        ans += N-k
print(ans)

Submission status: Wrong Answer

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())
 
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):
  b = 0

  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)

Submission status: Wrong Answer

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

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(n):
        
        ok = True
        for i in range(1,n):
            if vert[b+i][a+i:a+n] != hrzn[a+i][b+i:b+n]:
                ok = False
                break
                
        if ok:
            ans += 1
            
print(ans)

Submission status: Wrong Answer

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

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(n):
        
        ok = True
        for i in range(1,n):
            if vert[b][a+i:a+n] != hrzn[a][b+i:b+n]:
                ok = False
                
        if ok:
            ans += 1
            
print(ans)

Submission status: Wrong Answer

Solution code:
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)
    if len(a[a!=a.T])==0:c+=n
print(c)

Submission status: Wrong Answer

Solution code:
from itertools import combinations
import sys
N = int(input())

grid = sys.stdin.read().split('\n')

print('unko')

Submission status: Wrong Answer

Solution code:
from itertools import combinations

N = int(input())

S = []

for _ in range(N):
    S.append(input())

res = 0

for a in range(N):
    for x,y in combinations(range(N), r=2):
        if S[(x-a)%N][y] != S[y][(x-a)%N]:
            break
    else:
        res += N
            
print(res)

Submission status: Wrong Answer

Solution code:
from itertools import combinations

N = int(input())

S = []

for _ in range(N):
    S.append(input())

res = 0

for a in range(N):
    for x,y in combinations(range(N), r=2):
        if S[(x+a)%N][y] != S[y][(x+a)%N]:
            break
    else:
        res += N
            
print(res)

Submission status: Wrong Answer

Solution code:
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 + k) % N][i]:
                f = False
                break

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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] != 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)

Submission status: Wrong Answer

Solution code:
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
            x = (i+a)%N
            y=j
            if S[y][x]!=S[x][y]:
                t=0
                flag=False
                break
    if t:
        num+=1
print(N*num)

Submission status: Wrong Answer

Solution code:
import sys

N = int(input())
A = []
for _ in range(N):
    A.append(list(input()))
    
res = 0
i = 0 
while i < N:
    j = 0
    while j < N:
        row = A[i][j:N] + A[i][0:j]
        if i == 0:
            column = [A[x][j] for x in list(range(0,N))]
        elif i == N - 1:
            column = [A[i][j]] + [A[x][j] for x in list(range(0,N-1))]
        else:
            column = [A[x][j] for x in list(range(i,N))] + [A[x][j] for x in list(range(0,i))]
        if row == column:
            res += 1
        j += 1
    i +=1
print(res)

Submission status: Wrong Answer

Solution code:
import sys

N = int(input())
A = []
for _ in range(N):
    A.append(list(input()))
    
res = 0
i = 0 
while i < N:
    j = 0
    while j < N:
        row = A[i][j:N] + A[i][0:j]
        print(res)
        if i == 0:
            column = [A[x][j] for x in list(range(0,N))]
        elif i == N - 1:
            column = [A[i][j]] + [A[x][j] for x in list(range(0,N-1))]
        else:
            column = [A[x][j] for x in list(range(i,N))] + [A[x][j] for x in list(range(0,i))]
        if row == column:
            res += 1
        j += 1
    i +=1
print(res)

Submission status: Wrong Answer

Solution code:
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 = [S() * 2 for _ in range(n)]
    a = a + a
    r = 0
    for i in range(n):
        f = True
        for ii in range(n):
            for jj in range(ii+1,n):
                if a[ii][jj+i] != a[jj+i][ii]:
                    f = False
                    break
        if f:
            r += 1

    return r * n




print(main())

Submission status: Wrong Answer

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

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

print(ans*N)

Submission status: Wrong Answer

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

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

print(ans*N)

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

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 =  shift(array_int).is_sym(0,0)
print(count)