import sys


class Node():
    def __init__(self,  key=None, prev=None, next=None):
        self.key = key
        self.prev = prev
        self.next = next


class DoublyLinkedList():
    def __init__(self):
        self.head = Node()
        self.head.next = self.head
        self.head.prev = self.head

    def insert(self, x):
        node = Node(key=x, prev=self.head, next=self.head.next)
        self.head.next.prev = node
        self.head.next = node

    def search(self, x):
        node = self.head.next
        while node is not self.head and node.key != x:
            node = node.next
        return node

    def delete_key(self, x):
        node = self.search(x)
        self._delete(node)

    def _delete(self, node):
        if node is self.head:
            return None
        node.prev.next = node.next
        node.next.prev = node.prev

    def deleteFirst(self):
        self._delete(self.head.next)

    def deleteLast(self):
        self._delete(self.head.prev)

    def getKeys(self):
        node = self.head.next
        keys = []
        while node is not self.head:
            keys.append(node.key)
            node = node.next
        return " ".join(keys)


L = DoublyLinkedList()
n = int(input())
for i in sys.stdin:
    if 'insert' in i:
        x = i[7:-1]
        L.insert(x)
    elif 'deleteFirst' in i:
        L.deleteFirst()
    elif 'deleteLast' in i:
        L.deleteLast()
    elif 'delete' in i:
        x = i[7:-1]
        L.delete_key(x)
    else:
        pass
print(L.getKeys())
 import sys sys class Node():
    def __init__(self,  key=None, prev=None, next=None):
        self.key = key
        self.prev = prev
        self.next = next Node def __init__(self,  key=None, prev=None, next=None):
        self.key = key
        self.prev = prev
        self.next = next __init__ self.key = key self.key self key key self.prev = prev self.prev self prev prev self.next = next self.next self next next self self key=None key None prev=None prev None next=None next None class DoublyLinkedList():
    def __init__(self):
        self.head = Node()
        self.head.next = self.head
        self.head.prev = self.head

    def insert(self, x):
        node = Node(key=x, prev=self.head, next=self.head.next)
        self.head.next.prev = node
        self.head.next = node

    def search(self, x):
        node = self.head.next
        while node is not self.head and node.key != x:
            node = node.next
        return node

    def delete_key(self, x):
        node = self.search(x)
        self._delete(node)

    def _delete(self, node):
        if node is self.head:
            return None
        node.prev.next = node.next
        node.next.prev = node.prev

    def deleteFirst(self):
        self._delete(self.head.next)

    def deleteLast(self):
        self._delete(self.head.prev)

    def getKeys(self):
        node = self.head.next
        keys = []
        while node is not self.head:
            keys.append(node.key)
            node = node.next
        return " ".join(keys) DoublyLinkedList def __init__(self):
        self.head = Node()
        self.head.next = self.head
        self.head.prev = self.head

     __init__ self.head = Node() self.head self head Node() Node self.head.next = self.head self.head.next self.head self head next self.head self head self.head.prev = self.head self.head.prev self.head self head prev self.head self head self self def insert(self, x):
        node = Node(key=x, prev=self.head, next=self.head.next)
        self.head.next.prev = node
        self.head.next = node

     insert node = Node(key=x, prev=self.head, next=self.head.next) node Node(key=x, prev=self.head, next=self.head.next) Node key=x key x prev=self.head prev self.head self head next=self.head.next next self.head.next self.head self head next self.head.next.prev = node self.head.next.prev self.head.next self.head self head next prev node self.head.next = node self.head.next self.head self head next node self self x x def search(self, x):
        node = self.head.next
        while node is not self.head and node.key != x:
            node = node.next
        return node

     search node = self.head.next node self.head.next self.head self head next while node is not self.head and node.key != x:
            node = node.next
         node is not self.head and node.key != x node is not self.head node self.head self head node.key != x node.key node key x node = node.next node node.next node next return node node self self x x def delete_key(self, x):
        node = self.search(x)
        self._delete(node)

     delete_key node = self.search(x) node self.search(x) self.search self search x self._delete(node) self._delete self _delete node self self x x def _delete(self, node):
        if node is self.head:
            return None
        node.prev.next = node.next
        node.next.prev = node.prev

     _delete if node is self.head:
            return None
         node is self.head node self.head self head return None None node.prev.next = node.next node.prev.next node.prev node prev next node.next node next node.next.prev = node.prev node.next.prev node.next node next prev node.prev node prev self self node node def deleteFirst(self):
        self._delete(self.head.next)

     deleteFirst self._delete(self.head.next) self._delete self _delete self.head.next self.head self head next self self def deleteLast(self):
        self._delete(self.head.prev)

     deleteLast self._delete(self.head.prev) self._delete self _delete self.head.prev self.head self head prev self self def getKeys(self):
        node = self.head.next
        keys = []
        while node is not self.head:
            keys.append(node.key)
            node = node.next
        return " ".join(keys) getKeys node = self.head.next node self.head.next self.head self head next keys = [] keys [] while node is not self.head:
            keys.append(node.key)
            node = node.next
         node is not self.head node self.head self head keys.append(node.key) keys.append keys append node.key node key node = node.next node node.next node next return " ".join(keys) " ".join(keys) " ".join " " join keys self self L = DoublyLinkedList() L DoublyLinkedList() DoublyLinkedList n = int(input()) n int(input()) int input() input for i in sys.stdin:
    if 'insert' in i:
        x = i[7:-1]
        L.insert(x)
    elif 'deleteFirst' in i:
        L.deleteFirst()
    elif 'deleteLast' in i:
        L.deleteLast()
    elif 'delete' in i:
        x = i[7:-1]
        L.delete_key(x)
    else:
        pass i sys.stdin sys stdin if 'insert' in i:
        x = i[7:-1]
        L.insert(x)
    elif 'deleteFirst' in i:
        L.deleteFirst()
    elif 'deleteLast' in i:
        L.deleteLast()
    elif 'delete' in i:
        x = i[7:-1]
        L.delete_key(x)
    else:
        pass 'insert' in i 'insert' i x = i[7:-1] x i[7:-1] i 7:-1 7 -1 L.insert(x) L.insert L insert x elif 'deleteFirst' in i:
        L.deleteFirst()
     'deleteFirst' in i 'deleteFirst' i L.deleteFirst() L.deleteFirst L deleteFirst elif 'deleteLast' in i:
        L.deleteLast()
     'deleteLast' in i 'deleteLast' i L.deleteLast() L.deleteLast L deleteLast elif 'delete' in i:
        x = i[7:-1]
        L.delete_key(x)
     'delete' in i 'delete' i x = i[7:-1] x i[7:-1] i 7:-1 7 -1 L.delete_key(x) L.delete_key L delete_key x print(L.getKeys()) print L.getKeys() L.getKeys L getKeys x = i[7:-1] i[7:-1] x class Node():
    def __init__(self,  key=None, prev=None, next=None):
        self.key = key
        self.prev = prev
        self.next = next class Node():
    def __init__(self,  key=None, prev=None, next=None):
        self.key = key
        self.prev = prev
        self.next = next Node x = i[7:-1] i[7:-1] x n = int(input()) int(input()) n class DoublyLinkedList():
    def __init__(self):
        self.head = Node()
        self.head.next = self.head
        self.head.prev = self.head

    def insert(self, x):
        node = Node(key=x, prev=self.head, next=self.head.next)
        self.head.next.prev = node
        self.head.next = node

    def search(self, x):
        node = self.head.next
        while node is not self.head and node.key != x:
            node = node.next
        return node

    def delete_key(self, x):
        node = self.search(x)
        self._delete(node)

    def _delete(self, node):
        if node is self.head:
            return None
        node.prev.next = node.next
        node.next.prev = node.prev

    def deleteFirst(self):
        self._delete(self.head.next)

    def deleteLast(self):
        self._delete(self.head.prev)

    def getKeys(self):
        node = self.head.next
        keys = []
        while node is not self.head:
            keys.append(node.key)
            node = node.next
        return " ".join(keys) class DoublyLinkedList():
    def __init__(self):
        self.head = Node()
        self.head.next = self.head
        self.head.prev = self.head

    def insert(self, x):
        node = Node(key=x, prev=self.head, next=self.head.next)
        self.head.next.prev = node
        self.head.next = node

    def search(self, x):
        node = self.head.next
        while node is not self.head and node.key != x:
            node = node.next
        return node

    def delete_key(self, x):
        node = self.search(x)
        self._delete(node)

    def _delete(self, node):
        if node is self.head:
            return None
        node.prev.next = node.next
        node.next.prev = node.prev

    def deleteFirst(self):
        self._delete(self.head.next)

    def deleteLast(self):
        self._delete(self.head.prev)

    def getKeys(self):
        node = self.head.next
        keys = []
        while node is not self.head:
            keys.append(node.key)
            node = node.next
        return " ".join(keys) DoublyLinkedList L = DoublyLinkedList() DoublyLinkedList() L
