let  () =
let link x a = x::a in

let bit_first = function
    |x::xs -> xs
    |_ -> []
in

let rec bit_last = function
    |[] -> []
    |[c] -> []
    |x::xs -> x::bit_last xs
in

let rec del x  = function
    | [] -> []
    | e::ex -> if x=e then ex else e::(del x ex)
in

let ex li lis = 
    match lis with
    |["insert";n] -> link n li
    |["delete";n] -> del n li
    |["deleteFirst"] -> bit_first li
    |["deleteLast"] -> bit_last li
    |_ -> li
in

let rec loop l n =
    if n=0 then l
    else 
        let f = (ex l) in
        let listd = Str.split (Str.regexp " ") (read_line ()) in
        let ans = f listd in
        loop ans (n-1)
in

let rec pnt = function
    | [] -> print_newline ()
    | x::xs -> print_string x;print_string " ";pnt xs
in

let num = Scanf.scanf "%d" (fun x -> x) in

let ballel = loop [] num in

pnt ballel