s=gets.chomp.reverse
s.gsub!('CB', 'D')
s = s.split(/[BC]/).compact.reject(&:empty?)
r=0
s.each do |e|
  k=0
  e.each_char do |c|
    if c == 'A'
      r += k
    else
      k += 1
    end
  end
end

p r