from itertools import groupby

s = input()

g = []

for i, v in groupby(s):
    g.append(len(list(v)))
    
i = 0
j = 1

if len(g) < 2:
    print(0)
    exit()

first = g[i] # 最初に現れる方
second = g[j] # firstじゃない方
ans = 0

while True:
    if first < second:
        ans += 2*first
        first = 0
        second -= first
        i += 2
        if i >= len(g) or j >= len(g):
            break
        first += g[i]
    elif second < first:
        ans += 2*second
        first -= second
        i += 2
        j += 2
        if i >= len(g) or j >= len(g):
            break
        first += g[i]
        second = g[j]
    else:
        ans += 2*first
        i += 2
        j += 2
        if i >= len(g) or j >= len(g):
            break
        first = g[i]
        second = g[j]
        
print(ans)
