class List
  def initialize
    @head = Node.new(nil)
    @tail = Node.new(nil)
    @head.next = @tail
    @tail.prev = @head
  end

  def insert(x)
    v = Node.new(x)
    left, right = @head, @head.next
    left.next, right.prev = v, v
    v.prev, v.next = left, right
  end

  def deleteFirst
    @head.next.unlink
  end

  def deleteLast
    @tail.prev.unlink
  end

  def delete(x)
    u = @head.next
    until u == @tail
      v = u.next
      if u.value == x
        u.unlink 
        return
      end
      u = v
    end
  end

  def to_s
    a = []
    v = @head.next
    until v == @tail
      a << v.value
      v = v.next
    end
    a * " "
  end

  class Node
    def initialize(x)
      @value = x
      @next = @prev = nil
    end

    attr_accessor :value, :next, :prev

    def unlink
      left, right = @prev, @next
      left.next = right
      right.prev = left
    end
  end
end

n = gets.to_i
list = List.new
n.times do
  command, x = gets.chomp.split
  if x 
    list.send(command, x.to_i)
  else
    list.send(command)
  end
end
puts list

