import sys

input = sys.stdin.readline


class DoublyLinkedNode(object):
    def __init__(self, front, data, back):
        self.front = front
        self.data = data
        self.back = back


class DoublyLinkedList(object):
    def __init__(self):
        self.first_node = None
        self.last_node = None

    def insert(self, data):
        if self.first_node is None:
            self.first_node = DoublyLinkedNode(None, data, None)
            self.last_node = self.first_node
        else:
            second_node = self.first_node
            self.first_node = DoublyLinkedNode(None, data, second_node)
            second_node.front = self.first_node

    def delete(self, data):
        node = self.first_node
        while node:
            if node.data == data:
                if node == self.first_node:
                    self.delete_first()
                    break
                elif node == self.last_node:
                    self.delete_last()
                    break
                else:
                    node.front.back = node.back
                    node.back.front = node.front
                    break
            else:
                node = node.back

    def delete_first(self):
        if self.first_node.back is None:
            self.__init__()
        else:
            self.first_node = self.first_node.back
            self.first_node.front = None

    def delete_last(self):
        if self.last_node.front is None:
            self.__init__()
        else:
            self.last_node = self.last_node.front
            self.last_node.back = None

    def show_all(self):
        data_list = []
        node = self.first_node
        while node:
            data_list.append(node.data)
            node = node.back
        print(" ".join(map(str, data_list)))


def main():
    n = int(input())
    link = DoublyLinkedList()
    for _ in range(n):
        command = input().rstrip()
        if command == "deleteFirst":
            link.delete_first()
        elif command == "deleteLast":
            link.delete_last()
        else:
            command = command.split()
            command, data = command[0], int(command[1])
            if command == "insert":
                link.insert(data)
            elif command == "delete":
                link.delete(data)
            else:
                raise ValueError
    link.show_all()


