import sys

class DoublyLinkedList:
    def __init__(self, value = -1):
        self.value = value
        self.prev = self
        self.next = self

    def insert(self, value):
        newNode = DoublyLinkedList(value)
        newNode.next = self.next
        newNode.prev = self
        self.next.prev = newNode
        self.next = newNode

    def delete(self, value):
        node = self.next
        while node.value != -1:
            if node.value == value:
                node.next.prev = node.prev
                node.prev.next = node.next
                break
            node = node.next

    def deleteFirst(self):
        if self.next.value != -1:
            self.next = self.next.next
            self.next.prev = self

    def deleteLast(self):
        if self.prev.value != -1:
            self.prev = self.prev.prev
            self.prev.next = self

    def printAll(self):
        node = self.next
        while node.next.value != -1:
            print node.value,
            node = node.next
        print node.value

if __name__ == "__main__":
    dll = DoublyLinkedList()
    lines = sys.stdin.readlines()
    lines.pop(0)
    for line in lines:
        if line[0] == "i":
            dll.insert(int(line[7:]))
        elif line[6] == "F":
            dll.deleteFirst()
        elif line[6] == "L":
            dll.deleteLast()
        else:
            dll.delete(int(line[7:]))
    dll.printAll() import sys sys class DoublyLinkedList:
    def __init__(self, value = -1):
        self.value = value
        self.prev = self
        self.next = self

    def insert(self, value):
        newNode = DoublyLinkedList(value)
        newNode.next = self.next
        newNode.prev = self
        self.next.prev = newNode
        self.next = newNode

    def delete(self, value):
        node = self.next
        while node.value != -1:
            if node.value == value:
                node.next.prev = node.prev
                node.prev.next = node.next
                break
            node = node.next

    def deleteFirst(self):
        if self.next.value != -1:
            self.next = self.next.next
            self.next.prev = self

    def deleteLast(self):
        if self.prev.value != -1:
            self.prev = self.prev.prev
            self.prev.next = self

    def printAll(self):
        node = self.next
        while node.next.value != -1:
            print node.value,
            node = node.next
        print node.value DoublyLinkedList def __init__(self, value = -1):
        self.value = value
        self.prev = self
        self.next = self

     __init__ self.value = value self.value self value value self.prev = self self.prev self prev self self.next = self self.next self next self self self value = -1 value -1 def insert(self, value):
        newNode = DoublyLinkedList(value)
        newNode.next = self.next
        newNode.prev = self
        self.next.prev = newNode
        self.next = newNode

     insert newNode = DoublyLinkedList(value) newNode DoublyLinkedList(value) DoublyLinkedList value newNode.next = self.next newNode.next newNode next self.next self next newNode.prev = self newNode.prev newNode prev self self.next.prev = newNode self.next.prev self.next self next prev newNode self.next = newNode self.next self next newNode self self value value def delete(self, value):
        node = self.next
        while node.value != -1:
            if node.value == value:
                node.next.prev = node.prev
                node.prev.next = node.next
                break
            node = node.next

     delete node = self.next node self.next self next while node.value != -1:
            if node.value == value:
                node.next.prev = node.prev
                node.prev.next = node.next
                break
            node = node.next

     node.value != -1 node.value node value -1 if node.value == value:
                node.next.prev = node.prev
                node.prev.next = node.next
                break
             node.value == value node.value node value value node.next.prev = node.prev node.next.prev node.next node next prev node.prev node prev node.prev.next = node.next node.prev.next node.prev node prev next node.next node next break node = node.next node node.next node next self self value value def deleteFirst(self):
        if self.next.value != -1:
            self.next = self.next.next
            self.next.prev = self

     deleteFirst if self.next.value != -1:
            self.next = self.next.next
            self.next.prev = self

     self.next.value != -1 self.next.value self.next self next value -1 self.next = self.next.next self.next self next self.next.next self.next self next next self.next.prev = self self.next.prev self.next self next prev self self self def deleteLast(self):
        if self.prev.value != -1:
            self.prev = self.prev.prev
            self.prev.next = self

     deleteLast if self.prev.value != -1:
            self.prev = self.prev.prev
            self.prev.next = self

     self.prev.value != -1 self.prev.value self.prev self prev value -1 self.prev = self.prev.prev self.prev self prev self.prev.prev self.prev self prev prev self.prev.next = self self.prev.next self.prev self prev next self self self def printAll(self):
        node = self.next
        while node.next.value != -1:
            print node.value,
            node = node.next
        print node.value printAll node = self.next node self.next self next while node.next.value != -1:
            print node.value,
            node = node.next
         node.next.value != -1 node.next.value node.next node next value -1 print node.value node value node = node.next node node.next node next print node.value node value self self if __name__ == "__main__":
    dll = DoublyLinkedList()
    lines = sys.stdin.readlines()
    lines.pop(0)
    for line in lines:
        if line[0] == "i":
            dll.insert(int(line[7:]))
        elif line[6] == "F":
            dll.deleteFirst()
        elif line[6] == "L":
            dll.deleteLast()
        else:
            dll.delete(int(line[7:]))
    dll.printAll() __name__ == "__main__" __name__ "__main__" dll = DoublyLinkedList() dll DoublyLinkedList() DoublyLinkedList lines = sys.stdin.readlines() lines sys.stdin.readlines() sys.stdin.readlines sys.stdin sys stdin readlines lines.pop(0) lines.pop lines pop 0 for line in lines:
        if line[0] == "i":
            dll.insert(int(line[7:]))
        elif line[6] == "F":
            dll.deleteFirst()
        elif line[6] == "L":
            dll.deleteLast()
        else:
            dll.delete(int(line[7:]))
     line lines if line[0] == "i":
            dll.insert(int(line[7:]))
        elif line[6] == "F":
            dll.deleteFirst()
        elif line[6] == "L":
            dll.deleteLast()
        else:
            dll.delete(int(line[7:]))
     line[0] == "i" line[0] line 0 "i" dll.insert(int(line[7:])) dll.insert dll insert int(line[7:]) int line[7:] line 7: 7 elif line[6] == "F":
            dll.deleteFirst()
         line[6] == "F" line[6] line 6 "F" dll.deleteFirst() dll.deleteFirst dll deleteFirst elif line[6] == "L":
            dll.deleteLast()
         line[6] == "L" line[6] line 6 "L" dll.deleteLast() dll.deleteLast dll deleteLast dll.delete(int(line[7:])) dll.delete dll delete int(line[7:]) int line[7:] line 7: 7 dll.printAll() dll.printAll dll printAll dll = DoublyLinkedList() DoublyLinkedList() dll lines = sys.stdin.readlines() sys.stdin.readlines() lines class DoublyLinkedList:
    def __init__(self, value = -1):
        self.value = value
        self.prev = self
        self.next = self

    def insert(self, value):
        newNode = DoublyLinkedList(value)
        newNode.next = self.next
        newNode.prev = self
        self.next.prev = newNode
        self.next = newNode

    def delete(self, value):
        node = self.next
        while node.value != -1:
            if node.value == value:
                node.next.prev = node.prev
                node.prev.next = node.next
                break
            node = node.next

    def deleteFirst(self):
        if self.next.value != -1:
            self.next = self.next.next
            self.next.prev = self

    def deleteLast(self):
        if self.prev.value != -1:
            self.prev = self.prev.prev
            self.prev.next = self

    def printAll(self):
        node = self.next
        while node.next.value != -1:
            print node.value,
            node = node.next
        print node.value class DoublyLinkedList:
    def __init__(self, value = -1):
        self.value = value
        self.prev = self
        self.next = self

    def insert(self, value):
        newNode = DoublyLinkedList(value)
        newNode.next = self.next
        newNode.prev = self
        self.next.prev = newNode
        self.next = newNode

    def delete(self, value):
        node = self.next
        while node.value != -1:
            if node.value == value:
                node.next.prev = node.prev
                node.prev.next = node.next
                break
            node = node.next

    def deleteFirst(self):
        if self.next.value != -1:
            self.next = self.next.next
            self.next.prev = self

    def deleteLast(self):
        if self.prev.value != -1:
            self.prev = self.prev.prev
            self.prev.next = self

    def printAll(self):
        node = self.next
        while node.next.value != -1:
            print node.value,
            node = node.next
        print node.value DoublyLinkedList
import sys

class DoublyLinkedList:
    def __init__(self, value = -1):
        self.value = value
        self.prev = self
        self.next = self

    def insert(self, value):
        newNode = DoublyLinkedList(value)
        newNode.next = self.next
        newNode.prev = self
        self.next.prev = newNode
        self.next = newNode

    def delete(self, value):
        node = self.next
        while node.value != -1:
            if node.value == value:
                node.next.prev = node.prev
                node.prev.next = node.next
                break
            node = node.next

    def deleteFirst(self):
        if self.next.value != -1:
            self.next = self.next.next
            self.next.prev = self

    def deleteLast(self):
        if self.prev.value != -1:
            self.prev = self.prev.prev
            self.prev.next = self

    def printAll(self):
        node = self.next
        while node.next.value != -1:
            print node.value,
            node = node.next
        print node.value

if __name__ == "__main__":
    dll = DoublyLinkedList()
    lines = sys.stdin.readlines()
    lines.pop(0)
    for line in lines:
        if line[0] == "i":
            dll.insert(int(line[7:]))
        elif line[6] == "F":
            dll.deleteFirst()
        elif line[6] == "L":
            dll.deleteLast()
        else:
            dll.delete(int(line[7:]))
    dll.printAll()