s = gets.chomp
t = []
a = ""
i = 0
n = s.size
while (i < n)
    if s[i] == "A"
        a += "A"
        i += 1
    elsif n-i > 1 && s[i,2] == "BC"
        a += "D"
        i += 2
    else
        t << a if a.size != 0
        a = ""
        i += 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