import scala.math.BigInt
import scala.io.StdIn

object Main {

  type BI = BigInt

  def main(args: Array[String]): Unit = {
    val s: List[Char] = StdIn.readLine().toList
    println(s"${solve(s, 0, 0)}")
  }

  def solve(s: List[Char], aAlive: BI, ans: BI): BI = {
    s match {
      case Nil => ans
      case 'A' :: t => solve(t, aAlive + 1, ans)
      case 'B' :: 'C' :: t => solve(t, aAlive, ans + aAlive)
      case _ :: t => solve(t, 0, ans)
    }
  }

}
