numOps :: String -> Int numOps = numOps' 0 0 where numOps' a _ [] = a numOps' a b (c : cs) | c == 'A' = numOps' (a + b) b cs | c == 'B' = numOps' a (b + 1) cs | otherwise = numOps' a b cs main :: IO () main = print . numOps =<< getLine