module Main where

findABC :: String -> (Int, String)
findABC =
  foldl (\(occ, acc) c ->
    case acc of
      "" | c == 'A' -> (occ, "A")
      "A" | c == 'B' -> (occ, "AB")
      "AB" | c == 'C' -> (occ + 1, "")
      _ | c == 'A' -> (occ, "A")
      _ -> (occ, "")) (0, "")

main =
  getLine >>
  getLine >>= \str ->
  let (occ, _) = findABC str
  in putStrLn $ show occ
