import qualified Data.Vector         as V
import qualified Data.Vector.Mutable as VM
import Control.Applicative
import Control.Monad
import Data.IORef
import Text.Printf
import Data.List

type Cmd = [String]

doublyLinkedList :: [Cmd] -> [String]
doublyLinkedList cmds = loop [] cmds
  where
    loop xs [] = xs
    loop xs ((c : x) : cmd)
      | c == "insert" = loop ((head x) : xs) cmd
      | c == "delete" = loop (delete (head x) xs) cmd
      | c == "deleteFirst" = loop (tail xs) cmd
      | c == "deleteLast"  = loop (init xs) cmd

main :: IO ()
main = do
  n  <- readLn
  xs <- map words <$> replicateM n getLine
  putStrLn $ unwords $ doublyLinkedList xs

