s = gets.chomp

s.gsub!(/BC/, "D")

k = s.split(/[BC]++/)

count = 0

# p k

k.each{|str|
  i = 0

  while i < str.length do
    i = str.index("A", i)
    if i != nil then
      count += str[i...str.length].count("D")
      i += 1
    else
      break
    end
  end
}


p count
