Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import numpy as np
    n = int(input())
    ss = [list(input()) for _ in [0]*n]
    alphabet = "abcdefghijklmnopqrstuvwxyz"
    d = {j: i for i, j in enumerate(alphabet)}
    s = np.array([[d[i] for i in j] for j in ss], dtype=np.int8)

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


main()


Fixed submission:
def main():
    n=int(input())
    nn=2*n-1
    s=[input() for _ in [0]*n]
    s=[i+i[:-1] for i in s]+[i+i[:-1] for i in s][:-1]
    ans=[[0]*n for _ in [0]*n]
    for i in range(1,nn):
        m=min(i+1,n)
        for j in range(nn-1):
            for k in range(max(i-j-n,0)+1,min(m,nn-j,i-j+n)):
                ii=i-k
                if s[i][j]!=s[ii][j+k]:
                    l=min(n-k+1,ii,j)
                    width=l-max(-1,ii-n,j-n)
                    ans[ii-l][j-l]=max(ans[ii-l][j-l],width)
    for i in range(1,n):
        for j in range(1,n):
            ans[i][j]=max(ans[i][j],ans[i-1][j-1]-1)
    print(sum([sum([i==0 for i in a]) for a in ans]))
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import numpy as np
    c=np.concatenate
    n=int(input())
    s=np.array([np.array(list(input())) for _ in [0]*n])
    cnt=0
    for a in range(n):
        for i in range(n):
            ia_n=(i+a)%n
            if not (c([s[i,i+a:n],s[i,:a]])==c([s[i:n-a,ia_n],s[n-a:n,ia_n]])).all():
                break
        else:
            cnt+=1
    print(n*cnt)
main()

Fixed submission:
def main():
    n=int(input())
    nn=2*n-1
    s=[input() for _ in [0]*n]
    s=[i+i[:-1] for i in s]+[i+i[:-1] for i in s][:-1]
    ans=[[0]*n for _ in [0]*n]
    for i in range(1,nn):
        m=min(i+1,n)
        for j in range(nn-1):
            for k in range(max(i-j-n,0)+1,min(m,nn-j,i-j+n)):
                ii=i-k
                if s[i][j]!=s[ii][j+k]:
                    l=min(n-k+1,ii,j)
                    width=l-max(-1,ii-n,j-n)
                    ans[ii-l][j-l]=max(ans[ii-l][j-l],width)
    for i in range(1,n):
        for j in range(1,n):
            ans[i][j]=max(ans[i][j],ans[i-1][j-1]-1)
    print(sum([sum([i==0 for i in a]) for a in ans]))
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import numpy as np
    n=int(input())
    s=np.array([np.array(list(input())) for _ in [0]*n])
    cnt=0
    for a in range(n):
        for i in range(n):
            ia_n=(i+a)%n
            if not (s[i,i+a:n]==s[i:n-a,ia_n]).all():
                break
            elif not (s[i,:a]==s[n-a:n,ia_n]).all():
                break
        else:
            cnt+=1
    print(n*cnt)
main()

Fixed submission:
def main():
    n=int(input())
    nn=2*n-1
    s=[input() for _ in [0]*n]
    s=[i+i[:-1] for i in s]+[i+i[:-1] for i in s][:-1]
    ans=[[0]*n for _ in [0]*n]
    for i in range(1,nn):
        m=min(i+1,n)
        for j in range(nn-1):
            for k in range(max(i-j-n,0)+1,min(m,nn-j,i-j+n)):
                ii=i-k
                if s[i][j]!=s[ii][j+k]:
                    l=min(n-k+1,ii,j)
                    width=l-max(-1,ii-n,j-n)
                    ans[ii-l][j-l]=max(ans[ii-l][j-l],width)
    for i in range(1,n):
        for j in range(1,n):
            ans[i][j]=max(ans[i][j],ans[i-1][j-1]-1)
    print(sum([sum([i==0 for i in a]) for a in ans]))
main()

Buggy python submission (verdict: Time Limit Exceeded):
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()

Fixed submission:
def main():
    n=int(input())
    nn=2*n-1
    s=[input() for _ in [0]*n]
    s=[i+i[:-1] for i in s]+[i+i[:-1] for i in s][:-1]
    ans=[[0]*n for _ in [0]*n]
    for i in range(1,nn):
        m=min(i+1,n)
        for j in range(nn-1):
            for k in range(max(i-j-n,0)+1,min(m,nn-j,i-j+n)):
                ii=i-k
                if s[i][j]!=s[ii][j+k]:
                    l=min(n-k+1,ii,j)
                    width=l-max(-1,ii-n,j-n)
                    ans[ii-l][j-l]=max(ans[ii-l][j-l],width)
    for i in range(1,n):
        for j in range(1,n):
            ans[i][j]=max(ans[i][j],ans[i-1][j-1]-1)
    print(sum([sum([i==0 for i in a]) for a in ans]))
main()

Buggy python submission (verdict: Time Limit Exceeded):
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):
            i_n=i%n
            ia_n=(i+a)%n
            for j in range(i):
                if s[i_n][(j+a)%n]!=s[j%n][ia_n]:
                    flag=1
                    break
            if flag==1:
                break
        else:
            cnt+=1
    print(n*cnt)
main()

Fixed submission:
def main():
    n=int(input())
    nn=2*n-1
    s=[input() for _ in [0]*n]
    s=[i+i[:-1] for i in s]+[i+i[:-1] for i in s][:-1]
    ans=[[0]*n for _ in [0]*n]
    for i in range(1,nn):
        m=min(i+1,n)
        for j in range(nn-1):
            for k in range(max(i-j-n,0)+1,min(m,nn-j,i-j+n)):
                ii=i-k
                if s[i][j]!=s[ii][j+k]:
                    l=min(n-k+1,ii,j)
                    width=l-max(-1,ii-n,j-n)
                    ans[ii-l][j-l]=max(ans[ii-l][j-l],width)
    for i in range(1,n):
        for j in range(1,n):
            ans[i][j]=max(ans[i][j],ans[i-1][j-1]-1)
    print(sum([sum([i==0 for i in a]) for a in ans]))
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n=int(input())
    nn=2*n
    s=[input() for _ in [0]*n]
    #s=[i+i[:-1] for i in s]+[i+i[:-1] for i in s][:-1]
    ans=[[0]*n for _ in [0]*n]
    for i in range(1,nn-1):
        m=min(i+1,n)
        for j in range(nn-2):
            for k in range(1,min(m,nn-1-j)):
                ii=i-k
                if s[i%n][j%n]!=s[ii%n][(j+k)%n]:
                    l=min(n-k+1,ii,j)
                    width=l-max(-1,ii-n,j-n)
                    if width<1:
                        continue
                    ans[ii-l][j-l]=max(ans[ii-l][j-l],width)
    for i in range(1,n):
        for j in range(1,n):
            ans[i][j]=max(ans[i][j],ans[i-1][j-1]-1)
    print(sum([sum([i==0 for i in a]) for a in ans]))
main()

Fixed submission:
def main():
    n=int(input())
    nn=2*n-1
    s=[input() for _ in [0]*n]
    s=[i+i[:-1] for i in s]+[i+i[:-1] for i in s][:-1]
    ans=[[0]*n for _ in [0]*n]
    for i in range(1,nn):
        m=min(i+1,n)
        for j in range(nn-1):
            for k in range(max(i-j-n,0)+1,min(m,nn-j,i-j+n)):
                ii=i-k
                if s[i][j]!=s[ii][j+k]:
                    l=min(n-k+1,ii,j)
                    width=l-max(-1,ii-n,j-n)
                    ans[ii-l][j-l]=max(ans[ii-l][j-l],width)
    for i in range(1,n):
        for j in range(1,n):
            ans[i][j]=max(ans[i][j],ans[i-1][j-1]-1)
    print(sum([sum([i==0 for i in a]) for a in ans]))
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n=int(input())
    nn=2*n
    s=[input() for _ in [0]*n]
    s=[i+i[:-1] for i in s]+[i+i[:-1] for i in s][:-1]
    ans=[[0]*n for _ in [0]*n]
    for i in range(1,nn-1):
        m=min(i+1,n)
        for j in range(nn-2):
            for k in range(1,min(m,nn-1-j)):
                ii=i-k
                if s[i][j]!=s[ii][j+k]:
                    l=min(n-k+1,ii,j)
                    width=l-max(-1,ii-n,j-n)
                    if width<1:
                        continue
                    ans[ii-l][j-l]=max(ans[ii-l][j-l],width)
    for i in range(n-1):
        for j in range(n-1):
            ans[i+1][j+1]=max(ans[i+1][j+1],ans[i][j]-1)
    print(sum([sum([i==0 for i in a]) for a in ans]))
main()

