import scala.io.StdIn

object Main extends App {

  val n = StdIn.readLine()
  val s = StdIn.readLine()

  println(impl(s))

  def impl(s: String): Int = {
    val reqSequence = Array('A', 'B', 'C')
    var count = 0
    var toBeSeen = 0
    for (c <- s) {
      if (c == reqSequence(toBeSeen)) {
        if (toBeSeen == 2) count += 1
        toBeSeen = (toBeSeen + 1) % 3
      } else {
        if (c == 'A') {
          toBeSeen = 1
        } else {
          toBeSeen = 0
        }
      }
    }
    count
  }
}
