Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50
EPS = 1e-8


def run():
    N = int(input())
    S_ = []

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

    #for s in S_:
    #    print(s)
    S = []
    for s in S_:
        S.append(s)
    for s in S_:
        S.append(s)

    #for s in S:
    #    print(s)


    axises = [(i, 0) for i in range(N)]
    for i in range(1, N):
        axises.append((0, i))

    ans = 0

    #print(axises)
    for axis in axises:
        ci, cj = axis
        done = False
        for i in range(N):
            if done:break
            for j in range(i, N):
                if S[ci+i][cj+j] == S[ci+j][cj+i]:continue
                else:
                    #print((ci, cj), (i, j))
                    done=True
                    break
        if not done:
            ans += min(N-ci, N-cj)


    print(ans)

if __name__ == "__main__":
    run()


Fixed submission:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50
EPS = 1e-8


def run():
    N = int(input())
    S_ = []

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

    #for s in S_:
    #    print(s)
    S = []
    for s in S_:
        S.append(s)
    for s in S_:
        S.append(s)

    #for s in S:
    #    print(s)


    axises = [(i, 0) for i in range(N)]
    for i in range(1, N):
        axises.append((0, i))

    ans = 0

    #print(axises)
    for axis in axises:
        ci, cj = axis
        done = False
        for i in range(N):
            if done:break
            for j in range(i, N):
                if S[ci+i][cj+j] == S[ci+j][cj+i]:continue
                else:
                    #print((ci, cj), (i, j))
                    done=True
                    break
        if not done:
            ans += min(N-ci, N-cj)


    print(ans)

if __name__ == "__main__":
    run()

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
from numba import jit

INF = 1 << 50
EPS = 1e-8
@jit
def solve(S):
    count = 0
    N, _ = S.shape
    N //= 2
    #print(N)
    #print(S.shape)
    #print(S)
    for i in range(N):
        for j in range(N):
            cut_S = S[i:i+N, j:j+N]
            #print(cut_S)
            if (cut_S == cut_S.T).all():
                count+=1
    return count



def run():
    N = int(input())
    S = []

    for i in range(N):
        s = input()
        s = [ord(ss)-96 for ss in s]
        S.append(s)
    S = np.array(S, dtype=np.int32)

    S = np.tile(S, (2,2))
    print(solve(S))

if __name__ == "__main__":
    run()


Fixed submission:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50
EPS = 1e-8


def run():
    N = int(input())
    S_ = []

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

    #for s in S_:
    #    print(s)
    S = []
    for s in S_:
        S.append(s)
    for s in S_:
        S.append(s)

    #for s in S:
    #    print(s)


    axises = [(i, 0) for i in range(N)]
    for i in range(1, N):
        axises.append((0, i))

    ans = 0

    #print(axises)
    for axis in axises:
        ci, cj = axis
        done = False
        for i in range(N):
            if done:break
            for j in range(i, N):
                if S[ci+i][cj+j] == S[ci+j][cj+i]:continue
                else:
                    #print((ci, cj), (i, j))
                    done=True
                    break
        if not done:
            ans += min(N-ci, N-cj)


    print(ans)

if __name__ == "__main__":
    run()