import numpy as np

n = int(eval(input()))

S = np.array([ list(eval(input())) for _ in range(n) ])

ans = 0

for j in range(n):

  M = S[:, [(l+j)%n for l in range(n)]]

  if (M==M.T).all():

    ans += n

print(ans)
import numpy as np

n = int(eval(input()))

S = np.array([ list(eval(input())) for _ in range(n) ])

ans = 0

for j in range(n):

  M = np.roll(S, j, axis=0)

  if (M==M.T).all():

    ans += n

print(ans)
import numpy as np

n = int(eval(input()))
S = np.array([list(eval(input())) for _ in range(n)])
ans = 0
for j in range(n):
    M = S[:, [(l + j) % n for l in range(n)]]
    if (M == M.T).all():
        ans += n
print(ans)

import numpy as np

n = int(eval(input()))
S = np.array([list(eval(input())) for _ in range(n)])
ans = 0
for j in range(n):
    M = np.roll(S, j, axis=0)
    if (M == M.T).all():
        ans += n
print(ans)

-    M = S[:, [(l + j) % n for l in range(n)]] +    M = np.roll(S, j, axis=0)