import copy
S = list(input())

flag = True
total = len(S)

S_ = S

while flag:
  S = S_
  S_ = copy.copy(S)
  j = 0
  carsor = 0
  while carsor < len(S)-1:
    if S[carsor] != S[carsor+1]:
      del S_[j]
      del S_[j]
      j -= 2
      carsor += 1
    j += 1
    carsor += 1
  if carsor == j:
    flag = False
      
print(total - len(S))
      
   
  