import scala.io.StdIn.{readInt, readLine}
case class Node[T](data: Option[T], var prev: Node[T], var next: Node[T])
case class DoublyLinkedList[T]() {
    val n = new Node[T](None, null, null)
    def isEmpty(): Boolean = if (n.prev == null && n.next == null) true else false
    def insert(e: T): Unit = {
        if (isEmpty) {
            val newNode = new Node(Option(e), n, n)
            n.next = newNode
            n.prev = newNode
        } else {
            val newNode = new Node(Option(e), n, n.next)
            n.next.prev = newNode
            n.next = newNode
        }
    }
    def delete(e: T): Unit = {
        def find(node: Node[T]): Node[T] = node.next match {
            case null => null
            case a if a.data.isEmpty => null
            case a if a.data.get == e => a 
            case a => find(a)
        }
        val target = find(n)
        if (!isEmpty && target != null) {
            val target = find(n)
            val targetNext = target.next
            val targetPrev = target.prev
            if (targetNext eq targetPrev) {
                n.prev = null
                n.next = null
            } else {
                targetPrev.next = targetNext
                targetNext.prev = targetPrev
            }
        }
    }
    def deleteFirst(): Unit = {
        if (!isEmpty) {
            val targetNext = n.next.next
            if (n eq targetNext) {
                n.prev = null
                n.next = null
            } else {
                n.next = targetNext
                targetNext.prev = n
            }
        }
    }
    def deleteLast(): Unit = {
        if (!isEmpty) {
            val targetPrev = n.prev.prev
            if (n eq targetPrev) {
                n.prev = null
                n.next = null
            } else {
                n.prev = targetPrev
                targetPrev.next = n
            }
        }
    }
    def printList(): Unit = {
        if (isEmpty) {
            println()
        } else {
            val sb = new StringBuilder
            def go(node: Node[T]): Unit = node.next match {
                case a if a.data.isEmpty => Unit
                case a if a.next.data.isEmpty => sb.append(a.data.get); go(a)
                case a => sb.append(a.data.get).append(" "); go(a)
            }
            go(n)
            println(sb)
        }
    }
}
object Main {
    def main(args: Array[String]): Unit = {
        val list = DoublyLinkedList[String]()
        for (i <- (1 to readInt)) {
            readLine.split(" ") match {
                case Array(command, value) => {
                    if (command == "insert") list.insert(value)
                    if (command == "delete") list.delete(value)
                }
                case Array(command) =>  {
                    if (command == "deleteFirst") list.deleteFirst()
                    if (command == "deleteLast") list.deleteLast()
                }
            }
        }
        list.printList()
    }
}
