(* O(|s|) *)
let s = read_line () in
let n = String.length s in
let rec find acc bc i =
  if i < 0 then acc
  else if i >= 1 && s.[i - 1] = 'B' && s.[i] = 'C' then find acc (bc + 1) @@ i - 2
  else if s.[i] = 'A' then find (acc + bc) bc @@ i - 1
  else find acc 0 @@ i - 1 in
find 0 0 @@ n - 1 |> Printf.printf "%d\n"