{-# LANGUAGE BangPatterns      #-}
{-# LANGUAGE OverloadedStrings #-}

import           Control.Applicative
import           Control.Monad
import           Text.Printf

import qualified Data.ByteString.Char8 as B
import           Data.Foldable         (toList)
import qualified Data.Sequence         as S

insert :: a -> S.Seq a -> S.Seq a
insert = (S.<|)

delete :: Eq a => a -> S.Seq a -> S.Seq a
delete x s
    | S.null r = s
    | otherwise =
        case S.viewl r of
            x S.:< xs -> l S.>< xs
  where
    (l, r) = S.breakl (== x) s

deleteFirst :: S.Seq a -> S.Seq a
deleteFirst s =
    case S.viewl s of
        x S.:< xs -> xs

deleteLast :: S.Seq a -> S.Seq a
deleteLast s =
    case S.viewr s of
        xs S.:> x -> xs

doCommands :: [[B.ByteString]] -> [Int]
doCommands css = toList $ f S.empty css
  where
    f !s []                    = s
    f !s (["insert", a]:xss)   = let Just (b, _) = B.readInt a
                                 in f (insert b s) xss
    f !s (["delete", a]:xss)   = let Just (b, _) = B.readInt a
                                 in f (delete b s) xss
    f !s (["deleteFirst"]:xss) = f (deleteFirst s) xss
    f !s (["deleteLast"]:xss)  = f (deleteLast s) xss

main :: IO ()
main = do
    n <- readLn
    cs <- fmap B.words <$> replicateM n B.getLine
    let answer = doCommands cs
    putStrLn $ unwords $ fmap show answer

