import qualified Data.List as L

type MyList = [String]
type Method = String
type Value = String

-- Your code here!
main :: IO()
main = do
    str <- getLine
    let n = read str :: Int
    list <- doLines n []
    putList list
    
doLines :: Int -> MyList -> IO(MyList)
doLines 0 list = return list
doLines n list = doLine list >>= doLines (n - 1)
    
doLine :: MyList -> IO(MyList)
doLine list = do
    s <- getLine
    let (m, vs) = analyse s
    return $ doMethod m vs list

analyse :: String -> (Method, [Value])
analyse "" = ("", [])
analyse line = (method, values)
    where 
        (method:values) = split ' ' line
        
doMethod :: Method -> [Value] -> MyList -> MyList
doMethod "insert"      []    list = list 
doMethod "insert"      (v:_) list = insert v list
doMethod "delete"      []    list = list 
doMethod "delete"      (v:_) list = delete v list
doMethod "deleteFirst" _     list = deleteFirst list
doMethod "deleteLast"  _     list = deleteLast list
doMethod _ _ list = list

insert :: Value -> MyList -> MyList
insert v list = v:list 

delete :: Value -> MyList -> MyList
delete _ [] = []
delete v list = L.delete v list 

deleteFirst :: MyList -> MyList
deleteFirst [] = []
deleteFirst (_:list) = list

deleteLast :: MyList -> MyList
deleteLast [] = []
deleteLast (_:[]) = []
deleteLast (x:list) = x : deleteLast list

putList :: [String] -> IO()
putList [] = putStrLn ""
putList (x:[]) = putStrLn x
putList (x:xs) = putStr (x ++ " ") >> putList xs

split d = _split d []
_split d cs "" = cs
_split d cs s = _split d (cs ++ [token d s]) (drop (length(token d s) + 1) s)
 
token d = _token d ""
_token d t "" = t
_token d t (x:xs) = if (x == d) then t else _token d (t ++ [x]) xs

