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)
  str.scan(/AA+BC/) do |item|
    $count += item.size - 3
    r = 'ABC' + (item.size-4).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) }
end

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

puts $count