main = getLine >>= print . solve 0 0

solve ans _ [] = ans
solve ans _ (_:[]) = ans
solve ans tmp ('A':ls) = solve ans (tmp + 1) ls
solve ans tmp ('B':'C':ls) = solve (ans + tmp) tmp ls
solve ans tmp (_:ls) = solve ans 0 ls