open Batteries

let () =
  let n = Scanf.scanf "%d\n" (fun a -> a) in

  let arr = Array.make_matrix n n '-' in
  for i = 0 to n-1 do
    for j = 0 to n-1-1 do
      let c = Scanf.scanf "%c " (fun c -> c) in
      Array.set (Array.get arr i) j c
    done;
    let c = Scanf.scanf "%c\n" (fun c -> c) in
    Array.set (Array.get arr i) (n-1) c
  done;


  let cnt = ref 0 in
  let cur_char = ref '-' in

  for j = 0 to n-1 do
    for i = 0 to n-1 do
      let j = j - i in
      let j = if j < 0 then j + n else j in
      let c = (Array.get (Array.get arr i) j) in
      if (i = 0) then (
        cur_char := c;
      ) else (
        if !cur_char <> c then (
          cur_char := '-';
        )
      );
    done;
    if !cur_char <> '-' then (
      cnt := !cnt + n
    )
  done;

  print_endline (string_of_int !cnt)


