fun main(args: Array<String>) {
    val S  = readLine()!!
    var ans = 0L
    var BC = 0
    var n = S.length - 1
    while (n >= 0) {
        if (n >= 1 && S[n - 1] == 'B' && S[n] == 'C') { n--; BC++ }
        else if (S[n] == 'A') ans += BC else BC = 0
        n--
    }
    println(ans)
}
