s = gets.chomp
cnt = 0
i = 0
while i < s.length-1
  bcc = 0
  if s[i] == "B" && s[i+1] == "C"
    bcc = 1
    k = 2
    while i+k <= s.length-2 && s[i+k] == "B" && s[i+k+1] == "C"
      bcc += 1
      k += 2
    end
    j = 1
    loop do
      if i == j-1 || s[i-j] != "A"
        bcc.times do |kk|
          s[i-j+1+kk*2] = "B"
          s[i-j+2+kk*2] = "C"
        end
        s[i-j+1+bcc*2..i+bcc*2-1] = "A" * (j-1)
        cnt += (j-1)*bcc
        break
      end
      j += 1
    end
  end
  i += 1 + bcc*2
end
puts cnt
