local str = io.read()
local index = 1
local tStr = {}
for i = 1, #str do
    tStr[i] = string.sub(str, i, i)
end
local sum = 0
local a = 0
for i = index, #str do
    if tStr[i] == "A" then
        a = a + 1
    elseif  tStr[i]  == "B" and  (i + 1 <= #str and tStr[i + 1]  == "C" ) then
        if a > 0 then
            sum = sum + a
        end
    elseif tStr[i]  == "C" and (i > 1 and  tStr[i - 1]  ~= "B") then
        a = 0
    end
end
print(sum)