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 sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def main():
    N = int(input())
    S = [input().strip() for _ in range(N)]
    print(sum(N if all(S[(i - a) % N][j] != S[(j - a) % N][i] for i in range(N) for j in range(N)) else 0 for a in range(N)))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [list(input()) for i in range(n)]
ans = 0
for a in range(n):
    check = True
    for x in range(n):
        for y in range(x):
            if s[(x+a)%n][y] != s[(y+a)%n][x]:
                check = False
                break
        if check == False:
            break
    if check:
        ans += n-a
    if a == 0:
        continue
    check = True
    for x in range(n):
        for y in range(x):
            if s[x][(y+a)%n] != s[(y+a)%n][x]:
                check = False
                break
        if check == False:
            break
    if check:
        ans += n-a
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [list(input()) for i in range(n)]
count = [0]*26
for i in s:
    for j in i:
        count[ord(j)-ord("a")] += 1
if max(count) == n**2:
    print(n**2)
    exit()
ans = 0
for a in range(n):
    for b in range(n):
        check = True
        for x in range(n):
            for y in range(x):
                dx = ((y+b)%n-a)%n
                dy = ((x+a)%n-b)%n
                
                if s[x][y] != s[dx][dy]:
                    check = False
                    break
            if check == False:
                break
        if check:
            ans += 1
print(ans)

Submission status: Wrong Answer

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

ans = 0
for a in range(n):
    for b in range(n):
        check = True
        for x in range(n):
            for y in range(x):
                dx = ((y+b)%n-a)%n
                dy = ((x+a)%n-b)%n
                
                if s[x][y] != s[dx][dy]:
                    check = False
                    break
            if check == False:
                break
        if check:
            ans += 1
print(ans)

Submission status: Wrong Answer

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

ans = 0
for a in range(n):
    for b in range(n):
        check = True
        for x in range(n):
            for y in range(x):
                dx = ((y+b)%n-a)%n
                dy = ((x+a)%n-b)%n
                
                if s[x][y] != s[dy][dx]:
                    check = False
                    break
            if check == False:
                break
        if check:
            ans += 1
print(ans)

Submission status: Wrong Answer

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

ans = 0
for a in range(n):
    for b in range(n):
        check = True
        for x in range(n):
            for y in range(x):
                dx = (x+a)%n
                dy = (y+b)%n
                if s[dx][dy] != s[dy][dx]:
                    check = False
                    break
            if check == False:
                break
        if check:
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
L=list()
for i in range(N):
  L.append(list(input())*2)
