import Control.Applicative
import Text.Printf

main :: IO ()
main = do
  n <- read <$> getLine :: IO Int
  solve [] n

solve :: [Int] -> Int -> IO()
solve xs n = do
  if n == 0 then do {
    printlist xs;
    return ();
    }
    else do {
    ss <- words <$> getLine;
    --printlist (process xs ss);
    (solve $! (process xs ss)) (n - 1);
    }

printlist :: [Int] -> IO ()
printlist xs = do 
  if (null xs) then do {
    putStrLn "";
    return ();
    }
    else do {  
    putStr (show (xs !! 0));
    printlist2 (tail xs);
    }
  
printlist2 :: [Int] -> IO ()
printlist2 xs = do 
  if (null xs) then do {
    putStrLn "";
    return ();
    }
    else do {  
    putStr (" " ++ (show (xs !! 0)));
    printlist2 (tail xs);
    }

process :: [Int] -> [String] -> [Int]
process xs ss
  | ss !! 0 == "insert" = (read (ss !! 1) :: Int) : xs
  | ss !! 0 == "delete" = deletex 0 (read (ss !! 1) :: Int) xs
  | ss !! 0 == "deleteFirst" = tail xs
  | ss !! 0 == "deleteLast" = init xs

deletex :: Int -> Int -> [Int] -> [Int]
deletex n x xs
  | (length xs == n) = xs
  | (xs !! n) == x = ((take (n) xs) ++ (drop (n + 1) xs))
  | otherwise = deletex (n + 1) x xs