{-# LANGUAGE BangPatterns #-}

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

main :: IO ()
main = do
  n <- readLn :: IO Int
  putStrLn . unwords . map show . toList =<< processloop n S.empty
  where
    processloop :: Int -> Seq Int -> IO (Seq Int)
    processloop 0 s = return s
    processloop n s = do
      op <- fmap words getLine
      processloop (n-1) $! processOp s op