import Data.Array.Unboxed
import qualified Data.ByteString as B

main = do
  n <- readLn
  input <- B.getContents
  let tab = listArray ((0,0),(n-1,n-1)) $ map fromEnum $ B.unpack $ B.filter (20<) $ input
  print (solve n tab)

type Table = UArray (Int,Int) Int

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 [() | i<-[0..n-1], isGood n i tab]