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