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