s = gets.chomp
res = 0
#p s
flag = true
while flag
	flag = false
	s.gsub!(/(A+)((BC)+)/) do 
		flag = true
		u = $1.size
		v = $2.size / 2
		res += u * v
#		p [$1,$2,u,v]
	#	p  [x,x.size / 2]
#		res += x.size / 2
#		x << ?A
#		x[1..-1]a
		"BC"*v  << "A"*u
	end

#	s.gsub!(/A+(BC)/) do |x|
#		flag = true
	#	p  [x,t = x.size -  2]
#		t = x.size - 2
#		res += t
#		"BC" << ?A*t
#	end
#	p [s,res]
end
p res


