main = do s <- getLine print (swap (reverse s)) swap [] = 0 swap ('A':xs) = length (filter (=='B') xs) + swap xs swap (_:xs) = swap xs