import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
sys.setrecursionlimit(500*500)
import itertools
from collections import Counter,deque

def main():

    def de(l,i):
        if len(l) == 0:
            return
        if len(l) == 2:
            if l[0] != l[1]:
                l = []
            return
        if l[i] != l[i-1]:
            l.pop(i)
            l.pop(i-1)
            de(l,i-1)
        elif len(l) >= i+1:
            if l[i] != l[i+1]:
                l.pop(i+1)
                l.pop(i)
                de(l,i)
        else:
            pass

    s = list(input().rstrip())
    l = len(s)
    for i in range(1,len(s)):
        de(s,i)
    print(l - len(s))

if __name__=="__main__":
    main()
