import Data.Array
import Debug.Trace

main = do
  n <- readLn
  input <- getContents
  let tab = listArray ((1,1),(n,n)) $ concat $ lines $ input
  print (solve n tab)

type Table = Array (Int,Int) Char

isGood :: Table -> Bool
isGood tab =
  and [tab!(i,j) == tab!(j,i) | i<-[s1..t1], j<-[i..t2]]
  where
    ((s1,s2),(t1,t2)) = bounds tab

solve :: Int -> Table -> Int
solve n tab =
  n * length[1 | i<-[1..n], let rtab = ixmap ((1,1),(n,n)) (f i) tab, isGood rtab]
  where
    f i (x,y) = ((x+i)`mod`n+1, y)