object Main extends App {
  class Node(val key: Int, var prev: Node, var next: Node) {
    def insert(key: Int): Unit = {
      val n = new Node(key, this, this.next)
      this.next.prev = n
      this.next = n
    }

    def listSearch(key: Int): Node =
      Stream
        .iterate(this.next)(_.next)
        .takeWhile(_.key != -1)
        .find(_.key == key)
        .getOrElse(null)

    def deleteNode(n: Node): Unit =
      if (n != null) {
        n.prev.next = n.next
        n.next.prev = n.prev
      }

    def deleteFirst(): Unit    = deleteNode(this.next)
    def deleteLast(): Unit     = deleteNode(this.prev)
    def delete(key: Int): Unit = deleteNode(listSearch(key))

    def show: String =
      Stream
        .iterate(this.next)(_.next)
        .takeWhile(_.key != -1)
        .map(_.key)
        .mkString(" ")

    def action(line: String): Unit = line match {
      case "deleteFirst"                  => this.deleteFirst()
      case "deleteLast"                   => this.deleteLast()
      case _ if line.startsWith("insert") => this.insert(line.replaceFirst("insert ", "").toInt)
      case _                              => this.delete(line.replaceFirst("delete ", "").toInt)
    }
  }

  def init(): Node = {
    val n: Node = new Node(-1, null, null)
    n.next = n
    n.prev = n
    n
  }

  val a = init()

  (1 to readInt)
    .foreach(_ => a.action(readLine))

  println(a.show)
}

