import sys


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


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


def insert(double_lst, key):
    node = Node(key, double_lst.nil, double_lst.nil.next)
    double_lst.nil.next.prev = node
    double_lst.nil.next = node


def search(double_lst, key):
    cur = double_lst.nil.next

    while cur != double_lst.nil and cur.key != key:
        cur = cur.next

    return cur


def delete_node(double_lst, node):
    if node == double_lst.nil:
            return

    node.prev.next = node.next
    node.next.prev = node.prev


def delete_first(double_lst):
    delete_node(double_lst, double_lst.nil.next)


def delete_last(double_lst):
    delete_node(double_lst, double_lst.nil.prev)


def delete_key(double_lst, key):
    node = search(double_lst, key)
    delete_node(double_lst, node)


def main():
    n = int(input())
    ll = LinkedList()

    for i in range(n):
        order = sys.stdin.readline().split()

        if order[0] == "insert":
            insert(ll, int(order[1]))
        elif order[0] == "delete":
            delete_key(ll, int(order[1]))
        elif order[0] == "deleteFirst":
            delete_first(ll)
        else:
            delete_last(ll)

    cur = ll.nil
    while cur.next != ll.nil:
        cur = cur.next
        if cur.next == ll.nil:
            print(cur.key)
        else:
            print(cur.key, end=" ")


if __name__ == '__main__':
    main()
 import sys sys class Node:
    def __init__(self, key, prev, next):
        self.key = key
        self.prev = prev
        self.next = next Node def __init__(self, key, prev, next):
        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 key prev prev next next class LinkedList:
    def __init__(self):
        self.nil = Node(None, None, None)
        self.nil.prev = self.nil
        self.nil.next = self.nil LinkedList def __init__(self):
        self.nil = Node(None, None, None)
        self.nil.prev = self.nil
        self.nil.next = self.nil __init__ self.nil = Node(None, None, None) self.nil self nil Node(None, None, None) Node None None None self.nil.prev = self.nil self.nil.prev self.nil self nil prev self.nil self nil self.nil.next = self.nil self.nil.next self.nil self nil next self.nil self nil self self def insert(double_lst, key):
    node = Node(key, double_lst.nil, double_lst.nil.next)
    double_lst.nil.next.prev = node
    double_lst.nil.next = node insert node = Node(key, double_lst.nil, double_lst.nil.next) node Node(key, double_lst.nil, double_lst.nil.next) Node key double_lst.nil double_lst nil double_lst.nil.next double_lst.nil double_lst nil next double_lst.nil.next.prev = node double_lst.nil.next.prev double_lst.nil.next double_lst.nil double_lst nil next prev node double_lst.nil.next = node double_lst.nil.next double_lst.nil double_lst nil next node double_lst double_lst key key def search(double_lst, key):
    cur = double_lst.nil.next

    while cur != double_lst.nil and cur.key != key:
        cur = cur.next

    return cur search cur = double_lst.nil.next cur double_lst.nil.next double_lst.nil double_lst nil next while cur != double_lst.nil and cur.key != key:
        cur = cur.next

     cur != double_lst.nil and cur.key != key cur != double_lst.nil cur double_lst.nil double_lst nil cur.key != key cur.key cur key key cur = cur.next cur cur.next cur next return cur cur double_lst double_lst key key def delete_node(double_lst, node):
    if node == double_lst.nil:
            return

    node.prev.next = node.next
    node.next.prev = node.prev delete_node if node == double_lst.nil:
            return

     node == double_lst.nil node double_lst.nil double_lst nil return 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 double_lst double_lst node node def delete_first(double_lst):
    delete_node(double_lst, double_lst.nil.next) delete_first delete_node(double_lst, double_lst.nil.next) delete_node double_lst double_lst.nil.next double_lst.nil double_lst nil next double_lst double_lst def delete_last(double_lst):
    delete_node(double_lst, double_lst.nil.prev) delete_last delete_node(double_lst, double_lst.nil.prev) delete_node double_lst double_lst.nil.prev double_lst.nil double_lst nil prev double_lst double_lst def delete_key(double_lst, key):
    node = search(double_lst, key)
    delete_node(double_lst, node) delete_key node = search(double_lst, key) node search(double_lst, key) search double_lst key delete_node(double_lst, node) delete_node double_lst node double_lst double_lst key key def main():
    n = int(input())
    ll = LinkedList()

    for i in range(n):
        order = sys.stdin.readline().split()

        if order[0] == "insert":
            insert(ll, int(order[1]))
        elif order[0] == "delete":
            delete_key(ll, int(order[1]))
        elif order[0] == "deleteFirst":
            delete_first(ll)
        else:
            delete_last(ll)

    cur = ll.nil
    while cur.next != ll.nil:
        cur = cur.next
        if cur.next == ll.nil:
            print(cur.key)
        else:
            print(cur.key, end=" ") main n = int(input()) n int(input()) int input() input ll = LinkedList() ll LinkedList() LinkedList for i in range(n):
        order = sys.stdin.readline().split()

        if order[0] == "insert":
            insert(ll, int(order[1]))
        elif order[0] == "delete":
            delete_key(ll, int(order[1]))
        elif order[0] == "deleteFirst":
            delete_first(ll)
        else:
            delete_last(ll)

     i range(n) range n order = sys.stdin.readline().split() order sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split if order[0] == "insert":
            insert(ll, int(order[1]))
        elif order[0] == "delete":
            delete_key(ll, int(order[1]))
        elif order[0] == "deleteFirst":
            delete_first(ll)
        else:
            delete_last(ll)

     order[0] == "insert" order[0] order 0 "insert" insert(ll, int(order[1])) insert ll int(order[1]) int order[1] order 1 elif order[0] == "delete":
            delete_key(ll, int(order[1]))
         order[0] == "delete" order[0] order 0 "delete" delete_key(ll, int(order[1])) delete_key ll int(order[1]) int order[1] order 1 elif order[0] == "deleteFirst":
            delete_first(ll)
         order[0] == "deleteFirst" order[0] order 0 "deleteFirst" delete_first(ll) delete_first ll delete_last(ll) delete_last ll cur = ll.nil cur ll.nil ll nil while cur.next != ll.nil:
        cur = cur.next
        if cur.next == ll.nil:
            print(cur.key)
        else:
            print(cur.key, end=" ") cur.next != ll.nil cur.next cur next ll.nil ll nil cur = cur.next cur cur.next cur next if cur.next == ll.nil:
            print(cur.key)
        else:
            print(cur.key, end=" ") cur.next == ll.nil cur.next cur next ll.nil ll nil print(cur.key) print cur.key cur key print(cur.key, end=" ") print cur.key cur key end=" " end " " if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def search(double_lst, key):
    cur = double_lst.nil.next

    while cur != double_lst.nil and cur.key != key:
        cur = cur.next

    return cur def search(double_lst, key):
    cur = double_lst.nil.next

    while cur != double_lst.nil and cur.key != key:
        cur = cur.next

    return cur search def delete_key(double_lst, key):
    node = search(double_lst, key)
    delete_node(double_lst, node) def delete_key(double_lst, key):
    node = search(double_lst, key)
    delete_node(double_lst, node) delete_key class Node:
    def __init__(self, key, prev, next):
        self.key = key
        self.prev = prev
        self.next = next class Node:
    def __init__(self, key, prev, next):
        self.key = key
        self.prev = prev
        self.next = next Node def delete_last(double_lst):
    delete_node(double_lst, double_lst.nil.prev) def delete_last(double_lst):
    delete_node(double_lst, double_lst.nil.prev) delete_last def insert(double_lst, key):
    node = Node(key, double_lst.nil, double_lst.nil.next)
    double_lst.nil.next.prev = node
    double_lst.nil.next = node def insert(double_lst, key):
    node = Node(key, double_lst.nil, double_lst.nil.next)
    double_lst.nil.next.prev = node
    double_lst.nil.next = node insert def delete_node(double_lst, node):
    if node == double_lst.nil:
            return

    node.prev.next = node.next
    node.next.prev = node.prev def delete_node(double_lst, node):
    if node == double_lst.nil:
            return

    node.prev.next = node.next
    node.next.prev = node.prev delete_node def main():
    n = int(input())
    ll = LinkedList()

    for i in range(n):
        order = sys.stdin.readline().split()

        if order[0] == "insert":
            insert(ll, int(order[1]))
        elif order[0] == "delete":
            delete_key(ll, int(order[1]))
        elif order[0] == "deleteFirst":
            delete_first(ll)
        else:
            delete_last(ll)

    cur = ll.nil
    while cur.next != ll.nil:
        cur = cur.next
        if cur.next == ll.nil:
            print(cur.key)
        else:
            print(cur.key, end=" ") def main():
    n = int(input())
    ll = LinkedList()

    for i in range(n):
        order = sys.stdin.readline().split()

        if order[0] == "insert":
            insert(ll, int(order[1]))
        elif order[0] == "delete":
            delete_key(ll, int(order[1]))
        elif order[0] == "deleteFirst":
            delete_first(ll)
        else:
            delete_last(ll)

    cur = ll.nil
    while cur.next != ll.nil:
        cur = cur.next
        if cur.next == ll.nil:
            print(cur.key)
        else:
            print(cur.key, end=" ") main def delete_first(double_lst):
    delete_node(double_lst, double_lst.nil.next) def delete_first(double_lst):
    delete_node(double_lst, double_lst.nil.next) delete_first class LinkedList:
    def __init__(self):
        self.nil = Node(None, None, None)
        self.nil.prev = self.nil
        self.nil.next = self.nil class LinkedList:
    def __init__(self):
        self.nil = Node(None, None, None)
        self.nil.prev = self.nil
        self.nil.next = self.nil LinkedList
