s = gets.chomp

sum = 0
count = s.scan(/(?=ABC)/).count
if count == 0
  puts sum
  exit
end
s.gsub!(/A+(BC)+/) do |word|
  a_count = word.count('A')
  bc_count = word.scan(/(?=BC)/).count
  sum += a_count * bc_count
  'BC' * bc_count + 'A' * a_count
end
while true
  index = s.index('ABC')
  if index == nil
    break
  end

  a = s[0..index].scan(/A+$/)[0]
  bc_count = s[index+1..s.size].match(/^(BC)+/)[0].size / 2
  sum += a.size * bc_count

  s = a + s[(index + bc_count * 2 + 1)...s.size]
end
puts sum
