let () =
    let main () =
        let s = read_line () in
        let len = String.length s in
        let rec loop i mode acc =
            if i = len then List.rev acc else match s.[i], mode with
            | 'A', 0 -> loop (i + 1) 0 (0 :: acc)
            | 'A', 1 -> loop (i + 1) 0 (0 :: 2 :: acc)
            | 'A', _ -> loop (i + 1) 0 (0 :: 2 :: acc)
            | 'B', 0 -> loop (i + 1) 1 acc
            | 'B', _ -> loop (i + 1) 2 acc
            | 'C', 1 -> loop (i + 1) 0 (1 :: acc)
            | _      -> loop (i + 1) 2 acc
        in
        (* mode 0 - clear stack / mode 1 - prev = B / mode 2 - otherwise *)
        let l = loop 0 0 [] in
        let rec loop stack acc = function
            | [] -> acc
            | 2 :: tl -> loop 0 acc tl
            | 0 :: tl -> loop (stack + 1) acc tl
            | _ :: tl -> loop stack (acc + stack) tl
        in
        Printf.printf "%d\n" (loop 0 0 l)
    in
    main ()