import Control.Applicative
import Data.List
import Data.Array.Unboxed

main = do
  n <- readLn :: IO Int
  s <- lines <$> getContents :: IO [[Char]]

  print $ sum $ map (\x -> if isSymmetrical (listArray ((1,1),(n,n)) (concat x)) n then n else 0) (take n (iterate rotate s))


isSymmetrical :: Array (Int,Int) Char -> Int -> Bool
isSymmetrical s n = and [s!(i,j) == s!(j,i) | i<-[1..n], j<-[i..n]]

rotate :: [a] -> [a]
rotate xs = last xs : init xs
