solve [] n = n
solve [_] n = n
solve [_,_] n = n
solve ('A':'B':'C':ss) n = solve ss (n+1)
solve (_:'A':'B':ss) n = solve ('A':'B':ss) n
solve (_:_:'A':ss) n = solve ('A':ss) n
solve (_:_:_:ss) n = solve ss n

main = do
  _ <- getLine
  s <- getLine
  putStrLn . show $ solve s 0