import sys

input = lambda : sys.stdin.readline().rstrip()

sys.setrecursionlimit(max(1000, 10**9))

write = lambda x: sys.stdout.write(x+"\n")





n = int(eval(input()))

s = [None]*n

for i in range(n):

    s[i] = eval(input())

    

def sub(i):

#     res = True

#     for j in range(n):

#         if not all(s[(i+j)%n][(j+k)%n]==s[(i+j+k)%n][j] for k in range(n)):

#             res = False

#             break

    res = all(all(s[(i+j)%n][(j+k)%n]==s[(i+j+k)%n][j] for k in range(n)) for j in range(n))

    return res

ans = 0

for i in range(n):

    if sub(i):

        ans += n

print(ans)
import sys

input = lambda : sys.stdin.readline().rstrip()

sys.setrecursionlimit(max(1000, 10**9))

write = lambda x: sys.stdout.write(x+"\n")





n = int(eval(input()))

s = [None]*n

for i in range(n):

    s[i] = eval(input())

    

ans = n * sum(all(all(s[(i+j)%n][(j+k)%n]==s[(i+j+k)%n][j] for k in range(n)) for j in range(n)) for i in range(n))

print(ans)
import sys

input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x + "\n")
n = int(eval(input()))
s = [None] * n
for i in range(n):
    s[i] = eval(input())


def sub(i):
    #     res = True
    #     for j in range(n):
    #         if not all(s[(i+j)%n][(j+k)%n]==s[(i+j+k)%n][j] for k in range(n)):
    #             res = False
    #             break
    res = all(
        all(s[(i + j) % n][(j + k) % n] == s[(i + j + k) % n][j] for k in range(n))
        for j in range(n)
    )
    return res


ans = 0
for i in range(n):
    if sub(i):
        ans += n
print(ans)

import sys

input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x + "\n")
n = int(eval(input()))
s = [None] * n
for i in range(n):
    s[i] = eval(input())
ans = n * sum(
    all(
        all(s[(i + j) % n][(j + k) % n] == s[(i + j + k) % n][j] for k in range(n))
        for j in range(n)
    )
    for i in range(n)
)
print(ans)

- - -def sub(i): -    #     res = True -    #     for j in range(n): -    #         if not all(s[(i+j)%n][(j+k)%n]==s[(i+j+k)%n][j] for k in range(n)): -    #             res = False -    #             break -    res = all( +ans = n * sum( +    all( -    return res - - -ans = 0 -for i in range(n): -    if sub(i): -        ans += n +    for i in range(n) +)