s = gets.split("")

old_count = -1
count = 0
stack_a = 1
stack_b = 0

while old_count != count
	i = 1
	next_s = []
	old_count = count
	while s.size - 1 >= i 
		if s[i] != s[i-1] then
			if stack_a > 0 && stack_b == 0 then
				stack_b += 1
			else
				if stack_a > stack_b then
					count += stack_b * 2
					next_s += s[i - stack_a - stack_b ... i - stack_b * 2]
				else
					count += stack_a * 2
					next_s += s[i - stack_b ... i - stack_b + stack_a]
				end
			
				stack_a = 1
				stack_b = 0
			end
		else
			if stack_b == 0 then
				stack_a += 1
			else
				stack_b += 1
			end
		end

		i += 1
	end

	s = next_s
end

puts count
