{-# LANGUAGE OverloadedStrings #-}

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

import qualified Data.ByteString.Lazy.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
    getLine
    css <- fmap B.words . B.lines <$> B.getContents
    let answer = doCommands css
    putStrLn $ unwords $ fmap show answer

