import Data.Array
import qualified Data.ByteString.Lazy.Char8 as B
import Debug.Trace

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

type Table = Array (Int,Int) Char

isGood :: Int -> Int -> Table -> Bool
isGood n dx tab =
  and [tab!(f x,y) == tab!(f y,x) | x<-[0..n-1], y<-[x..n-1]]
  where
    f i = (i+dx)`mod`n

solve :: Int -> Table -> Int
solve n tab =
  n * length [1 | i<-[0..n-1], isGood n i tab]