{-# LANGUAGE ViewPatterns #-}

import           Control.Monad.Trans.State.Strict
import           Data.Foldable
import           Data.Sequence

main :: IO ()
main = interact $ toList . flip execState empty . mapM_ pressKey

pressKey :: Char -> State (Seq Char) ()
pressKey 'B' = modify delete
pressKey key = modify (|> key)

delete :: Seq Char -> Seq Char
delete (viewr -> EmptyR) = empty
delete (viewr -> s :> c) = s