{-# LANGUAGE OverloadedStrings #-}

import Control.Applicative
import Control.Monad
import qualified Data.ByteString.Char8 as BC8
import Data.List

doublyList :: [B8.ByteString] -> [B8.ByteString] -> [B8.ByteString]
doublyList xs (c : n)
  | c == "insert" = (head n) : xs
  | c == "delete" = delete (head n) xs
  | c == "deleteFirst" = tail xs
  | c == "deleteLast"  = init xs

main :: IO ()
main = do
  n <- readLn
  xs <- map B8.words <$> replicateM n B8.getLine
  let ans = foldl doublyList [] xs
  B8.putStrLn $ B8.unwords ans

