import sys

class Node:
    """
    key: Value of the node
    next: Pointer to the next node
    prev: Pointer to the previous node
    """

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


class DoublyLinkedList:
    def __init__(self):
        """
        next always point to the very first node in a list
        prev always point to the last node in a list
        """
        self.next = None
        self.prev = None

    def insert(self, key):
        """
        :param key: key to insert into a list (inserted to the first place in the list)
        :return: None
        """
        newNode = Node(key)
        # First node ever added to the list
        if self.next is None:
            newNode.next = None
            newNode.prev = self
            self.next = newNode
            self.prev = newNode
        # Second nodes and forth
        else:
            newNode.next = self.next
            newNode.prev = self
            self.next.prev = newNode
            self.next = newNode

    def listSearch(self, key):
        """
        :param key: key of a note to search for
        :return: Node (the first Node from the beginning of a list)
        """
        cur = self.next
        while cur is not None and cur.key != key:
            cur = cur.next
        return cur

    def deleteNode(self, node):
        """
        :param node: Node to delete
        :return: None
        """
        if node is None:
            return
        # If the node is the last node
        elif node.next is None:
            node.prev.next = None
            self.prev = node.prev
        # If the node is not the last node
        else:
            node.prev.next = node.next
            node.next.prev = node.prev

    def delete(self, key):
        """
        Delete the first node that has the key.
        :param key: key that the node to be deleted has
        :return: None
        """
        self.deleteNode(self.listSearch(key))

    def deleteFirst(self):
        """
        Delete the first node in a list
        :return: None
        """
        cur = self.next
        self.deleteNode(cur)

    def deleteLast(self):
        """
        Delete the last node in a list
        :return: None
        """
        cur = self.prev
        self.deleteNode(cur)

    def showKeys(self):
        """
        Print keys of nodes in a list divided by a space
        :return: None
        """
        cur = self.next
        keys = []
        while cur is not None:
            keys.append(cur.key)
            cur = cur.next
        keys = map(str, keys)
        print(' '.join(keys))

n = int(input())
d = DoublyLinkedList()

# input() seems to be too slow for this (result in TLE for large inputs)
for i in sys.stdin:
    if 'insert' in i:
        x = i[7:-1]
        d.insert(x)
    elif 'deleteFirst' in i:
        d.deleteFirst()
    elif 'deleteLast' in i:
        d.deleteLast()
    elif 'delete' in i:
        x = i[7:-1]
        d.delete(x)
    else:
        pass

