module DLinkedList = struct
  type 'a element =
    { value : 'a;
      mutable next : int;
      mutable prev : int
    }
  type 'a t = {
    mutable first : int;
    mutable last  : int;
    mutable index : int;
    elts : 'a element array
  }

  let create n = {first = -1; last = -1; index = 0;
                  elts = Array.make n {value=0;next=0;prev=0}}
                 
  let insert_first t value =
    let new_elt = {prev = -1; next = t.first; value} in
    let i = t.index in
    begin match t.first with
      | -1 -> ()
      |  old_first -> t.elts.(old_first).prev <- i
    end;
    t.first <- i; t.elts.(i) <- new_elt; t.index <- i + 1;
    begin match t.last with
      | -1 -> t.last <- t.first
      | _ -> ()
    end

  let remove t elt =
    let {prev; next; _} = elt in
    begin match prev with
      | -1 -> t.first <- next
      | pi -> t.elts.(pi).next <- next
    end;
    begin match next with
      | -1 -> t.last <- prev
      | ni -> t.elts.(ni).prev <- prev
    end
      
  let find t v =
    let rec loop = function
      | -1 -> ()
      |  i ->
        let elt = t.elts.(i) in
        if v = elt.value then remove t elt
        else loop elt.next
    in
    loop t.first

  let remove_first t =
    begin match t.first with
      | -1 -> ()
      |  i ->
        let first = t.elts.(i) in
        begin match first.next with
          | -1 -> t.first <- -1; t.last <- -1
          | j -> t.elts.(j).prev <- -1; t.first <- j
        end
    end

  let remove_last t =
    begin match t.last with
      | -1 -> ()
      | i ->
        let last = t.elts.(i) in
        begin match last.prev with
          | -1 -> t.first <- -1; t.last <- -1
          |  j -> t.elts.(j).next <- -1; t.last <- j
        end
    end

  let print t =
    let rec loop e = match e.next with
      | -1 -> Printf.printf "%d\n" e.value
      |  i -> Printf.printf "%d " e.value; loop t.elts.(i)
    in
    loop t.elts.(t.first)
end

let () =
  let open DLinkedList in
  let (n: int) = read_int () in
  let (dll: int t) = create n in
  for i=1 to n do
    begin match read_line () with
      | "deleteFirst" -> remove_first dll
      | "deleteLast" -> remove_last dll
      | s ->
        begin match String.sub s 0 6,
                    (String.sub s 7 (String.length s - 7)
                    |> int_of_string) with
        | "insert", n -> insert_first dll n
        | "delete", n -> find dll n
        | _ -> ()
        end
    end
  done;
  print dll