local s=io.read():gsub("BC","D")
local counter=0
local answer=0
for i=1,#s do
    if s:byte(i)==65 then
        counter=counter+1
    elseif s:byte(i)==68 then
        answer=answer+counter
    else
        counter=0
    end
end
print(answer)