d.showKeys() import sys sys class Node:
    """
    key: Value of the node
    next: Pointer to the next node
    prev: Pointer to the previous node
    """

    def __init__(self, key):
        self.key = key
        self.next = None
        self.prev = None Node """
    key: Value of the node
    next: Pointer to the next node
    prev: Pointer to the previous node
    """ def __init__(self, key):
        self.key = key
        self.next = None
        self.prev = None __init__ self.key = key self.key self key key self.next = None self.next self next None self.prev = None self.prev self prev None self self key key class DoublyLinkedList:
    def __init__(self):
        """
        next always point to the very first node in a list
        prev always point to the last node in a list
        """
        self.next = None
        self.prev = None

    def insert(self, key):
        """
        :param key: key to insert into a list (inserted to the first place in the list)
        :return: None
        """
        newNode = Node(key)
        # First node ever added to the list
        if self.next is None:
            newNode.next = None
            newNode.prev = self
            self.next = newNode
            self.prev = newNode
        # Second nodes and forth
        else:
            newNode.next = self.next
            newNode.prev = self
            self.next.prev = newNode
            self.next = newNode

    def listSearch(self, key):
        """
        :param key: key of a note to search for
        :return: Node (the first Node from the beginning of a list)
        """
        cur = self.next
        while cur is not None and cur.key != key:
            cur = cur.next
        return cur

    def deleteNode(self, node):
        """
        :param node: Node to delete
        :return: None
        """
        if node is None:
            return
        # If the node is the last node
        elif node.next is None:
            node.prev.next = None
            self.prev = node.prev
        # If the node is not the last node
        else:
            node.prev.next = node.next
            node.next.prev = node.prev

    def delete(self, key):
        """
        Delete the first node that has the key.
        :param key: key that the node to be deleted has
        :return: None
        """
        self.deleteNode(self.listSearch(key))

    def deleteFirst(self):
        """
        Delete the first node in a list
        :return: None
        """
        cur = self.next
        self.deleteNode(cur)

    def deleteLast(self):
        """
        Delete the last node in a list
        :return: None
        """
        cur = self.prev
        self.deleteNode(cur)

    def showKeys(self):
        """
        Print keys of nodes in a list divided by a space
        :return: None
        """
        cur = self.next
        keys = []
        while cur is not None:
            keys.append(cur.key)
            cur = cur.next
        keys = map(str, keys)
        print(' '.join(keys)) DoublyLinkedList def __init__(self):
        """
        next always point to the very first node in a list
        prev always point to the last node in a list
        """
        self.next = None
        self.prev = None

     __init__ """
        next always point to the very first node in a list
        prev always point to the last node in a list
        """ self.next = None self.next self next None self.prev = None self.prev self prev None self self def insert(self, key):
        """
        :param key: key to insert into a list (inserted to the first place in the list)
        :return: None
        """
        newNode = Node(key)
        # First node ever added to the list
        if self.next is None:
            newNode.next = None
            newNode.prev = self
            self.next = newNode
            self.prev = newNode
        # Second nodes and forth
        else:
            newNode.next = self.next
            newNode.prev = self
            self.next.prev = newNode
            self.next = newNode

     insert """
        :param key: key to insert into a list (inserted to the first place in the list)
        :return: None
        """ newNode = Node(key) newNode Node(key) Node key if self.next is None:
            newNode.next = None
            newNode.prev = self
            self.next = newNode
            self.prev = newNode
        # Second nodes and forth
        else:
            newNode.next = self.next
            newNode.prev = self
            self.next.prev = newNode
            self.next = newNode

     self.next is None self.next self next None newNode.next = None newNode.next newNode next None newNode.prev = self newNode.prev newNode prev self self.next = newNode self.next self next newNode self.prev = newNode self.prev self prev newNode 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 key key def listSearch(self, key):
        """
        :param key: key of a note to search for
        :return: Node (the first Node from the beginning of a list)
        """
        cur = self.next
        while cur is not None and cur.key != key:
            cur = cur.next
        return cur

     listSearch """
        :param key: key of a note to search for
        :return: Node (the first Node from the beginning of a list)
        """ cur = self.next cur self.next self next while cur is not None and cur.key != key:
            cur = cur.next
         cur is not None and cur.key != key cur is not None cur None cur.key != key cur.key cur key key cur = cur.next cur cur.next cur next return cur cur self self key key def deleteNode(self, node):
        """
        :param node: Node to delete
        :return: None
        """
        if node is None:
            return
        # If the node is the last node
        elif node.next is None:
            node.prev.next = None
            self.prev = node.prev
        # If the node is not the last node
        else:
            node.prev.next = node.next
            node.next.prev = node.prev

     deleteNode """
        :param node: Node to delete
        :return: None
        """ if node is None:
            return
        # If the node is the last node
        elif node.next is None:
            node.prev.next = None
            self.prev = node.prev
        # If the node is not the last node
        else:
            node.prev.next = node.next
            node.next.prev = node.prev

     node is None node None return elif node.next is None:
            node.prev.next = None
            self.prev = node.prev
        # If the node is not the last node
         node.next is None node.next node next None node.prev.next = None node.prev.next node.prev node prev next None self.prev = node.prev self.prev self prev node.prev node prev 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 delete(self, key):
        """
        Delete the first node that has the key.
        :param key: key that the node to be deleted has
        :return: None
        """
        self.deleteNode(self.listSearch(key))

     delete """
        Delete the first node that has the key.
        :param key: key that the node to be deleted has
        :return: None
        """ self.deleteNode(self.listSearch(key)) self.deleteNode self deleteNode self.listSearch(key) self.listSearch self listSearch key self self key key def deleteFirst(self):
        """
        Delete the first node in a list
        :return: None
        """
        cur = self.next
        self.deleteNode(cur)

     deleteFirst """
        Delete the first node in a list
        :return: None
        """ cur = self.next cur self.next self next self.deleteNode(cur) self.deleteNode self deleteNode cur self self def deleteLast(self):
        """
        Delete the last node in a list
        :return: None
        """
        cur = self.prev
        self.deleteNode(cur)

     deleteLast """
        Delete the last node in a list
        :return: None
        """ cur = self.prev cur self.prev self prev self.deleteNode(cur) self.deleteNode self deleteNode cur self self def showKeys(self):
        """
        Print keys of nodes in a list divided by a space
        :return: None
        """
        cur = self.next
        keys = []
        while cur is not None:
            keys.append(cur.key)
            cur = cur.next
        keys = map(str, keys)
        print(' '.join(keys)) showKeys """
        Print keys of nodes in a list divided by a space
        :return: None
        """ cur = self.next cur self.next self next keys = [] keys [] while cur is not None:
            keys.append(cur.key)
            cur = cur.next
         cur is not None cur None keys.append(cur.key) keys.append keys append cur.key cur key cur = cur.next cur cur.next cur next keys = map(str, keys) keys map(str, keys) map str keys print(' '.join(keys)) print ' '.join(keys) ' '.join ' ' join keys self self n = int(input()) n int(input()) int input() input d = DoublyLinkedList() d DoublyLinkedList() DoublyLinkedList for i in sys.stdin:
    if 'insert' in i:
        x = i[7:-1]
        d.insert(x)
    elif 'deleteFirst' in i:
        d.deleteFirst()
    elif 'deleteLast' in i:
        d.deleteLast()
    elif 'delete' in i:
        x = i[7:-1]
        d.delete(x)
    else:
        pass i sys.stdin sys stdin if 'insert' in i:
        x = i[7:-1]
        d.insert(x)
    elif 'deleteFirst' in i:
        d.deleteFirst()
    elif 'deleteLast' in i:
        d.deleteLast()
    elif 'delete' in i:
        x = i[7:-1]
        d.delete(x)
    else:
        pass 'insert' in i 'insert' i x = i[7:-1] x i[7:-1] i 7:-1 7 -1 d.insert(x) d.insert d insert x elif 'deleteFirst' in i:
        d.deleteFirst()
     'deleteFirst' in i 'deleteFirst' i d.deleteFirst() d.deleteFirst d deleteFirst elif 'deleteLast' in i:
        d.deleteLast()
     'deleteLast' in i 'deleteLast' i d.deleteLast() d.deleteLast d deleteLast elif 'delete' in i:
        x = i[7:-1]
        d.delete(x)
     'delete' in i 'delete' i x = i[7:-1] x i[7:-1] i 7:-1 7 -1 d.delete(x) d.delete d delete x d.showKeys() d.showKeys d showKeys x = i[7:-1] i[7:-1] x class DoublyLinkedList:
    def __init__(self):
        """
        next always point to the very first node in a list
        prev always point to the last node in a list
        """
        self.next = None
        self.prev = None

    def insert(self, key):
        """
        :param key: key to insert into a list (inserted to the first place in the list)
        :return: None
        """
        newNode = Node(key)
        # First node ever added to the list
        if self.next is None:
            newNode.next = None
            newNode.prev = self
            self.next = newNode
            self.prev = newNode
        # Second nodes and forth
        else:
            newNode.next = self.next
            newNode.prev = self
            self.next.prev = newNode
            self.next = newNode

    def listSearch(self, key):
        """
        :param key: key of a note to search for
        :return: Node (the first Node from the beginning of a list)
        """
        cur = self.next
        while cur is not None and cur.key != key:
            cur = cur.next
        return cur

    def deleteNode(self, node):
        """
        :param node: Node to delete
        :return: None
        """
        if node is None:
            return
        # If the node is the last node
        elif node.next is None:
            node.prev.next = None
            self.prev = node.prev
        # If the node is not the last node
        else:
            node.prev.next = node.next
            node.next.prev = node.prev

    def delete(self, key):
        """
        Delete the first node that has the key.
        :param key: key that the node to be deleted has
        :return: None
        """
        self.deleteNode(self.listSearch(key))

    def deleteFirst(self):
        """
        Delete the first node in a list
        :return: None
        """
        cur = self.next
        self.deleteNode(cur)

    def deleteLast(self):
        """
        Delete the last node in a list
        :return: None
        """
        cur = self.prev
        self.deleteNode(cur)

    def showKeys(self):
        """
        Print keys of nodes in a list divided by a space
        :return: None
        """
        cur = self.next
        keys = []
        while cur is not None:
            keys.append(cur.key)
            cur = cur.next
        keys = map(str, keys)
        print(' '.join(keys)) class DoublyLinkedList:
    def __init__(self):
        """
        next always point to the very first node in a list
        prev always point to the last node in a list
        """
        self.next = None
        self.prev = None

    def insert(self, key):
        """
        :param key: key to insert into a list (inserted to the first place in the list)
        :return: None
        """
        newNode = Node(key)
        # First node ever added to the list
        if self.next is None:
            newNode.next = None
            newNode.prev = self
            self.next = newNode
            self.prev = newNode
        # Second nodes and forth
        else:
            newNode.next = self.next
            newNode.prev = self
            self.next.prev = newNode
            self.next = newNode

    def listSearch(self, key):
        """
        :param key: key of a note to search for
        :return: Node (the first Node from the beginning of a list)
        """
        cur = self.next
        while cur is not None and cur.key != key:
            cur = cur.next
        return cur

    def deleteNode(self, node):
        """
        :param node: Node to delete
        :return: None
        """
        if node is None:
            return
        # If the node is the last node
        elif node.next is None:
            node.prev.next = None
            self.prev = node.prev
        # If the node is not the last node
        else:
            node.prev.next = node.next
            node.next.prev = node.prev

    def delete(self, key):
        """
        Delete the first node that has the key.
        :param key: key that the node to be deleted has
        :return: None
        """
        self.deleteNode(self.listSearch(key))

    def deleteFirst(self):
        """
        Delete the first node in a list
        :return: None
        """
        cur = self.next
        self.deleteNode(cur)

    def deleteLast(self):
        """
        Delete the last node in a list
        :return: None
        """
        cur = self.prev
        self.deleteNode(cur)

    def showKeys(self):
        """
        Print keys of nodes in a list divided by a space
        :return: None
        """
        cur = self.next
        keys = []
        while cur is not None:
            keys.append(cur.key)
            cur = cur.next
        keys = map(str, keys)
        print(' '.join(keys)) DoublyLinkedList n = int(input()) int(input()) n x = i[7:-1] i[7:-1] x class Node:
    """
    key: Value of the node
    next: Pointer to the next node
    prev: Pointer to the previous node
    """

    def __init__(self, key):
        self.key = key
        self.next = None
        self.prev = None class Node:
    """
    key: Value of the node
    next: Pointer to the next node
    prev: Pointer to the previous node
    """

    def __init__(self, key):
        self.key = key
        self.next = None
        self.prev = None Node d = DoublyLinkedList() DoublyLinkedList() d
