import Control.Applicative
import Control.Monad
import Data.List

doublyList :: [String] -> [String] -> [String]
doublyList xs ["insert", n] = n : xs
doublyList xs ["delete", n] = delete n xs
doublyList xs ["deleteFirst"] = tail xs
doublyList xs ["deleteLast"]  = init xs

main :: IO ()
main = do
  n <- readLn
  loop n []
    where
      loop 0 xs = do
        putStrLn $ unwords xs
      loop i xs = do
        cmd <- words <$> getLine
        loop (i - 1) (doublyList xs cmd)

