{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_GHC -fno-warn-incomplete-patterns #-}
{-# OPTIONS_GHC -fno-warn-name-shadowing #-}
{-# LANGUAGE OverloadedStrings #-}
-- {-# LANGUAGE MultiWayIf #-}
-- {-# LANGUAGE BangPatterns #-}
-- {-# LANGUAGE ViewPatterns #-}
-- {-# LANGUAGE TupleSections #-}

import           System.IO hiding (char8)
import           Control.Applicative
import           Control.Monad
import           Data.List
import           Data.Tuple
import           Data.Int
import           Data.Char
import           Data.Function (on)
import           Data.Ord (comparing)
import           Data.Monoid (mappend)
import           Data.Array
-- import           Data.Array.Unboxed
-- import           Data.Array.IArray
-- import           Data.Array.ST
-- import           Data.Array.MArray
-- import           Data.Array.Unsafe
import           Data.Ix
import           Data.Maybe
-- import           Data.Monoid hiding ((<>))
import qualified Data.ByteString.Char8 as BS
import qualified Data.ByteString.Lazy.Char8 as BL
import           Data.ByteString.Builder
-- import           Data.Graph
-- import           Data.Vector.Unboxed ((//), (++), (!), (!?))
-- import qualified Data.Vector.Unboxed as U
-- import           Data.IntSet (IntSet)
-- import qualified Data.IntSet as IntSet
-- import           Data.IntMap.Strict (IntMap)
-- import qualified Data.IntMap.Strict as IntMap
-- import           Data.Sequence ((|>), (<|), (><),ViewR(..), ViewL(..), Seq)
-- import qualified Data.Sequence              as Seq
-- import           Data.Foldable (toList, minimumBy)
import           Debug.Trace

data Query = Insert Int | Delete Int | DeleteFirst | DeleteLast

data Deque a = Q [a] Int [a] Int deriving (Show)

emptyQ :: Deque a
emptyQ = Q [] 0 [] 0

viewQ :: Deque a -> [a]
viewQ (Q xs _ ys _) = xs ++ reverse ys

insertQ :: a -> Deque a -> Deque a
insertQ a (Q x lx y ly) = chk $ Q (a:x) (lx + 1) y ly

deleteQ :: Eq a => a -> Deque a -> Deque a
deleteQ a (Q x lx y ly)
  | a `elem` x = chk $ Q (delete a x) (lx - 1) y ly
  | a `elem` y = chk $ Q x lx (delete a y) (ly - 1)
  | otherwise = chk $ Q x lx y ly

deleteFirstQ :: Deque a -> Deque a
deleteFirstQ (Q (_:xs) lx y ly) = chk $ Q xs (lx - 1) y ly
deleteFirstQ (Q [] _ [_] _) = emptyQ

deleteLastQ :: Deque a -> Deque a
deleteLastQ (Q x lx (_:ys) ly) = chk $ Q x lx ys (ly - 1)

chk :: Deque a -> Deque a
chk (Q [] 0 [] 0) = Q [] 0 [] 0
chk (Q [x] lx [] ly) = Q [] ly [x] lx
chk (Q (x:xs) lx y ly) = if lx > ly
  then Q [x] 1 (y++reverse xs) (lx+ly)
  else Q (x:xs) lx y ly

main = do
  n <- readInt1 <$> BS.getLine
  qs <- map myread <$> replicateM n BS.getLine
  putIntN $ solve qs

solve = viewQ . foldl' f emptyQ where
  -- f' q query = traceShowId $ f q query
  f q (Insert a) = insertQ a q
  f q (Delete a) = deleteQ a q
  f q DeleteFirst = deleteFirstQ q
  f q DeleteLast = deleteLastQ q

myread :: BS.ByteString -> Query
myread = f . BS.words where
  f (x:xs)
    | x == "insert" = Insert (readInt1 $ head xs)
    | x == "delete" = Delete (readInt1 $ head xs)
    | x == "deleteFirst" = DeleteFirst
    | x == "deleteLast" = DeleteLast

--  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --

format :: Show a => Maybe a -> IO ()
format Nothing = putStrLn "NO"
format (Just a) = putStrLn "YES" >> print a

-- [1,2,3] -> 1 2 3
putIntN :: [Int] -> IO ()
putIntN [] = return ()
putIntN xs = BL.putStrLn . toLazyByteString . foldl1 mappend . intersperse (char8 ' ') $ map intDec xs

readInt1 :: BS.ByteString -> Int
readInt1 = fst . fromJust . BS.readInt

readInt2 :: BS.ByteString -> (Int,Int)
readInt2 = toTuple . readIntN

readInt3 :: BS.ByteString -> (Int,Int,Int)
readInt3 = toTriple . readIntN

readIntN :: BS.ByteString -> [Int]
readIntN =  map readInt1 . BS.words

readInt641 :: BS.ByteString -> Int64
readInt641 = fromIntegral . fst . fromJust . BS.readInteger

readInt642 :: BS.ByteString -> (Int64,Int64)
readInt642 = toTuple . readInt64N

readInt643 :: BS.ByteString -> (Int64,Int64,Int64)
readInt643 = toTriple . readInt64N

readInt64N :: BS.ByteString -> [Int64]
readInt64N =  map readInt641 . BS.words

readInteger1 :: BS.ByteString -> Integer
readInteger1 = fst . fromJust . BS.readInteger

readInteger2 :: BS.ByteString -> (Integer,Integer)
readInteger2 = toTuple . readIntegerN

readInteger3 :: BS.ByteString -> (Integer,Integer,Integer)
readInteger3 = toTriple . readIntegerN

readIntegerN :: BS.ByteString -> [Integer]
readIntegerN =  map readInteger1 . BS.words

toTuple :: [a] -> (a, a)
toTuple [x, y] = (x, y)

toTriple :: [a] -> (a, a, a)
toTriple [x, y, z] =(x, y, z)

fromTuple :: (a, a) -> [a]
fromTuple (x, y) = [x, y]

fromTriple :: (a, a, a) -> [a]
fromTriple (x, y, z) = [x, y, z]

-- if not applying, use "const"

applyTuple :: (a -> a') -> (b -> b') -> (a, b) -> (a', b')
applyTuple f g (x, y) = (f x, g y)

applyTriple :: (a -> a') -> (b -> b') -> (c -> c') -> (a, b, c) -> (a', b', c')
applyTriple f g h (x, y, z) = (f x, g y, h z)

-- @since 4.8.0.0
sortOn' :: Ord b => (a -> b) -> [a] -> [a]
sortOn' f =
  map snd . sortBy (comparing fst) . map (\x -> let y = f x in y `seq` (y, x))