Scanf.scanf "%d" (fun n ->
    let conv s =
        let arr = Array.make 26 0 in
        String.iter (fun c -> let q = int_of_char c - 97 in arr.(q) <- arr.(q) + 1) s;
        arr
    in
    let s = Array.init n (fun _ -> Scanf.scanf " %s" conv) in
    Array.sort compare s;

    let rec loop i cur prev acc =
        if i = n then acc + cur * (cur - 1) / 2 else
            if s.(i) = prev then loop (i + 1) (cur + 1) prev acc
                else loop (i + 1) 1 s.(i) (acc + cur * (cur - 1) / 2)
    in
    loop 1 1 s.(0) 0 |> Printf.printf "%d\n"
)