fun main(args: Array<String>) {
    val s = readLine()!!
        .replace("BC","X")
        .replace('B','Y')
        .replace('C','Y')
        .split("Y")
    var result = s.map {
        var count = 0.toLong()
        var acount=0
        it.forEach {c->
            if(c=='A')acount+=1
            else count+=acount
        }
        count
    }.sum()
    println(result)
}