{-# LANGUAGE ViewPatterns #-}

import Control.Monad
import qualified Data.Sequence as S
import Data.Sequence (Seq, (<|), (><), ViewR((:>)))
import Data.Foldable (toList)

type Op = [String]

delete :: Eq a => a -> Seq a -> Seq a
delete e s = case S.elemIndexL e s of
  Just n -> (before >< (S.drop 1 after))
    where (before, after) = S.splitAt n s
  Nothing -> s

processOp :: Seq String -> [Op] -> Seq String
processOp s [] = s
processOp s (op:ops) = case op of
  ["insert", num] -> processOp (num <| s) ops
  ["delete", num] -> processOp (delete num s) ops
  ["deleteFirst"] -> processOp (S.drop 1 s) ops
  ["deleteLast"] -> processOp s' ops where s':>_ = S.viewr s

main :: IO ()
main = do
  n <- readLn
  putStrLn . unwords . toList . processOp S.empty =<< replicateM n (fmap words getLine)