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 = foldl f [] cmds
  where
    f xs (c : x)
      | c == "insert" = seq xs $ (head x) : xs
      | c == "delete" = seq xs $ delete (head x) xs
      | c == "deleteFirst" = seq xs $ tail xs
      | c == "deleteLast"  = seq xs $ init xs

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

