import sys

import numpy as np



read = sys.stdin.read

readline = sys.stdin.readline



N, *S = list(map(str, read().split()))

S = np.array(list(map(list, S)), np.str)

S = np.hstack((S, S))

S = np.vstack((S, S))

N = int(N)

answer = 0

for y in range(N):

    for i in range(N):

        a = S[i, y:y + N]

        b = S[:N, i + y]

        if np.any(a != b):

            break

    else:

        answer += N



print(answer)

import sys

import numpy as np



read = sys.stdin.read

readline = sys.stdin.readline



N, *S = list(map(str, read().split()))

S = np.array(list(map(list, S)), np.str)

S = np.hstack((S, S))

S = np.vstack((S, S))

N = int(N)

answer = 0

for y in range(N):

    a = S[:N, y:y + N]

    if np.all(a == a.T):

        answer += N



print(answer)

import sys
import numpy as np

read = sys.stdin.read
readline = sys.stdin.readline
N, *S = list(map(str, read().split()))
S = np.array(list(map(list, S)), np.str)
S = np.hstack((S, S))
S = np.vstack((S, S))
N = int(N)
answer = 0
for y in range(N):
    for i in range(N):
        a = S[i, y : y + N]
        b = S[:N, i + y]
        if np.any(a != b):
            break
    else:
        answer += N
print(answer)

import sys
import numpy as np

read = sys.stdin.read
readline = sys.stdin.readline
N, *S = list(map(str, read().split()))
S = np.array(list(map(list, S)), np.str)
S = np.hstack((S, S))
S = np.vstack((S, S))
N = int(N)
answer = 0
for y in range(N):
    a = S[:N, y : y + N]
    if np.all(a == a.T):
        answer += N
print(answer)

-    for i in range(N): -        a = S[i, y : y + N] -        b = S[:N, i + y] -        if np.any(a != b): -            break -    else: +    a = S[:N, y : y + N] +    if np.all(a == a.T):