{- SPDX-License-Identifier: X11
 -
 - Copyright 2020 Elias Yuan <a@jthv.ai>, MIT/X11 License
 -   https://jthv.ai/LICENSE/X11.txt
 -
 - ANU-CPC Observation Workshop - D: ABC
 -   2020-05-08
 -}

splitAll :: String -> [String]
splitAll = spl [[]]
  where
    spl :: [String] -> String -> [String]
    spl accu []     = accu
    spl accu (x:y:z:zs)
      | x == 'A' && z == 'C' = spl (accu ++ [[x,y,z]]) zs
      | otherwise            = spl (accu ++ [[x]]) (y:z:zs)
    spl accu (x:xs) = spl (accu ++ [[x]]) xs

function :: String -> Int
function = replaces 0 . splitAll
  where
    replaces :: Int -> [String] -> Int
    replaces accu ss
      | "ABC" `elem` ss = replaces (numReps ss) (splConc ss)
      | otherwise       = accu
      where
        numReps = (+) accu . length . filter (== "ABC")
        splConc = splitAll . concatMap (\x -> if x == "ABC" then "BCA" else x)

main :: IO ()
main = getLine >>= \x -> print $ function x
