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

main :: IO ()
main = interact solve

solve :: String -> String
solve = 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 console = case viewr console of EmptyR -> Empty
                                       s :> c -> s