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 as (c : x)
      | c == "insert" = (head x) : as
      | c == "delete" = delete (head x) as
      | c == "deleteFirst" = tail as
      | c == "deleteLast"  = init as

main :: IO ()
main = do
  n  <- readLn
  xs <- map words <$> replicateM n getLine
  let ans = doublyLinkedList xs
  print ans


xs = map words ["insert 5", "insert 2", "insert 3", "insert 1", "delete 3", "insert 6", "delete 5"]
ys = map words ["insert 5", "insert 2", "insert 3", "insert 1", "delete 3", "insert 6", "delete 5", "deleteFirst", "deleteLast"]

