s = gets.chomp.gsub("BC", "D")
blocks = s.split(/[BC]/)

swaps = blocks.inject(0) do |sum, block|
  right_d = 0
  (block.size-1).downto(0) do |i|
    if block[i] == "D"
      right_d += 1
      next
    end
    if block[i] == "A"
      sum += right_d
    end
  end
  sum
end

p swaps