L=L*2
ans=0
for i in range(N):
  for j in range(N):
    a=0
    for k in range((N//2)+1):
      s=L[i+k][j:j+k]+L[i+k][j+k+1:j+N]
      t=L[i+N-k-1][j:j+N-k-1]+L[i+N-k-1][j+N-k:j+N]
      if t!=s[::-1]:
        a=1
    if a==0:
      ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
L=list()
for i in range(N):
  L.append(list(input())*2)
L=L*2
ans=0
l=N-1
for i in range(N):
  for j in range(N):
    a=0
    for t in range(N):
      for q in range(t):
        if L[i+t][j+q]!=L[i+t-l][j-q+l]:
          a=1
    if a==0:
      ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
"""
不変なもの
- 移動した行/列内の順番
○ AとBの差によって、線対称(対角線上)のものが決まる
"""
n = int(input())
fs = []
for i in range(n):
    rs = list(input())
    fs.append(rs)
cnt = 0
for b in range(n):
    flg = True
    for i in range(n):
        for j in range(n):
            flg &= fs[i][j] == fs[i][(j+b)%n]
    cnt += flg
print(cnt*n)

Submission status: Wrong Answer

Solution code:
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq

n = ni()
S =[]
for i in range(n):
    S.append(input())
def isok(a,b):
    f=True
    ls=[[] for i in range(n)]
    for i in range(n):
        for j in range(i+1,n):
            if not S[(j+b)%n][(i+a)%n] == S[(i+a)%n][(j+b)%n]:
                f=False
                break
    return f

ans = 0
if isok(0,0):
    ans +=n
for a in range(1,n):
    if isok(a,0):
        ans+=n-a
    if isok(0,a):
        ans+=n-a
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=[input() for _ in range(n)]
ans=0
for k in range(n):
  cnt=0
  for i in range(n):
    l=(i+k)%n
    for j in range(n):
      cnt+=s[i][j]==s[(i+l-j)%n][l]
  if cnt==n**2: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):
  cnt=0
  for i in range(n):
    for j in range(n):
      l=(i+k)%n
      if s[i][j]!=s[(i+l-j)%n][l]:break
    else:cnt+=1
  if cnt==n:ans+=n
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil,pi,factorial
    from operator import itemgetter
    def I(): return int(input())
    def MI(): return map(int, input().split())
    def LI(): return list(map(int, input().split()))
    def LI2(): return [int(input()) for i in range(n)]
    def MXI(): return [[LI()]for i in range(n)]
    def SI(): return input().rstrip()
    def printns(x): print('\n'.join(x))
    def printni(x): print('\n'.join(list(map(str,x))))
    inf = 10**17
    mod = 10**9 + 7
#main code here!
    n=I()
    S=[SI() for i in range(n)]
    ans=0
    st=n*(n-1)//2
    for b in range(n):
        count=0
        for i in range(n-1):
            for j in range(i+1,n):
                #print(b,i,j)
                #print(i,(j+b)%n,j,(i+b)%n)
                if S[i][(j+b)%n]==S[j][(i+b)%n]:
                    count+=1
            if count==st:
                ans+=n
    print(ans)
        
        
                





if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
I,R=input,range
n=int(I())
s=[I()for i in R(n)]
a=0
for i in R(n):
 if all(s[(i+j)%n][k]==s[(i+k)%n][j]for j in R(n)for k in R(i+1,n)):a+=n
print(a)

Submission status: Wrong Answer

Solution code:
I,R=input,range
n=int(I())
s=[I()for i in R(n)]
a=0
for i in R(n):
 if all(s[(i+j)%n][k]==s[(i+j)%n][j]for j in R(n) for k in R(i+1,n)):a+=n
print(a)

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    grid = [list(input().rstrip()) for _ in range(n)]

    init = grid[0]
    for i in range(1, n):
        target = []
        for j in range(n):
            target.append(init[(i + j) % n])
        if grid[i] != target:
            break
    else:
        print(n ** 2)
        exit()

    res = 0
    for a in range(n):
        grid2 = [[""] * n for _ in range(n)]
        for i in range(n):
            for j in range(n):
                grid2[i][j] = grid[(i + a) % n][j]
        for i in range(n):
            for j in range(n):
                if grid2[i][j] != grid2[j][i]:
                    break
            else:
                continue
            break
        else:
            res += 1
    print(res * 2)


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
# 愚⇨愚/2 & ちょっと枝刈り
n = int(input())
fs = []
for _ in range(n):
    r = list(input())
    r = [ord(s) - ord("a") for s in r]    
    fs.append(r)

cnt = 0
for di in range(n):
    for dj in range(n):
        # sym[i][j] = fs[(i-di)%n][(j-dj)%n]
        flg = True
        for i in range(n):
            for j in range(i+1, n):
                if fs[(i-di)%n][(j-dj)%n] != fs[(j-dj)%n][(i-di)%n]:
                    flg = False
                    break
        if flg: cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

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

    ans = 0
    for i in range(N):
        flag = True
        for j in range(N):
            for k in range(N):
                if j == k:
                    continue
                if grid[j][(k + i)%N] != grid[(k + i)%N][j]:
                    flag = False
                    break
        if flag:
            ans += N
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#AGC023-B Find Symmetries
"""
各300*300の場所について、シフト数は300*300通り存在する。
実は、縦方向へのシフトをA,横方向へのシフトをBとした時、
A=Bとなるような状態では結果は等しくなる。
よって、縦方向もしくは横方向どちらかのみ動かせばよく、その時の判定にはN^2かかるので、
合計O(N^3)で求まった。
"""
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
n = int(readline())
lst1 = []
for i in range(n):
    lst1.append(readline().rstrip().decode('utf-8'))

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


ans = 0

for i in range(n):
    ans += judge(i)
if ans == 1:
    print(2)
else:
    print(ans*ans)

Submission status: Wrong Answer

Solution code:
def solve():
    N = int(input())
    S2 = [0]*N
    for i in range(N):
        S2[i] = input()
    ans = 0
    for k in range(N):
        cum = [[0]*(N+1) for _ in range(N+1)]
        for i in range(1,N+1):
            for j in range(1,N+1):
                cum[i][j] = cum[i-1][j]+cum[i][j-1]-cum[i-1][j-1]+(S2[i-1][j-1]==S2[(j-1+k)%N][(i-1-k)%N])
    for k in range(N):
        ans += (cum[-1][-1]==N*N)*N
    return ans
print(solve())

Submission status: Wrong Answer

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
N=int(input())
S=[input() for i in range(N)]
a=0
for i in range(N):
    for j in range(N-1):
        for k in range(j+1,N):
            if S[(j+i)%N][k]!=S[k][(j+i)%N]:
                break
        else:
            continue
        break
    else:
        a+=1
print(a*N)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [input() for i in range(n)]
t = []
for i in range(n):
    u = []
    for j in range(n):
        u.append(s[j][i])
    t.append("".join(u))

ans = 0
for i in range(n):
        j = 0
        a = []
        b = []
        for k in range(n):
            a.append(s[(k+i)%n][n+~j:])
            a.append(s[(k+i)%n][:n+~j])
            b.append(t[(k+j)%n][n+~i:])
            b.append(t[(k+j)%n][:n+~i])
        if "".join(a) == "".join(b):
            ans += 1

print(ans*n)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [input() for i in range(n)]
t = []
for i in range(n):
    u = []
    for j in range(n):
        u.append(s[j][i])
    t.append("".join(u))

ans = 0
for i in range(n):
    for j in range(n):
        a = []
        b = []
        for k in range(n):
            a.append(s[(k+i)%n][n+~j:]+s[(k+i)%n][:n+~j])
            b.append(t[(k+j)%n][n+~i:]+t[(k+j)%n][:n+~i])
        if "".join(a) == "".join(b):
            ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  n = int(input())
  board = []
  for _ in range(n):
    board.append(list(input().strip()))
    
  
  cnt = 0
  def judge(ia):
    for i in range(n):
      for j in range(i+1, n):
        if board[j%n][(i+ia)%n] != board[(i+ia)%n][j]:
          return False
    return True
    
  for ia in range(n):
    if judge(ia):
      cnt += 1
  print(n * cnt)
  
if __name__=='__main__':
  main()

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
n=int(input())
S=[list(input()) for i in range(n)]
def check(s,a,b):
    for i in range(n-1):
        for j in range(i+1,n):
            if s[(i-a)%n][(j-b)%n]!=s[(j-b)%n][(i-a)%n]:
                return False
    return True
ans=0
for i in range(n):
    if check(S,0,i):ans+=n
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
n=int(input())
S=[list(input()) for i in range(n)]
def check(s,a,b):
    for i in range(n-1):
        for j in range(i+1,n):
            if s[(i+a)%n][(j+b)%n]!=s[(j+b)%n][(i+a)%n]:
                return False
    return True
ans=0
for i in range(n):
    if check(S,0,i):ans+=n
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
n=int(input())
S=[list(input()) for i in range(n)]
def check(s,a,b):
    for i in range(n-1):
        for j in range(i+1,n):
            if s[(i+a)%n][(j+b)%n]!=s[(j+b)%n][(i+a)%n]:
                return False
    return True
ans=0
for i in range(1,n):
    if check(S,0,i):ans+=n-i
    if check(S,i,0):ans+=n-i
if check(S,0,0):ans+=n
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
S=[list(input()) for i in range(n)]
print(S)
def check(s,a,b):
    for i in range(n-1):
        for j in range(i+1,n):
            if s[(i+a)%n][(j+b)%n]!=s[(j+b)%n][(i+a)%n]:
                return False
    return True
ans=0
for i in range(1,n):
    if check(S,0,i):ans+=n-i
    if check(S,i,0):ans+=n-i
if check(S,0,0):ans+=n
print(ans)

Submission status: Wrong Answer

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

ans=0
for a in range(N):
    new_grid=[]
    new_grid.extend(grid[a:])
    new_grid.extend(grid[:a])

    flag=True
    for i in range(N):
        for j in range(N):
            if new_grid[i][j]==new_grid[j][i]:
                continue
            else:
                flag=False
                break
    if flag:
        ans+=1
print(ans)

Submission status: Wrong Answer

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

ans=0
for a in range(N):
    for b in range(1):
        new_grid=[]
        new_grid.extend(grid[a:])
        new_grid.extend(grid[:a])
        for i in range(N):
            new_grid[i] = new_grid[i][b:]+new_grid[i][:b]
        print(new_grid)

        flag=True
        for i in range(N):
            for j in range(N):
                if new_grid[i][j]==new_grid[j][i]:
                    continue
                else:
                    flag=False
                    break
        if flag:
            ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [list(input()) for i in range(n)]
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: Wrong Answer

Solution code:
N = int(input())
S = [input() for i in range(N)]
F = 0
for i in range(N):
  p = 1
  for j in range(N):
    for k in range(N):
      if S[(i + j) % N][k] != S[j][(i + k) % N]:
        p = 0
        break
    if p == 0:
      break
  F += N * p
print(F)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[]
for i in range(n):
    s=list(input())
    l.append(s+s)
ans=0
for i in range(n):
    f=0
    for h in range(n):
        for w in range(n):
            #0,0+i 1,1+i h,h+i
            if l[h][w+i]!=l[h-w][h+i]:
                f+=1
    if f==0:
        ans+=1
print(ans*n)

Submission status: Wrong Answer

Solution code:
# 解説AC
import numpy as np

def is_symmetric(a):
    """
    対象行列判定 O(N * N)
    """
    return np.array_equal(a, a.T)

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

    S = np.array(S)

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

    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

N = int(input())
S = [list(input().rstrip()) for _ in range(N)]
row = [[0] * 26 for _ in range(N)]
col = [[0] * 26 for _ in range(N)]
for i in range(N):
    for j in range(N):
        c = ord(S[i][j]) - ord('a')
        row[i][c] += 1
        col[j][c] += 1
ans = 0
for i in range(N):
    for j in range(N):
        if row[i] == col[j]:
            ans += 1
print(ans)

Submission status: Wrong Answer

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

ans = 0
for i in range(n):
        for j in range(n):
                for k in range(n):
                        for l in range(k+1, n):
                                x, y = (k+i)%n, (l+j)%n
                                if fie[x][y]!=fie[y][x]: break
                        else: continue
                        break
                else: ans += 1
print(ans)

Submission status: Wrong Answer

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

ans = 0
for i in range(n):
        for j in range(n):
                cnt2 = 0
                for k in range(n):
                        cnt1 = 0
                        for l in range(k+1, n):
                                x, y = (k+i)%n, (l+j)%n
                                if fie[x][y]==fie[y][x]: cnt1 += 1
                        if cnt1==n-k-1: cnt2 += 1
                if cnt2==n: ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
S = [input() for i in range(n)]
A = [[0] * n for i in range(n)]

for i in range(n):
    for j in range(n):
        for k in range(1, n):
            x = (i+k) % n
            y = (j-k) % n
            # print(i,j,x,y,k)
            if S[i][j] == S[x][y]:
                A[(i-(n-1-k))%n][j] += 1
                A[i][(j+(n-1-k))%n] += 1
                # print("p",(i+(n-1-k))%n,j)
                # print("p",i,(j-(n-1-k))%n)
# print(A)
ans = 0
for i in range(n):
    for j in range(n):
        if A[i][j] == 2*n-2:
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
S = [input() for i in range(n)]
A = [[0] * n for i in range(n)]

for i in range(n):
    for j in range(n):
        for k in range(1, n):
            x = (i+k) % n
            y = (j-k) % n
            if S[i][j] == S[x][y]:
                A[(i+(n-1-k))%n][j] += 1
                A[i][(j-(n-1-k))%n] += 1
ans = 0
for i in range(n):
    for j in range(n):
        if A[i][j] == 2*n-2:
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
S = [input() for i in range(n)]
A = [[0] * n for i in range(n)]

for i in range(n):
    a = 1
    m = S[i][0]
    f = 1
    for j in range(n*2):
        x0 = (i+j) % n
        y0 = (-j) % n
        x1 = (i+j+1) % n
        y1 = (-j-1) % n
        if S[x0][y0] != S[x1][y1]:
            if f == 0:
                A[x0][y0] = a
            else:
                f = 0
            a = 1
        else:
            a += 1
    # print('a',a)
    if a > n:
        for j in range(n):
            x0 = (i+j) % n
            y0 = (-j) % n
            A[x0][y0] = n
    else:
        for j in range(n*2):
            x0 = (i+j) % n
            y0 = (-j) % n
            if A[x0][y0] > 0:
                a = A[x0][y0]
                x0 = (x0-1) % n
                y0 = (y0+1) % n
                while A[x0][y0] == 0:
                    a -= 1
                    A[x0][y0] = a
                    x0 = (x0-1) % n
                    y0 = (y0+1) % n
    # print(A)
            
# print(A)

ans = 0
for i in range(n):
    for j in range(n):
        y = 0
        for k in range(n):
            if A[i][(j+k)%n] >= k+1:
                y += 1
            if A[(i+k)%n][(j+n-1)%n] >= n-k:
                y += 1
        if y == n*2:
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
S = [input() for i in range(n)]
A = [[0] * n for i in range(n)]

for i in range(n):
    a = 1
    m = S[i][0]
    f = 1
    for j in range(n*2):
        x0 = (i+j) % n
        y0 = (-j) % n
        x1 = (i+j+1) % n
        y1 = (-j-1) % n
        if S[x0][y0] != S[x1][y1]:
            if f == 0:
                A[x0][y0] = a
            else:
                f = 0
            a = 1
        else:
            a += 1
    # print('a',a)
    if a > n:
        for j in range(n):
            x0 = (i+j) % n
            y0 = (-j) % n
            A[x0][y0] = n
    else:
        for j in range(n*2):
            x0 = (i+j) % n
            y0 = (-j) % n
            if A[x0][y0] > 0:
                a = A[x0][y0]
                x0 = (x0-1) % n
                y0 = (y0+1) % n
                while A[x0][y0] == 0:
                    a -= 1
                    A[x0][y0] = a
                    x0 = (x0-1) % n
                    y0 = (y0+1) % n
    # print(A)
            
# print(A)

ans = 0
for i in range(n):
    for j in range(n):
        y = 0
        for k in range(n):
            if A[i][(j+k)%n] >= (k+1):
                y += 1
        if y == n:
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
S = [input() for i in range(n)]
A = [[0] * n for i in range(n)]

for i in range(n):
    a = 1
    m = S[i][0]
    f = 1
    for j in range(n*2):
        x0 = (i+j) % n
        y0 = (-j) % n
        x1 = (i+j+1) % n
        y1 = (-j+1) % n
        if S[x0][y0] != S[x1][y1]:
            if f == 0:
                A[x0][y0] = a
            else:
                f = 0
            a = 1
        else:
            a += 1
    if a > n:
        for j in range(n):
            x0 = (i+j) % n
            y0 = (-j) % n
            A[x0][y0] = n
    else:
        for j in range(n*2):
            x0 = (i+j) % n
            y0 = (-j) % n
            if A[x0][y0] > 0:
                a = A[x0][y0]
                x0 = (x0-1) % n
                y0 = (y0+1) % n
                while A[x0][y0] == 0:
                    a -= 1
                    A[x0][y0] = a
                    x0 = (x0-1) % n
                    y0 = (y0+1) % n
            
# print(A)

ans = 0
for i in range(n):
    for j in range(n):
        y = 0
        for k in range(n):
            if A[i][(j+k)%n] >= (k+1):
                y += 1
        if y == n:
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
S = [input() for i in range(n)]
A = [[0] * n for i in range(n)]

for i in range(n):
    a = 1
    m = S[i][0]
    f = 1
    for j in range(n*2):
        x0 = (i+j) % n
        y0 = (-j) % n
        x1 = (i+j+1) % n
        y1 = (-j+1) % n
        if S[x0][y0] != S[x1][y1]:
            if f == 0:
                A[x0][y0] = a
            else:
                f = 0
        else:
            a += 1
    if a > n:
        for j in range(n):
            x0 = (i+j) % n
            y0 = (-j) % n
            A[x0][y0] = n
    else:
        for j in range(n*2):
            x0 = (i+j) % n
            y0 = (-j) % n
            if A[x0][y0] > 0:
                a = A[x0][y0]
                x0 = (x0-1) % n
                y0 = (y0+1) % n
                while A[x0][y0] == 0:
                    a -= 1
                    A[x0][y0] = a
                    x0 = (x0-1) % n
                    y0 = (y0+1) % n
            
# print(A)

ans = 0
for i in range(n):
    for j in range(n):
        y = 0
        for k in range(n):
            if A[i][(j+k)%n] >= (k+1):
                y += 1
        if y == n:
            ans += 1
print(ans)

Submission status: Wrong Answer

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

ans = 0
for B in range(N):
    flag = True
    for i in range(N):
        for j in range(i+1, N):
            if S[i][(j-B)%N] != S[(j-B)%N][i]:
                flag = False
                break
    if flag:
        ans += N-B

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

Submission status: Wrong Answer

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

ans = 0
for B in range(N):
    flag = True
    for i in range(N):
        for j in range(i+1, N):
            if S[i][(j+B)%N] != S[(j+B)%N][i]:
                flag = False
                break
        if flag == False:
            break
    if flag:
        ans += N-B

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

Submission status: Wrong Answer

Solution code:
n=int(input())
s=[list(input()) for i in range(n)]
ans=0
for i in range(n):
  ct=0
  for j in range(n):
    for k in range(n):
      if s[(j+i)%n][k]==s[(k+1)%n][j]:
        ct+=1
  if ct==n**2:
    ans+=1
print(ans*n)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = [list(map(lambda x: ord(x) - ord("a") + 1, list(input()))) for _ in range(N)]
#print("S:", S)

yoko, tate = [], []
for i in range(N):
  tmp = 0
  for j in range(N):
    tmp += S[i][j] * 2 ** ((N - j - 1) * 5)
  yoko.append(tmp)
for j in range(N):
  tmp = 0
  for i in range(N):
    tmp += S[i][j] * 2 ** ((N - i - 1) * 5)
  tate.append(tmp)
#print("yoko:", yoko)
#print("tate:", tate)

answer = 0
for y in range(N):
  for t in range(N):
    flag = 0
    for i in range(N):
      if yoko[i] != tate[N - i - 1]:
        flag = 1
        break
    if flag == 0:
      answer += 1
    
    for i in range(N):
      tate[i] = (tate[i] << 5 | tate[i] >> (N - 1) * 5) & (2 ** (5 * N) - 1)
    #print("tate:", tate)
  for i in range(N):
    yoko[i] = (yoko[i] << 5 | yoko[i] >> (N - 1) * 5) & (2 ** (5 * N) - 1)

print(answer)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
a = [list(input().rstrip()) for i in range(n)]
ans = 0
for k in range(n):
    for i in range(n):
        for j in range(i+1,n):
            if a[(i+k)%n][j] != a[(j+k)%n][i]:
                break
        else:
            ans+=1
            continue
        break
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
import sys
input = sys.stdin.readline
table = collections.defaultdict(set)
N = int(input())
S = [list(input().rstrip()) for i in range(N)]
T = [[""] * (N*2) for i in range(2*N)]
table2 = [[set() for j in range(N)] for i in range(N)]

for i in range(2*N-1):
    if i < N:
        T[i] = S[i] + S[i]
    else:
        T[i] = S[i - N] + S[i-N]
ans = 0
for i in range(2*N-1):
    for j in range(2*N-1):
        table[T[i][j]].add((i, j))

for i in range(N):
    for j in range(N):
        for x, y in table[S[i][j]]:
            for k in range(2):
                for l in range(2):
                    idx = i + N*k
                    idy = j + N*l
                    if abs(x-idx) <= N and abs(y - idy) <= N and abs(x-idx) == abs(y-idy):
                        A = min(x, idx)
                        B = min(y, idy)
                        if A >= N:
                            A -= N
                        if B >= N:
                            B -= N
                        table2[i][j].add((A, B))
        # print(table2[i][j])
        for k in range(N):
            A = k - i
            B = k - j
            if A < 0:
                A += N
            if B < 0:
                B += N
            table2[i][j].add((A, B))
        #     print(table2[i][j])
        # print("--------")


ans = set()
for i in range(N):
    for j in range(N):
        if i == 0 and j == 0:
            ans = table2[i][j]
        else:
            ans = ans & table2[i][j]
flag = True
if (0, 0) in ans:
    for i in range(N):
        for j in range(N):
            if S[i][j] == S[j][i]:
                continue
            else:
                flag = False
                ans.remove((0, 0))
                break
        if flag == False:
            break

print(len(ans))