import collections

s = raw_input()
stack = collections.deque([])
i = 0
j = 0
while(j < len(s)):
	while(j < len(s) and s[i] == s[j]): j += 1	
	stack.append(j-i)
	i = j
n = len(s)
while(len(stack) > 1) :
	v = stack.pop()
	u = stack.pop()
	if v > u: 
		if stack:
			stack[-1] += v-u
		else:
			stack.append(v-u)
	elif v < u: stack.append( u - v)

print n - (stack[-1] if stack else 0) import collections collections s = raw_input() s raw_input() raw_input stack = collections.deque([]) stack collections.deque([]) collections.deque collections deque [] i = 0 i 0 j = 0 j 0 while(j < len(s)):
	while(j < len(s) and s[i] == s[j]): j += 1	
	stack.append(j-i)
	i = j j < len(s) j len(s) len s while(j < len(s) and s[i] == s[j]): j += 1	
	 j < len(s) and s[i] == s[j] j < len(s) j len(s) len s s[i] == s[j] s[i] s i s[j] s j stack.append(j-i) stack.append stack append j-i j i i = j i j n = len(s) n len(s) len s while(len(stack) > 1) :
	v = stack.pop()
	u = stack.pop()
	if v > u: 
		if stack:
			stack[-1] += v-u
		else:
			stack.append(v-u)
	elif v < u: stack.append( u - v) len(stack) > 1 len(stack) len stack 1 v = stack.pop() v stack.pop() stack.pop stack pop u = stack.pop() u stack.pop() stack.pop stack pop if v > u: 
		if stack:
			stack[-1] += v-u
		else:
			stack.append(v-u)
	elif v < u: stack.append( u - v) v > u v u if stack:
			stack[-1] += v-u
		else:
			stack.append(v-u)
	 stack stack[-1] += v-u stack[-1] stack -1 v-u v u stack.append(v-u) stack.append stack append v-u v u elif v < u: stack.append( u - v v < u v u print n - (stack[-1] if stack else 0) n stack[-1] if stack else 0 stack stack[-1] stack -1 0 v = stack.pop() stack.pop() v u = stack.pop() stack.pop() u s = raw_input() raw_input() s stack = collections.deque([]) collections.deque([]) stack n = len(s) len(s) n i = 0 0 i j = 0 0 j i = j j i
import collections

s = raw_input()
stack = collections.deque([])
i = 0
j = 0
while(j < len(s)):
	while(j < len(s) and s[i] == s[j]): j += 1	
	stack.append(j-i)
	i = j
n = len(s)
while(len(stack) > 1) :
	v = stack.pop()
	u = stack.pop()
	if v > u: 
		if stack:
			stack[-1] += v-u
		else:
			stack.append(v-u)
	elif v < u: stack.append( u - v)

print n - (stack[-1] if stack else 0)