s = gets.chomp

count = 0
na = 0

until s.empty?
  case s
  when /\A(A+)((BC)+)/
    na += $1.size
    count += na * $2.size/2
    s = $'
  when /(A+)((BC)+)/
    na = $1.size
    count += na * $2.size/2
    s = $'
  else
    break
  end
end

p count
