from collections import deque

import copy

S = deque(eval(input()))

S2 = deque([])

counter = 0

while True:

    flag = True

    while True:

        if len(S) == 0:

            break

        s = S.popleft()

        if len(S2) == 0:

            S2.append(s)

            flag = False

            continue

        

        elif s!=S2[-1]:

            S2.pop()

            flag = False

            counter +=2

        else:

            S2.append(s)

    

    if flag:

        break

    else:

        S = copy.deepcopy(S2)

print(counter)
from collections import deque

S = deque(eval(input()))

S2 = deque([])

counter = 0

flag = True

while True:

    if len(S) == 0:

        break

    s = S.popleft()

    if len(S2) == 0:

            S2.append(s)

            flag = False

            continue

    

    elif s!=S2[-1]:

            S2.pop()

            flag = False

            counter +=2

    else:

        S2.append(s)

    if flag:

        break

print(counter)
from collections import deque
import copy

S = deque(eval(input()))
S2 = deque([])
counter = 0
while True:
    flag = True
    while True:
        if len(S) == 0:
            break
        s = S.popleft()
        if len(S2) == 0:
            S2.append(s)
            flag = False
            continue
        elif s != S2[-1]:
            S2.pop()
            flag = False
            counter += 2
        else:
            S2.append(s)
    if flag:
        break
    else:
        S = copy.deepcopy(S2)
print(counter)

from collections import deque

S = deque(eval(input()))
S2 = deque([])
counter = 0
flag = True
while True:
    if len(S) == 0:
        break
    s = S.popleft()
    if len(S2) == 0:
        S2.append(s)
        flag = False
        continue
    elif s != S2[-1]:
        S2.pop()
        flag = False
        counter += 2
    else:
        S2.append(s)
    if flag:
        break
print(counter)

-import copy +flag = True -    flag = True -    while True: -        if len(S) == 0: -            break -        s = S.popleft() -        if len(S2) == 0: -            S2.append(s) -            flag = False -            continue -        elif s != S2[-1]: -            S2.pop() -            flag = False -            counter += 2 -        else: -            S2.append(s) +    if len(S) == 0: +        break +    s = S.popleft() +    if len(S2) == 0: +        S2.append(s) +        flag = False +        continue +    elif s != S2[-1]: +        S2.pop() +        flag = False +        counter += 2 +    else: +        S2.append(s) -    else: -        S = copy.deepcopy(S2)