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 (2*n-1) (fun j -> s.(i mod n).[j mod n])) in
  for_fold 0 n 0 (fun c i ->
    let g = List.sort_uniq (fun (x,_) (y,_) -> x-y) [(i, 0); (0, i)]
    |> List.fold_left (fun c (dx, dy) ->
      let sym =
        for_fold 0 (n*n) true (fun b j ->
          b && s.(dx + j/n).(dy + j mod n) = s.(dx + j mod n).(dy + j/n))
      in c + if sym then n-i else 0) 0
    in c + g)
  |> Printf.printf "%d\n"