if __name__ == "__main__":
    main()
 import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline class DoublyLinkedNode(object):
    def __init__(self, front, data, back):
        self.front = front
        self.data = data
        self.back = back DoublyLinkedNode def __init__(self, front, data, back):
        self.front = front
        self.data = data
        self.back = back __init__ self.front = front self.front self front front self.data = data self.data self data data self.back = back self.back self back back self self front front data data back back object class DoublyLinkedList(object):
    def __init__(self):
        self.first_node = None
        self.last_node = None

    def insert(self, data):
        if self.first_node is None:
            self.first_node = DoublyLinkedNode(None, data, None)
            self.last_node = self.first_node
        else:
            second_node = self.first_node
            self.first_node = DoublyLinkedNode(None, data, second_node)
            second_node.front = self.first_node

    def delete(self, data):
        node = self.first_node
        while node:
            if node.data == data:
                if node == self.first_node:
                    self.delete_first()
                    break
                elif node == self.last_node:
                    self.delete_last()
                    break
                else:
                    node.front.back = node.back
                    node.back.front = node.front
                    break
            else:
                node = node.back

    def delete_first(self):
        if self.first_node.back is None:
            self.__init__()
        else:
            self.first_node = self.first_node.back
            self.first_node.front = None

    def delete_last(self):
        if self.last_node.front is None:
            self.__init__()
        else:
            self.last_node = self.last_node.front
            self.last_node.back = None

    def show_all(self):
        data_list = []
        node = self.first_node
        while node:
            data_list.append(node.data)
            node = node.back
        print(" ".join(map(str, data_list))) DoublyLinkedList def __init__(self):
        self.first_node = None
        self.last_node = None

     __init__ self.first_node = None self.first_node self first_node None self.last_node = None self.last_node self last_node None self self def insert(self, data):
        if self.first_node is None:
            self.first_node = DoublyLinkedNode(None, data, None)
            self.last_node = self.first_node
        else:
            second_node = self.first_node
            self.first_node = DoublyLinkedNode(None, data, second_node)
            second_node.front = self.first_node

     insert if self.first_node is None:
            self.first_node = DoublyLinkedNode(None, data, None)
            self.last_node = self.first_node
        else:
            second_node = self.first_node
            self.first_node = DoublyLinkedNode(None, data, second_node)
            second_node.front = self.first_node

     self.first_node is None self.first_node self first_node None self.first_node = DoublyLinkedNode(None, data, None) self.first_node self first_node DoublyLinkedNode(None, data, None) DoublyLinkedNode None data None self.last_node = self.first_node self.last_node self last_node self.first_node self first_node second_node = self.first_node second_node self.first_node self first_node self.first_node = DoublyLinkedNode(None, data, second_node) self.first_node self first_node DoublyLinkedNode(None, data, second_node) DoublyLinkedNode None data second_node second_node.front = self.first_node second_node.front second_node front self.first_node self first_node self self data data def delete(self, data):
        node = self.first_node
        while node:
            if node.data == data:
                if node == self.first_node:
                    self.delete_first()
                    break
                elif node == self.last_node:
                    self.delete_last()
                    break
                else:
                    node.front.back = node.back
                    node.back.front = node.front
                    break
            else:
                node = node.back

     delete node = self.first_node node self.first_node self first_node while node:
            if node.data == data:
                if node == self.first_node:
                    self.delete_first()
                    break
                elif node == self.last_node:
                    self.delete_last()
                    break
                else:
                    node.front.back = node.back
                    node.back.front = node.front
                    break
            else:
                node = node.back

     node if node.data == data:
                if node == self.first_node:
                    self.delete_first()
                    break
                elif node == self.last_node:
                    self.delete_last()
                    break
                else:
                    node.front.back = node.back
                    node.back.front = node.front
                    break
            else:
                node = node.back

     node.data == data node.data node data data if node == self.first_node:
                    self.delete_first()
                    break
                elif node == self.last_node:
                    self.delete_last()
                    break
                else:
                    node.front.back = node.back
                    node.back.front = node.front
                    break
             node == self.first_node node self.first_node self first_node self.delete_first() self.delete_first self delete_first break elif node == self.last_node:
                    self.delete_last()
                    break
                 node == self.last_node node self.last_node self last_node self.delete_last() self.delete_last self delete_last break node.front.back = node.back node.front.back node.front node front back node.back node back node.back.front = node.front node.back.front node.back node back front node.front node front break node = node.back node node.back node back self self data data def delete_first(self):
        if self.first_node.back is None:
            self.__init__()
        else:
            self.first_node = self.first_node.back
            self.first_node.front = None

     delete_first if self.first_node.back is None:
            self.__init__()
        else:
            self.first_node = self.first_node.back
            self.first_node.front = None

     self.first_node.back is None self.first_node.back self.first_node self first_node back None self.__init__() self.__init__ self __init__ self.first_node = self.first_node.back self.first_node self first_node self.first_node.back self.first_node self first_node back self.first_node.front = None self.first_node.front self.first_node self first_node front None self self def delete_last(self):
        if self.last_node.front is None:
            self.__init__()
        else:
            self.last_node = self.last_node.front
            self.last_node.back = None

     delete_last if self.last_node.front is None:
            self.__init__()
        else:
            self.last_node = self.last_node.front
            self.last_node.back = None

     self.last_node.front is None self.last_node.front self.last_node self last_node front None self.__init__() self.__init__ self __init__ self.last_node = self.last_node.front self.last_node self last_node self.last_node.front self.last_node self last_node front self.last_node.back = None self.last_node.back self.last_node self last_node back None self self def show_all(self):
        data_list = []
        node = self.first_node
        while node:
            data_list.append(node.data)
            node = node.back
        print(" ".join(map(str, data_list))) show_all data_list = [] data_list [] node = self.first_node node self.first_node self first_node while node:
            data_list.append(node.data)
            node = node.back
         node data_list.append(node.data) data_list.append data_list append node.data node data node = node.back node node.back node back print(" ".join(map(str, data_list))) print " ".join(map(str, data_list)) " ".join " " join map(str, data_list) map str data_list self self object def main():
    n = int(input())
    link = DoublyLinkedList()
    for _ in range(n):
        command = input().rstrip()
        if command == "deleteFirst":
            link.delete_first()
        elif command == "deleteLast":
            link.delete_last()
        else:
            command = command.split()
            command, data = command[0], int(command[1])
            if command == "insert":
                link.insert(data)
            elif command == "delete":
                link.delete(data)
            else:
                raise ValueError
    link.show_all() main n = int(input()) n int(input()) int input() input link = DoublyLinkedList() link DoublyLinkedList() DoublyLinkedList for _ in range(n):
        command = input().rstrip()
        if command == "deleteFirst":
            link.delete_first()
        elif command == "deleteLast":
            link.delete_last()
        else:
            command = command.split()
            command, data = command[0], int(command[1])
            if command == "insert":
                link.insert(data)
            elif command == "delete":
                link.delete(data)
            else:
                raise ValueError
     _ range(n) range n command = input().rstrip() command input().rstrip() ().rstrip () input rstrip if command == "deleteFirst":
            link.delete_first()
        elif command == "deleteLast":
            link.delete_last()
        else:
            command = command.split()
            command, data = command[0], int(command[1])
            if command == "insert":
                link.insert(data)
            elif command == "delete":
                link.delete(data)
            else:
                raise ValueError
     command == "deleteFirst" command "deleteFirst" link.delete_first() link.delete_first link delete_first elif command == "deleteLast":
            link.delete_last()
         command == "deleteLast" command "deleteLast" link.delete_last() link.delete_last link delete_last command = command.split() command command.split() command.split command split command, data = command[0], int(command[1]) command command[0] command 0 data int(command[1]) int command[1] command 1 if command == "insert":
                link.insert(data)
            elif command == "delete":
                link.delete(data)
            else:
                raise ValueError
     command == "insert" command "insert" link.insert(data) link.insert link insert data elif command == "delete":
                link.delete(data)
             command == "delete" command "delete" link.delete(data) link.delete link delete data raise ValueError ValueError link.show_all() link.show_all link show_all if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main input = sys.stdin.readline sys.stdin.readline input def main():
    n = int(input())
    link = DoublyLinkedList()
    for _ in range(n):
        command = input().rstrip()
        if command == "deleteFirst":
            link.delete_first()
        elif command == "deleteLast":
            link.delete_last()
        else:
            command = command.split()
            command, data = command[0], int(command[1])
            if command == "insert":
                link.insert(data)
            elif command == "delete":
                link.delete(data)
            else:
                raise ValueError
    link.show_all() def main():
    n = int(input())
    link = DoublyLinkedList()
    for _ in range(n):
        command = input().rstrip()
        if command == "deleteFirst":
            link.delete_first()
        elif command == "deleteLast":
            link.delete_last()
        else:
            command = command.split()
            command, data = command[0], int(command[1])
            if command == "insert":
                link.insert(data)
            elif command == "delete":
                link.delete(data)
            else:
                raise ValueError
    link.show_all() main class DoublyLinkedNode(object):
    def __init__(self, front, data, back):
        self.front = front
        self.data = data
        self.back = back class DoublyLinkedNode(object):
    def __init__(self, front, data, back):
        self.front = front
        self.data = data
        self.back = back DoublyLinkedNode class DoublyLinkedList(object):
    def __init__(self):
        self.first_node = None
        self.last_node = None

    def insert(self, data):
        if self.first_node is None:
            self.first_node = DoublyLinkedNode(None, data, None)
            self.last_node = self.first_node
        else:
            second_node = self.first_node
            self.first_node = DoublyLinkedNode(None, data, second_node)
            second_node.front = self.first_node

    def delete(self, data):
        node = self.first_node
        while node:
            if node.data == data:
                if node == self.first_node:
                    self.delete_first()
                    break
                elif node == self.last_node:
                    self.delete_last()
                    break
                else:
                    node.front.back = node.back
                    node.back.front = node.front
                    break
            else:
                node = node.back

    def delete_first(self):
        if self.first_node.back is None:
            self.__init__()
        else:
            self.first_node = self.first_node.back
            self.first_node.front = None

    def delete_last(self):
        if self.last_node.front is None:
            self.__init__()
        else:
            self.last_node = self.last_node.front
            self.last_node.back = None

    def show_all(self):
        data_list = []
        node = self.first_node
        while node:
            data_list.append(node.data)
            node = node.back
        print(" ".join(map(str, data_list))) class DoublyLinkedList(object):
    def __init__(self):
        self.first_node = None
        self.last_node = None

    def insert(self, data):
        if self.first_node is None:
            self.first_node = DoublyLinkedNode(None, data, None)
            self.last_node = self.first_node
        else:
            second_node = self.first_node
            self.first_node = DoublyLinkedNode(None, data, second_node)
            second_node.front = self.first_node

    def delete(self, data):
        node = self.first_node
        while node:
            if node.data == data:
                if node == self.first_node:
                    self.delete_first()
                    break
                elif node == self.last_node:
                    self.delete_last()
                    break
                else:
                    node.front.back = node.back
                    node.back.front = node.front
                    break
            else:
                node = node.back

    def delete_first(self):
        if self.first_node.back is None:
            self.__init__()
        else:
            self.first_node = self.first_node.back
            self.first_node.front = None

    def delete_last(self):
        if self.last_node.front is None:
            self.__init__()
        else:
            self.last_node = self.last_node.front
            self.last_node.back = None

    def show_all(self):
        data_list = []
        node = self.first_node
        while node:
            data_list.append(node.data)
            node = node.back
        print(" ".join(map(str, data_list))) DoublyLinkedList
