s = gets.chomp
$count = 0

def scan(str)
  while true
    before_count = $count
    str.scan(/(A(BC)+)/) do |item, _|
      $count += (item.size-1)/2
      r = ((item.size-1)/2).times.inject(''){|s, i| s << 'BC'} + 'A'
      str.sub!(/#{item}/, r)
    end
    str.scan(/A+BC/) do |item|
      $count += item.size - 2 
      r = 'BC' + (item.size-2).times.inject(''){|s, i| s << 'A'}
      str.sub!(/#{item}/, r)
    end
    break if before_count == $count
  end
end

scan(s)

puts $count