import sys


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


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


def insert(double_lst, key):
    node = Node(key, double_lst.nil, double_lst.nil.next)
    double_lst.nil.next.prev = node
    double_lst.nil.next = node


def search(double_lst, key):
    cur = double_lst.nil.next

    while cur != double_lst.nil and cur.key != key:
        cur = cur.next

    return cur


def delete_node(double_lst, node):
    if node == double_lst.nil:
            return

    node.prev.next = node.next
    node.next.prev = node.prev


def delete_first(double_lst):
    delete_node(double_lst, double_lst.nil.next)


def delete_last(double_lst):
    delete_node(double_lst, double_lst.nil.prev)


def delete_key(double_lst, key):
    node = search(double_lst, key)
    delete_node(double_lst, node)


def main():
    n = int(input())
    ll = LinkedList()

    for i in range(n):
        order = sys.stdin.readline().split()

        if order[0] == "insert":
            insert(ll, int(order[1]))
        elif order[0] == "delete":
            delete_key(ll, int(order[1]))
        elif order[0] == "deleteFirst":
            delete_first(ll)
        else:
            delete_last(ll)

    cur = ll.nil
    while cur.next != ll.nil:
        cur = cur.next
        if cur.next == ll.nil:
            print(cur.key)
        else:
            print(cur.key, end=" ")


if __name__ == '__main__':
    main()

