fun main(args: Array<String>) {
    val sc = System.`in`.bufferedReader()
    val n = Integer.parseInt(sc.readLine())
    val list = LinkedList()

    repeat(n) {

        val (command, key) = run {
            val s = sc.readLine().split(' ')
            if (s.size == 1) {
                Pair(s[0], -1)
            } else {
                Pair(s[0], Integer.parseInt(s[1]))
            }
        }

        when (command) {
            "insert" -> list.insert(key)
            "delete" -> list.delete(key)
            "deleteFirst" -> list.deleteFirst()
            "deleteLast" -> list.deleteLast()
        }
    }

    println(list)
}

private class LinkedList {

    private val nil: Node = Node(null)

    fun insert(key: Int) {
        val x = Node(key)

        x.next = nil.next
        nil.next?.prev = x
        nil.next = x
        x.prev = nil
    }

    private fun deleteNode(node: Node?) {
        if (node == nil) {
            return
        }
        node?.prev?.next = node?.next
        node?.next?.prev = node?.prev
    }

    fun delete(key: Int) {
        var cur = nil.next
        while (cur != nil && cur?.key != key) {
            cur = cur?.next
        }
        deleteNode(cur)
    }

    fun deleteFirst() {
        deleteNode(nil.next)
    }

    fun deleteLast() {
        deleteNode(nil.prev)
    }

    override fun toString(): String {
        val sb = StringBuilder()
        var cur = nil.next
        while (cur != nil) {
            sb.append(cur?.key).append(' ')
            cur = cur?.next
        }
        sb.deleteCharAt(sb.lastIndex)
        return sb.toString()
    }

}

private class Node(val key: Int?) {

    var next: Node? = this

    var prev: Node? = this

}

