s = gets.chomp.split("")
s.push("#")
id = 0
while s[id] != "#"
  if s[id] == "B" && s[id+1] == "C"
    s[id] = "D"
    s[id+1] = "."
  end
  id += 1
end
id = 0
cnt = as = 0
while s[id] != "#"
  if s[id] == "A"
    as += 1
  elsif s[id] == "D"
    cnt += as
  elsif s[id] == "B" || s[id] == "C"
    as = 0
  end
  id += 1
end
s.delete_at(-1)
puts cnt