import qualified Data.ByteString.Char8 as BS
import Data.List
import Data.Maybe

readInts :: IO [Integer]
readInts = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine

readStrings :: IO [BS.ByteString]
readStrings = BS.words <$> BS.getLine

main :: IO ()
main = do
  readInts
  s <- getLine
  print $ solve 0 "" s

solve :: Int -> String -> String -> Int
solve acc before [] = acc
solve acc before (x:xs)
  | before == "A" && x == 'B' = solve acc (before ++ [x]) xs
  | before == "AB" && x == 'C' = solve (acc + 1) "" xs
  | x == 'A' = solve acc "A" xs
  | otherwise = solve acc "" xs