from queue import *



q = LifoQueue()

S=eval(input())

count=0

for s in S:

    if q.empty():

        q.put(s)

    else:

        q_1 = q.get()

        if q_1 != s:

            count+=2

        else:

            q.put(q_1)

            q.put(s)

print(count)

S = eval(input())

stack = []

ans = 0

for s in S:

  if not stack:

    stack.append(s)

  elif stack[-1] != s:

    stack.pop()

    ans += 2

  else:

    stack.append(s)

    

print(ans)
from queue import *

q = LifoQueue()
S = eval(input())
count = 0
for s in S:
    if q.empty():
        q.put(s)
    else:
        q_1 = q.get()
        if q_1 != s:
            count += 2
        else:
            q.put(q_1)
            q.put(s)
print(count)

S = eval(input())
stack = []
ans = 0
for s in S:
    if not stack:
        stack.append(s)
    elif stack[-1] != s:
        stack.pop()
        ans += 2
    else:
        stack.append(s)
print(ans)

-from queue import * - -q = LifoQueue() -count = 0 +stack = [] +ans = 0 -    if q.empty(): -        q.put(s) +    if not stack: +        stack.append(s) +    elif stack[-1] != s: +        stack.pop() +        ans += 2 -        q_1 = q.get() -        if q_1 != s: -            count += 2 -        else: -            q.put(q_1) -            q.put(s) -print(count) +        stack.append(s) +print(ans)