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 (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