s = gets.chomp
$count = 0

def split(str)
  ary = []
  while i = (str.index('BB') || str.index('CC'))
    ary << str[0..i]
    str = str[i+1..-1]
  end
  ary << str if ary.size.positive?
  ary
end

def scan(str)
  while true
    before_count = $count
    str.scan(/AA+BC/) do |item|
      $count += item.size - 2 
      r = 'BC' + (item.size-3).times.inject('A'){|s, i| s << 'A'}
      str.gsub!(/#{item}/, r)
    end
    str.scan(/(ABC(BC)+)/) do |item, _|
      $count += (item.size-1)/2
      r = ((item.size-1)/2-1).times.inject('BC'){|s, i| s << 'BC'} + 'A'
      str.gsub!(/#{item}/, r)
    end
    while (n = str.scan(/ABC/).size) != 0
      $count += n
      str.gsub!(/ABC/, 'BCA')
    end
  #  split(str).each{|e| scan(e) }
    break if before_count == $count
  end
end

#base = split(s)
#base = [s] if base.size.zero?
#base.each{|e| scan(e) }
scan(s)

puts $count