import sys

class Node:
    """
    key: Value of the node
    next: Pointer to the next node
    prev: Pointer to the previous node
    """

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


class DoublyLinkedList:
    def __init__(self):
        """
        next always point to the very first node in a list
        prev always point to the last node in a list
        """
        self.next = None
        self.prev = None

    def insert(self, key):
        """
        :param key: key to insert into a list (inserted to the first place in the list)
        :return: None
        """
        newNode = Node(key)
        # First node ever added to the list
        if self.next is None:
            newNode.next = None
            newNode.prev = self
            self.next = newNode
            self.prev = newNode
        # Second nodes and forth
        else:
            newNode.next = self.next
            newNode.prev = self
            self.next.prev = newNode
            self.next = newNode

    def listSearch(self, key):
        """
        :param key: key of a note to search for
        :return: Node (the first Node from the beginning of a list)
        """
        cur = self.next
        while cur is not None and cur.key != key:
            cur = cur.next
        return cur

    def deleteNode(self, node):
        """
        :param node: Node to delete
        :return: None
        """
        if node is None:
            return
        # If the node is the last node
        elif node.next is None:
            node.prev.next = None
            self.prev = node.prev
        # If the node is not the last node
        else:
            node.prev.next = node.next
            node.next.prev = node.prev

    def delete(self, key):
        """
        Delete the first node that has the key.
        :param key: key that the node to be deleted has
        :return: None
        """
        self.deleteNode(self.listSearch(key))

    def deleteFirst(self):
        """
        Delete the first node in a list
        :return: None
        """
        cur = self.next
        self.deleteNode(cur)

    def deleteLast(self):
        """
        Delete the last node in a list
        :return: None
        """
        cur = self.prev
        self.deleteNode(cur)

    def showKeys(self):
        """
        Print keys of nodes in a list divided by a space
        :return: None
        """
        cur = self.next
        keys = []
        while cur is not None:
            keys.append(cur.key)
            cur = cur.next
        keys = map(str, keys)
        print(' '.join(keys))

n = int(input())
d = DoublyLinkedList()

# input() seems to be too slow for this (result in TLE for large inputs)
for i in sys.stdin:
    if 'insert' in i:
        x = i[7:-1]
        d.insert(x)
    elif 'deleteFirst' in i:
        d.deleteFirst()
    elif 'deleteLast' in i:
        d.deleteLast()
    elif 'delete' in i:
        x = i[7:-1]
        d.delete(x)
    else:
        pass

d.showKeys()
