output_description: Print the number of the ways to choose integers A and B ( 0 \leq A, B < N )
  such that the second board is a good board.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
      S_{1,1}S_{1,2}..S_{1,N}
      S_{2,1}S_{2,2}..S_{2,N}
      :
      S_{N,1}S_{N,2}..S_{N,N}
attempt: def getN():
      return int(input())
  
  
  def getNM():
      return map(int, input().split())
  
  
  def getList():
      return list(map(int, input().split()))
  
  
  def getArray(intn):
      return [int(input()) for i in range(intn)]
  
  
  def input():
      return sys.stdin.readline().rstrip()
  
  
  def rand_N(ran1, ran2):
      return random.randint(ran1, ran2)
  
  
  def rand_List(ran1, ran2, rantime):
      return [random.randint(ran1, ran2) for i in range(rantime)]
  
  
  def rand_ints_nodup(ran1, ran2, rantime):
      ns = []
      while len(ns) < rantime:
          n = random.randint(ran1, ran2)
          if not n in ns:
              ns.append(n)
      return sorted(ns)
  
  
  def rand_query(ran1, ran2, rantime):
      r_query = []
      while len(r_query) < rantime:
          n_q = rand_ints_nodup(ran1, ran2, 2)
          if not n_q in r_query:
              r_query.append(n_q)
      return sorted(r_query)
  
  
  from collections import defaultdict, deque, Counter
  from sys import exit
  from decimal import *
  from heapq import heapify, heappop, heappush
  import math
  import random
  import string
  from copy import deepcopy
  from itertools import combinations, permutations, product
  from operator import mul, itemgetter
  from functools import reduce
  from bisect import bisect_left, bisect_right
  
  import sys
  
  sys.setrecursionlimit(1000000000)
  mod = 10**9 + 7
  
  #############
  # Main Code #
  #############
  
  # N <= 300 O(n ** 3)まで
  # 何通り dp or combo
  N = getN()
  # 1つ目の譜面
  B = [list(input()) for i in range(N)]
  # 2つ目にはなにも書かれてない
  # 2つ目の盤面に縦にi、横にjずらして数字を記入する
  
  # 対角線に対して線対称なものの数を求める
  # 整数a, bの選び方が何通りあるか
  
  
  def judge(a, b):
      res = [[""] * N for i in range(N)]
      # 盤面１のB[i][j]を盤面2に書き込む
      for i in range(N):
          for j in range(N):
              res[(i + a) % N][(j + b) % N] = B[i][j]
  
      for i in range(N):
          for j in range(N):
              if res[i][j] != res[j][i]:
                  return 0
          else:
              continue
          break
      else:
          return 1
  
  
  # 全てのa, bについて調べるなら１つの(a, b)についてO(N)で求める必要がある
  # 判定する際、節約出来ないか？
  
  # N * N のゾーンをずらしていく
  # a [b  a] b
  # c [a  c] a
  # a  b  a  b
  # c  a  c  a 対称軸がずれる 軸は2N - 1本ある
  # 良い盤面になる条件
  
  # 斜めにずらしていくことで前の結果を利用できる
  # 1本の軸について判定した時、1つの盤面が良い盤面なら他全ても良い盤面
  # 軸に刺さっている盤面の数を求めればいい
  
  # 軸は2N - 1本ある
  # 縦に対角線をずらす
  ans = 0
  for i in range(N):
      # 軸(0, i)にはN - i本の盤面が連なっている
      # 連なっている全ての盤面は全てTrueか全てFalse
      ans += (N - i) * judge(i, 0)
  
  # 横に対角線をずらす
  for i in range(1, N):
      ans += (N - i) * judge(0, i)
  print(ans)
  
problem_description: Statement
  
  Snuke has two boards, each divided into a grid with N rows and N columns. For
  both of these boards, the square at the i-th row from the top and the j-th
  column from the left is called Square (i,j).
  
  There is a lowercase English letter written in each square on the first board.
  The letter written in Square (i,j) is S_{i,j}. On the second board, nothing is
  written yet.
  
  Snuke will write letters on the second board, as follows:
  
    * First, choose two integers A and B ( 0 \leq A, B < N ).
    * Write one letter in each square on the second board. Specifically, write the letter written in Square ( i+A, j+B ) on the first board into Square (i,j) on the second board. Here, the k-th row is also represented as the (N+k)-th row, and the k-th column is also represented as the (N+k)-th column.
  
  After this operation, the second board is called a _good_ board when, for
  every i and j ( 1 \leq i, j \leq N ), the letter in Square (i,j) and the
  letter in Square (j,i) are equal.
  
  Find the number of the ways to choose integers A and B ( 0 \leq A, B < N )
  such that the second board is a good board.
samples: [{"input": "2\n    ab\n    ca", "output": "2\n    \n\nFor each pair of A and B, the second board will look as shown below:\n\n![](https://img.atcoder.jp/agc023/2414e26dc3abb6dd7bfa0c800bb4af0c.png)\n\nThe second board is a good board when (A,B) = (0,1) or (A,B) = (1,0), thus the\nanswer is 2.\n\n* * *"}, {"input": "4\n    aaaa\n    aaaa\n    aaaa\n    aaaa", "output": "16\n    \n\nEvery possible choice of A and B makes the second board good.\n\n* * *"}, {"input": "5\n    abcde\n    fghij\n    klmno\n    pqrst\n    uvwxy", "output": "0\n    \n\nNo possible choice of A and B makes the second board good."}]