local s = io.read()

local i = 1
local counts = {}
local all = 0
while(true) do 
	if string.byte(s, i) == 65 then
		i = i + 1
		table.insert(counts, 0)
	elseif string.byte(s, i) == 66 and string.byte(s, i + 1) == 67 then
		i = i + 2
		for t, v in ipairs(counts) do 
			counts[t] = counts[t] + 1 
		end
	else
		i = i + 1
		for _, v in ipairs(counts) do 
			all = all + v
		end
		counts = {}
	end
	if i > string.len(s) + 1 then
		break
	end
end
print(all)