open Printf
open Scanf

let n = scanf "%d\n" (fun x -> x)

let rec print_list = function
 [] -> printf ""
 |a :: [] -> printf "%d\n" a
 |b :: l -> (printf "%d " b; print_list l)

let insert l x = x :: l

let rec delete l x = 
 match l with
 [] -> []
 |a :: l' when (a = x) -> l'
 |b :: l' -> b :: delete l' x

let deleteFirst = function
 [] -> []
 |a :: l' -> l'

let rec deleteLast = function
 [] -> []
 |a :: l when (l = []) -> []
 |b :: l -> b :: deleteLast l

let () =
 let rec readcom l i =
  if i = n then l
  else
   let c = scanf "%s\n" (fun x -> x) in
   let c' = String.sub c 0 7 in
   match c' with 
   "insert " -> readcom (insert l (int_of_char c.[7])) (i+1)
  |"delete " -> readcom (delete l (int_of_char c.[7])) (i+1)
  |"deleteF" -> readcom (deleteFirst l) (i+1)
  |"deleteL" -> readcom (deleteLast l) (i+1)
  | _ -> []
 in
 print_list (readcom [] 0)