fun main() {
    val s = readLine() ?: return
    val c = s.replace("BC", "D")
    var t = 0L
    var i = 0
    while (i < c.length) {
        val v = c[i]
        if (v == 'A') {
            var d = 1
            var j = i + 1
            while (j < c.length) {
                val n = c[j]
                if (n == 'D') {
                    t += d
                } else if (n == 'A') {
                    d++
                } else {
                    break
                }
                j++
            }
            i = j
        }
        i++
    }
    println(t.toString())
}