let rec for_fold a b v f = if a >= b then v else for_fold (a+1) b (f v a) f
let () =
  Scanf.scanf "%d" @@ fun n ->
  let s = Array.init n (fun _ -> Scanf.scanf " %s" (fun x -> x)) in
  let s = Array.init (2*n-1) (fun i ->
    Array.init n (fun j -> s.(i mod n).[j mod n])) in
  for_fold 0 n 0 (fun c i ->
    let sym =
      for_fold 0 (n*n) true (fun b j ->
        b && s.(i + j/n).(j mod n) = s.(i + j mod n).(j/n))
    in c + if sym then n else 0)
  |> Printf.printf "%d\n"