def main():

    n=int(eval(input()))

    nn=2*n-1

    s=[eval(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()
def main():

    n=int(eval(input()))

    s=[eval(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%n][(i+a)%n]:

                    return 0

        return 1

    print((n*sum([check(i) for i in range(n)])))

main()
def main():
    n = int(eval(input()))
    nn = 2 * n - 1
    s = [eval(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()

def main():
    n = int(eval(input()))
    s = [eval(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 % n][(i + a) % n]:
                    return 0
        return 1

    print((n * sum([check(i) for i in range(n)])))


main()

-    nn = 2 * n - 1 -    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]))) + +    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)])))