n = gets.chomp.to_i
arr = Array.new
n.times do
  order = gets.split(" ")
  case order[0]
    when "insert"
      arr.unshift(order[1].to_i)
    when "delete" 
      arr.index(order[1].to_i) == nil ? (next): (queue.delete_at(queue.index(order[1].to_i)))
    when "deleteFirst"
    arr.shift
    when "deleteLast"
    arr.pop
  end
end

(arr.size).times do |num|
  print arr[num]
  num+1 == (arr.size) ? (print "\n") : (print " ")
end
