let () =
  let s = read_line () in
  Printf.printf "%d\n" @@
  fst @@
  Array.fold_left (fun (acc, s) c ->
    match s, c with
    | `A n, 'A' -> (acc, `A (n + 1))
    | `AB _, 'A' -> (acc, `A 1)
    | `A n, 'B' -> (acc, `AB n)
    | `AB n, 'C' -> (acc + n, `A n)
    | _ -> (acc, `A 0)) (0, `A 0) @@
  Array.init (String.length s) (String.get s)