Fixed submission:
def main():
    n=int(input())
    nn=2*n-1
    s=[input() for _ in [0]*n]
    s=[i+i[:-1] for i in s]+[i+i[:-1] for i in s][:-1]
    ans=[[0]*n for _ in [0]*n]
    for i in range(1,nn):
        m=min(i+1,n)
        for j in range(nn-1):
            for k in range(max(i-j-n,0)+1,min(m,nn-j,i-j+n)):
                ii=i-k
                if s[i][j]!=s[ii][j+k]:
                    l=min(n-k+1,ii,j)
                    width=l-max(-1,ii-n,j-n)
                    ans[ii-l][j-l]=max(ans[ii-l][j-l],width)
    for i in range(1,n):
        for j in range(1,n):
            ans[i][j]=max(ans[i][j],ans[i-1][j-1]-1)
    print(sum([sum([i==0 for i in a]) for a in ans]))
main()

Buggy python submission (verdict: Time Limit Exceeded):
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=[[0]*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,min(i+1,n,2*n-1-j)):
                if s[i][j]!=s[i-k][j+k]:
                    width=min(n-k+1,i-k,j)-max(-1,i-k-n,j-n)
                    if width<1:
                        continue
                    l=min(n-k+1,i-k,j)
                    ans[i-k-l][j-l]=max(ans[i-k-l][j-l],width)
    for i in range(n-1):
        for j in range(n-1):
            ans[i+1][j+1]=max(ans[i+1][j+1],ans[i][j]-1)
    print(sum([sum([i==0 for i in a]) for a in ans]))
main()

Fixed submission:
def main():
    n=int(input())
    nn=2*n-1
    s=[input() for _ in [0]*n]
    s=[i+i[:-1] for i in s]+[i+i[:-1] for i in s][:-1]
    ans=[[0]*n for _ in [0]*n]
    for i in range(1,nn):
        m=min(i+1,n)
        for j in range(nn-1):
            for k in range(max(i-j-n,0)+1,min(m,nn-j,i-j+n)):
                ii=i-k
                if s[i][j]!=s[ii][j+k]:
                    l=min(n-k+1,ii,j)
                    width=l-max(-1,ii-n,j-n)
                    ans[ii-l][j-l]=max(ans[ii-l][j-l],width)
    for i in range(1,n):
        for j in range(1,n):
            ans[i][j]=max(ans[i][j],ans[i-1][j-1]-1)
    print(sum([sum([i==0 for i in a]) for a in ans]))
main()

Buggy python submission (verdict: Time Limit Exceeded):
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,min(i+1,n,2*n-1-j)):
                if s[i][j]!=s[i-k][j+k]:
                    for l in range(max(-1,i-k-n,j-n)+1,min(n-k+1,i-k,j)+1):
                        ans[i-k-l][j-l]=False
    print(sum([sum(a) for a in ans]))
main()

Fixed submission:
def main():
    n=int(input())
    nn=2*n-1
    s=[input() for _ in [0]*n]
    s=[i+i[:-1] for i in s]+[i+i[:-1] for i in s][:-1]
    ans=[[0]*n for _ in [0]*n]
    for i in range(1,nn):
        m=min(i+1,n)
        for j in range(nn-1):
            for k in range(max(i-j-n,0)+1,min(m,nn-j,i-j+n)):
                ii=i-k
                if s[i][j]!=s[ii][j+k]:
                    l=min(n-k+1,ii,j)
                    width=l-max(-1,ii-n,j-n)
                    ans[ii-l][j-l]=max(ans[ii-l][j-l],width)
    for i in range(1,n):
        for j in range(1,n):
            ans[i][j]=max(ans[i][j],ans[i-1][j-1]-1)
    print(sum([sum([i==0 for i in a]) for a in ans]))
main()

Buggy python submission (verdict: Time Limit Exceeded):
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()

Fixed submission:
def main():
    n=int(input())
    nn=2*n-1
    s=[input() for _ in [0]*n]
    s=[i+i[:-1] for i in s]+[i+i[:-1] for i in s][:-1]
    ans=[[0]*n for _ in [0]*n]
    for i in range(1,nn):
        m=min(i+1,n)
        for j in range(nn-1):
            for k in range(max(i-j-n,0)+1,min(m,nn-j,i-j+n)):
                ii=i-k
                if s[i][j]!=s[ii][j+k]:
                    l=min(n-k+1,ii,j)
                    width=l-max(-1,ii-n,j-n)
                    ans[ii-l][j-l]=max(ans[ii-l][j-l],width)
    for i in range(1,n):
        for j in range(1,n):
            ans[i][j]=max(ans[i][j],ans[i-1][j-1]-1)
    print(sum([sum([i==0 for i in a]) for a in ans]))
main()