Scanf.sscanf (read_line ()) "%d" (fun n ->
    let s = Array.init n (fun _ -> read_line ()) in
    let check1 sh =
        let rec loop y =
            let rec loop2 x =
                if x = n then true else
                    if s.(y).[(x + sh) mod n] = s.(x).[(y + sh) mod n] then loop2 (x + 1) else (
                        false
                    )
            in
            if y = n then true else
                if loop2 0 then loop (y + 1) else false
        in
        loop 0
    in
    let rec loop sh acc =
        if sh = n then acc * n else
            let acc = if check1 sh then acc + 1 else acc in
            loop (sh + 1) acc
    in
    loop 0 0 |> Printf.printf "%d\n"
)