import java.util.*

const val MOD: Long = (1e9+7).toLong()
fun Double.format(digits: Int) = String.format("%.${digits}f", this)
fun <T : Comparable<T>> Iterable<T>.argmax(): Int? = withIndex().maxBy{it.value}?.index
fun <T : Comparable<T>> Iterable<T>.argmin(): Int? = withIndex().minBy{it.value}?.index

fun main(args: Array<String>) {
    val reader = System.`in`.bufferedReader()
    val s = reader.readLine()!!
    val n = s.length

    val a = Array(n, {0L})
    for (i in 1..n-2) {
        if (s.substring(i..i+1) == "BC") {
            var f = false
            for (d in i-1 downTo 0) {
                if (a[d] > 0) {
                    a[i] += a[d]
                    break
                }
                if (f) {
                    break
                }
                if (s[d] == 'A') {
                    a[i] += 1L
                } else if (s[d] == 'B') {
                    break
                } else if (s[d] == 'C') {
                    f = true
                }
            }
        }
    }

    println(a.sum())
}