import sys

input = sys.stdin.readline


class DoublyLinkedNode(object):
    def __init__(self, front, data, back):
        self.front = front
        self.data = data
        self.back = back


class DoublyLinkedList(object):
    def __init__(self):
        self.first_node = None
        self.last_node = None

    def insert(self, data):
        if self.first_node is None:
            self.first_node = DoublyLinkedNode(None, data, None)
            self.last_node = self.first_node
        else:
            second_node = self.first_node
            self.first_node = DoublyLinkedNode(None, data, second_node)
            second_node.front = self.first_node

    def delete(self, data):
        node = self.first_node
        while node:
            if node.data == data:
                if node == self.first_node:
                    self.delete_first()
                    break
                elif node == self.last_node:
                    self.delete_last()
                    break
                else:
                    node.front.back = node.back
                    node.back.front = node.front
                    break
            else:
                node = node.back

    def delete_first(self):
        if self.first_node.back is None:
            self.__init__()
        else:
            self.first_node = self.first_node.back
            self.first_node.front = None

    def delete_last(self):
        if self.last_node.front is None:
            self.__init__()
        else:
            self.last_node = self.last_node.front
            self.last_node.back = None

    def show_all(self):
        data_list = []
        node = self.first_node
        while node:
            data_list.append(node.data)
            node = node.back
        print(" ".join(map(str, data_list)))


def main():
    n = int(input())
    link = DoublyLinkedList()
    for _ in range(n):
        command = input().rstrip()
        if command == "deleteFirst":
            link.delete_first()
        elif command == "deleteLast":
            link.delete_last()
        else:
            command = command.split()
            command, data = command[0], int(command[1])
            if command == "insert":
                link.insert(data)
            elif command == "delete":
                link.delete(data)
            else:
                raise ValueError
    link.show_all()


if __name__ == "__main__":
    main()

