import Control.Applicative

import Data.Foldable (toList)
import Data.Sequence (Seq)
import qualified Data.Sequence as S

removeOne :: Int -> Seq Int -> Seq Int
removeOne x seq =
  case S.viewl seq of
    S.EmptyL  -> S.empty
    s S.:< ss ->
      if x == s
         then ss
         else s S.<| (removeOne x ss)

exec :: [String] -> Seq Int -> Seq Int
exec ["insert", n]   seq = (read n) S.<| seq
exec ["delete", n]   seq = removeOne (read n) seq
exec ["deleteFirst"] seq = let (s  S.:< ss) = S.viewl seq in ss
exec ["deleteLast"]  seq = let (ss S.:>  s) = S.viewr seq in ss

printSeq :: String -> [Int] -> IO ()
printSeq _ []       = putStrLn "" >> return ()
printSeq sep (x:xs) = do
  putStr sep
  putStr $ show x
  printSeq " " xs

main :: IO ()
main = do
  n   <- read <$> getLine :: IO Int
  seq <- readCommand n S.empty
  printSeq "" (toList seq)
  where
    readCommand :: Int -> Seq Int -> IO (Seq Int)
    readCommand 0 seq = return seq
    readCommand n seq = do
      cmds <- words <$> getLine
      readCommand (n-1) (exec cmds seq)

