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

main = do
  n <- readLn
  input <- B.getContents
  let tab = listArray ((1,1),(n,n)) $ 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!(x',y) == tab!(y,x') | x<-[1..n], y<-[x..n], let x' = (x+dx)`mod`n+1 ]

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