s = gets.chomp

sum = 0
while true
  unless s.include?('ABC')
    break
  end

  s.sub!(/A+(BC)+/) do |word|
    a_count = word.count('A')
    bc_count = word.scan(/(?=BC)/).count
    sum += a_count * bc_count
    'A' * a_count
  end
end
puts sum
