import Prelude hiding (foldr)
import Control.Monad
import Control.Monad.State
import Data.Foldable
import Debug.Trace

data DLList a = Null | DLL { dlLeft :: (DLList a)
                           , dlElem :: a
                           , dlRight :: (DLList a)
                           } deriving (Eq)

main = do
        n <- readLn
        result <- execStateT (query n) Null
        print $ result
        putStrLn.unwords.map show.toList $ (result :: DLList Int)

isNull Null = True
isNull _    = False

infixr <>
x <> dllist = insert x dllist

instance Show a => Show (DLList a) where
        show (DLL l a r)
          | isNull l && isNull r = "|N|" ++ " " ++ show a ++ " " ++ "|N|"
          | isNull l = "|N|" ++ " " ++ show a ++ " " ++ show r
          | isNull r = show a ++ " " ++ "|N|"
          | otherwise = show a ++ " " ++ show r

instance Foldable DLList where
    foldr f e Null = e
    foldr f e (DLL l a r) = f a (foldr f e r)

insert x Null = DLL Null x Null
insert x (DLL l a r)
    | isNull l = null1
    | otherwise = insert x l
    where null1 = DLL Null x null2
          null2 = DLL null1 a r

delete x Null = Null
delete x (DLL l a Null)
  | x == a = Null
  | x /= a = DLL (delete x l) a Null

delete x (DLL Null a r)
  | x == a = Null
  | x /= a = DLL Null a (delete x r)
delete x (DLL l a r)
  | x == a = DLL l (dlElem r) (dlRight r)
  | x /= a = DLL l a (delete x r)

delLeft (DLL l a r) = DLL Null a r
delRight (DLL l a r) = DLL l a Null

deleteFirst Null = Null
deleteFirst (DLL Null a r) = delLeft r
deleteFirst (DLL l a r) = deleteFirst l

deleteLast Null = Null
deleteLast (DLL l a Null) = delRight l
deleteLast (DLL l a r)    = deleteLast r

type Query a = StateT (DLList a) IO ()

query :: (Show a, Read a, Eq a) => Int -> Query a
query 0 = return ()
query n = do
        com <- liftIO $ getLine
        let func = getCommand com
        modify func
        query (n-1)

getCommand :: (Show a, Read a, Eq a) => String -> (DLList a -> DLList a)
getCommand str
    | (length.words $ str) == 2 = insOrDel str
    | otherwise                 = del1stOrdelLast str

insOrDel str
    | com == "insert" = insert x
    | com == "delete" = delete x
    where [com,x'] = words str
          x = read x'

del1stOrdelLast str
    | str == "deleteFirst" = deleteFirst
    | str == "deleteLast"  = deleteLast

