main = do
  s <- getLine
  print . sum . map (score 0) . words . separate . bctos $ s

bctos ('B':'C':xs) = 'S' : bctos xs
bctos (x:xs) = x : bctos xs
bctos [] = []

separate (x:xs)
  | x == 'B' || x == 'C' = ' ' : separate xs
  | otherwise = x : separate xs
separate [] = []

score _ [] = 0
score as (x:xs)
  | x == 'A' = score (as+1) xs
  | otherwise = as + score as xs