let s = Str.global_replace (Str.regexp "BC") "D" @@ read_line ()
let rec f acc bc i =
  if i < 0 then acc
  else if s.[i] = 'A' then f (acc + bc) bc (i - 1)
  else if s.[i] = 'D' then f acc (bc + 1) (i - 1)
  else f acc 0 (i - 1)
let _ = f 0 0 @@ String.length s - 1 |> Printf.printf "%d\n"