s = gets.chomp
t = []
a = ""
while (s.size != 0)
    if s[0] == "A"
        a += "A"
        s = s[1..-1]
    elsif s.size > 1 && s[0,2] == "BC"
        a += "D"
        s = s[2..-1]
    else
        t << a if a.size != 0
        a = ""
        s = s[1..-1]
    end
end
t << a if a.size != 0
ans = 0
t.each do |str|
    x = 0
    str.size.times do |i|
        if str[i] == "A"
            x += 1
        else
            ans += x
        end
    end
end
puts ans