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]  == "C" and (i > 1 and tStr[i - 1]  ~= "B")) or (tStr[i]  == "B" and (i > 1 and tStr[i - 1]  == "B")) then
        a = 0
    elseif  tStr[i]  == "B" and  (i + 1 <= #tStr and tStr[i + 1]  == "C") then
        sum = sum + a
        i = i + 1
    end
end
print(sum)
