{-# LANGUAGE OverloadedStrings #-}
import Data.ByteString as SBS hiding(putStrLn)
import Control.Monad.State
import Data.Maybe
import Data.Word

main = do
  s <- SBS.getLine
  let remain = SBS.length $ execState (step s) SBS.empty
  putStrLn $ show (SBS.length s - remain)

step :: ByteString -> State ByteString ()
step "" = pure ()
step i = do
  let Just (x, xs) = uncons i
  st <- get
  if SBS.null st || SBS.head st == x
    then push x
    else pop
  step xs

push :: Word8 -> State ByteString ()
push x = modify (cons x)

pop :: State ByteString ()
pop = state (fromJust . uncons) >> pure ()
