function Main(input) {
	var output = 0;
  if(input.length <= 2){
     console.log(output);
    return;
     }
  input = input.replace(/BC/g,"D");//BCは塊なので1文字へ 
  var renzoku = 0;
  while(input.indexOf("AD") != -1){
    output += input.match(new RegExp("AD","g")).length;
    input = input.replace(/AD/g,"DA"); 
  }
        
  console.log(output);
  
  function getValue(val){
    var ret = 0;
    for(var i = 1; i <= val; i++){
      ret += i;
    }
    return ret;
  }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
