s = gets.chomp

s.gsub!(/BC/, "D")

k = s.split(/[BC]++/)

count = 0
a = 0

k.each{ |str|
  str.length.times{|i|
    if str[i] == "A" then
      a += 1
    elsif str[i] == "D" then
      count += a
    end
  }
  a = 0
}

p count