import sys


class Node():
    def __init__(self,  key=None, prev=None, next=None):
        self.key = key
        self.prev = prev
        self.next = next


class DoublyLinkedList():
    def __init__(self):
        self.head = Node()
        self.head.next = self.head
        self.head.prev = self.head

    def insert(self, x):
        node = Node(key=x, prev=self.head, next=self.head.next)
        self.head.next.prev = node
        self.head.next = node

    def search(self, x):
        node = self.head.next
        while node is not self.head and node.key != x:
            node = node.next
        return node

    def delete_key(self, x):
        node = self.search(x)
        self._delete(node)

    def _delete(self, node):
        if node is self.head:
            return None
        node.prev.next = node.next
        node.next.prev = node.prev

    def deleteFirst(self):
        self._delete(self.head.next)

    def deleteLast(self):
        self._delete(self.head.prev)

    def getKeys(self):
        node = self.head.next
        keys = []
        while node is not self.head:
            keys.append(node.key)
            node = node.next
        return " ".join(keys)


L = DoublyLinkedList()
n = int(input())
for i in sys.stdin:
    if 'insert' in i:
        x = i[7:-1]
        L.insert(x)
    elif 'deleteFirst' in i:
        L.deleteFirst()
    elif 'deleteLast' in i:
        L.deleteLast()
    elif 'delete' in i:
        x = i[7:-1]
        L.delete_key(x)
    else:
        pass
print(L.getKeys())

