import sys

from itertools import product



read = sys.stdin.read

readline = sys.stdin.readline



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

N = int(N)

x = 0

answer = 0

for y in range(N):

    for i, j in product(list(range(N)), repeat=2):

        if S[(i + x) % N][(j + y) % N] != S[(j + x) % N][(i + y) % N]:

            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)

N = int(N)

answer = 0

for y in range(N):

    for i in range(N):

        a = S[i, y:].tolist() + S[i, :y].tolist()

        b = S[:, (i + y) % N].tolist()

        if a != b:

            break

    else:

        answer += N



print(answer)

import sys
from itertools import product

read = sys.stdin.read
readline = sys.stdin.readline
N, *S = list(map(str, read().split()))
N = int(N)
x = 0
answer = 0
for y in range(N):
    for i, j in product(list(range(N)), repeat=2):
        if S[(i + x) % N][(j + y) % N] != S[(j + x) % N][(i + y) % N]:
            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)
N = int(N)
answer = 0
for y in range(N):
    for i in range(N):
        a = S[i, y:].tolist() + S[i, :y].tolist()
        b = S[:, (i + y) % N].tolist()
        if a != b:
            break
    else:
        answer += N
print(answer)

-from itertools import product +import numpy as np +S = np.array(list(map(list, S)), np.str) -x = 0 -    for i, j in product(list(range(N)), repeat=2): -        if S[(i + x) % N][(j + y) % N] != S[(j + x) % N][(i + y) % N]: +    for i in range(N): +        a = S[i, y:].tolist() + S[i, :y].tolist() +        b = S[:, (i + y) % N].tolist() +        if a != b: