import Control.Applicative
import Data.Array.IO
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as C

main :: IO ()
main = do
  s1 <- BS.getLine
  n <- return (case (C.readInt s1) of
                 Just x -> fst x
                 Nothing -> 0)
  nums <- newArray(0, 2100000) 0 :: IO(IOUArray Int Int)
  solve n nums 0 0

solve :: Int -> IOUArray Int Int -> Int -> Int -> IO ()
solve n nums left right = do
  if n == 0 then do { printanswer nums left right; return (); }
    else do {
    ss <- C.words <$> BS.getLine;
    if C.index (ss !! 0) 0 == 'i'
    then do {
      x <- return (case (C.readInt (ss !! 1)) of
                      Just s -> fst s
                      Nothing -> 0);
      writeArray nums right x;
      solve (n - 1) nums left (right + 1);
      return ();
      }
    else do {
      if C.length (ss !! 0) == 6
      then do {
        x <- return (case (C.readInt (ss !! 1)) of
                       Just s -> fst s
                       Nothing -> 0);
        deletex nums left right x;
        solve (n - 1) nums left right;
        return ();
        }
      else do {
        if C.index (ss !! 0) 6 == 'F' then do {
          right2 <- newright nums left right;
          solve (n - 1) nums left right2;
          }
        else do {
          left2 <- newleft nums left right;
          solve (n - 1) nums left2 right;
          }
        }
      }
    }

newright :: IOUArray Int Int -> Int -> Int -> IO Int
newright nums left right = do
  x <- readArray nums (right - 1);
  if x == (-1) then do {
    y <- newright nums left (right - 1);
    return y;
    }
    else do {
    return (right - 1);
    }

newleft :: IOUArray Int Int -> Int -> Int -> IO Int
newleft nums left right = do
  x <- readArray nums left;
  if x == (-1) then do {
    y <- newleft nums (left + 1) right;
    return y;
    }
    else do {
    return (left + 1);
    }

deletex :: IOUArray Int Int -> Int -> Int -> Int -> IO ()
deletex nums left right x = do
  if left >= right then return ()
    else do {
    y <- readArray nums left;
    if x == y then do {
      writeArray nums left (-1);
      }
    else do {
      deletex nums (left + 1) right x;
      }
    }
  
printanswer :: IOUArray Int Int -> Int -> Int -> IO ()
printanswer nums left right = do
  if left >= right then do { putStrLn ""; return (); }
    else do {
    x <- readArray nums (right - 1);
    if x /= (-1) then putStr ((show x)) else return ();
    printanswer2 nums left (right - 1);
    }

printanswer2 :: IOUArray Int Int -> Int -> Int -> IO ()
printanswer2 nums left right = do
  if left >= right then do { putStrLn ""; return (); }
    else do {
    x <- readArray nums (right - 1);
    if x /= (-1) then putStr (" " ++ (show x)) else return ();
    printanswer2 nums left (right - 1);
    }