S = eval(input())

N=len(S)



S2 = S[0]

count = 0

for i in range(1,N):

    S2 += S[i]

    while len(S2) > 1 and S2[len(S2)-1] != S2[len(S2)-2] :

        S2 = S2[:len(S2)-2]

        count += 2

        

print(count)


S = list(eval(input()))

N = len(S)

num = [0,0]

for s in S:

    num[int(s)] += 1

    

print((N-(max(num)-min(num))))
S = eval(input())
N = len(S)
S2 = S[0]
count = 0
for i in range(1, N):
    S2 += S[i]
    while len(S2) > 1 and S2[len(S2) - 1] != S2[len(S2) - 2]:
        S2 = S2[: len(S2) - 2]
        count += 2
print(count)

S = list(eval(input()))
N = len(S)
num = [0, 0]
for s in S:
    num[int(s)] += 1
print((N - (max(num) - min(num))))

-S = eval(input()) +S = list(eval(input())) -S2 = S[0] -count = 0 -for i in range(1, N): -    S2 += S[i] -    while len(S2) > 1 and S2[len(S2) - 1] != S2[len(S2) - 2]: -        S2 = S2[: len(S2) - 2] -        count += 2 -print(count) +num = [0, 0] +for s in S: +    num[int(s)] += 1 +print((N - (max(num) - min(num))))