let () =
  Scanf.scanf "%s" @@ fun a ->
  let a = Array.init (String.length a) (fun i -> i, a.[i]) in
  let ct = Array.make 26 0 in
  Array.fold_left (fun c (i, x) ->
    let x = int_of_char x - 97 in
    let c' = c + (i - ct.(x)) in
    ct.(x) <- ct.(x) + 1;
    c') 1 a
  |> Printf.printf "%d\n"