fun main(args: Array<String>) {
    agc034b()
}

fun agc034b() {
    val s = readLine()!!.replace("BC", "D").toCharArray()

    var aCount = 0L
    var answer = 0L
    s.forEach {
        when (it) {
            'A' -> aCount++
            'D' -> answer += aCount
            else -> aCount = 0L
        }
    }

    println(answer)
}
