{-# LANGUAGE ViewPatterns #-}

import Data.List
import qualified Data.Foldable as F
import Control.Monad.State
import Data.Sequence (Seq, (<|), (|>), empty, fromList, viewr, ViewR((:>)), viewl, ViewL((:<)), ViewL(EmptyL))

insertDL :: Int -> State (Seq Int) Int
insertDL n = state $ \xs -> (n, n <| xs)

deleteDL :: Int -> State (Seq Int) Int
deleteDL n = state $ \xs -> (n, fromList $ delete n . F.toList $ xs)

deleteFirst :: State (Seq Int) Int
deleteFirst = state $ \s -> let (x :< xs) = viewl s in (x, xs)

deleteLast :: State (Seq Int) Int
deleteLast = state $ \s -> let (xs :> x) = viewr s in (x, xs)

main = do
  _ <- getLine
  lines <- fmap lines getContents
  let cmds = parse lines :: [(String, Int)]
  let result = foldM execCmd 0 cmds
  putStrLn $ concat . intersperse " " . map show . F.toList . snd . runState result $ empty

parse :: [String] -> [(String, Int)]
parse lines = map (\x -> case x of
                           [y] -> (y, -1)
                           [y, z] -> (y, read z)) cmds
              where cmds = map words lines

execCmd :: Int -> (String, Int) -> State (Seq Int) Int
execCmd _ (cmd, n)
  | cmd == "insert"      = insertDL n
  | cmd == "delete"      = deleteDL n
  | cmd == "deleteFirst" = deleteFirst
  | otherwise            = deleteLast