class DoublyLinkedList
  def initialize
    @ctl = Node.new
  end
  
  def solve
    n = gets.chomp.to_i

    n.times do
      case(cmd = gets.chomp)
      when "deleteFirst"
        deleteFirst
      when "deleteLast"
        deleteLast
      when /insert/
        insert(cmd.split(/ /)[1].to_i)
      else
        delete(cmd.split(/ /)[1].to_i)
      end
    end
    return show
  end

  def show
    s = []
    pt = @ctl.next
    while(pt != @ctl)
      s << pt.value
      pt = pt.next
    end
    return s.join(" ")
  end
  
  def insert(x)
    nd = Node.new(x)
    
    @ctl.next.prev = nd
    nd.next = @ctl.next
    @ctl.next = nd
    nd.prev = @ctl
  end
  
  def delete(x)
    pt = @ctl.next
    while(pt != @ctl)
      if (x == pt.value)
        deleteNode(pt)
        break
      else
        pt = pt.next
      end
    end
  end

  def deleteFirst
    deleteNode(@ctl.next)
  end

  def deleteLast
    deleteNode(@ctl.prev)
  end

  def deleteNode(n)
    n.prev.next = n.next
    n.next.prev = n.prev
    n.next = n
    n.prev = n
  end
end


class Node
  attr_accessor  :next, :prev, :value
  
  def initialize(x = nil)
    @next = self
    @prev = self
    @value = x
  end
end

if $0 == __FILE__
  puts DoublyLinkedList.new.solve
end