s = gets.chomp
ss = s.gsub(/BC/, 'D').split(/[B|C]/)
def count(str)
  count = 0
  c = 0
  ary = str.split('')
  ary.reverse_each do |i|
    if i == 'A'
      count += c
    else
      c += 1
    end
  end
  count
end

p ss.map{|s| count(s) }.inject(:+)