# Original solution
class LinkedList(object):
    def __init__(self):
        self.nodes = []
        self.first = None
        self.last = None

    def insert(self, key):
        node = {'key':key, 'next':None, 'prev':None}
        if not self.nodes:
            self.first = self.last = node
            self.nodes.append(node)
        else:
            node['next'] = self.first
            self.first['prev'] = node
            self.first = node
            self.nodes.append(node)

    def delete(self, key):
        node = self.first
        if len(self.nodes) == 1 and node['key'] == key:
            self.first = self.last = None
            self.nodes = []
            return
        if self.first['key'] == key:
            self.deleteFirst()
            return
        while node['next']:
            if node['key'] == key:
                node['prev']['next'] = node['next']
                node['next']['prev'] = node['prev']
                self.nodes.remove(node)
                return
            node = node['next']
        if self.last['key'] == key:
            self.deleteLast()

    def deleteFirst(self):
        if len(self.nodes) == 1:
            self.first = self.last = None
            self.nodes = []
        else:
            self.first['next']['prev'] = None
            self.nodes.remove(self.first)
            self.first = self.first['next']

    def deleteLast(self):
        if len(self.nodes) == 1:
            self.first = self.last = None
            self.nodes = []
        else:
            self.last['prev']['next'] = None
            self.nodes.remove(self.last)
            self.last = self.last['prev']

    def show(self):
        if not self.nodes:
            print('')
            return
        node = self.first
        res = [node['key']]
        while node['next']:
            node = node['next']
            res.append(node['key'])
        print((' '.join(res)))

def run():
    n = int(eval(input()))
    linked_list = LinkedList()
    for _ in range(n):
        order = [o.strip() for o in input().split()]
        if order[0] == 'insert':
            linked_list.insert(order[1])
        elif order[0] == 'delete':
            linked_list.delete(order[1])
        elif order[0] == 'deleteFirst':
            linked_list.deleteFirst()
        elif order[0] == 'deleteLast':
            linked_list.deleteLast()
    linked_list.show()

if __name__ == '__main__':
    run()


# Optimized solution
class LinkedList(object):
    def __init__(self):
        self.first = None
        self.last = None

    def insert(self, key):
        node = {'key':key, 'next':None, 'prev':None}
        if not self.first:
            self.first = self.last = node
        else:
            node['next'] = self.first
            self.first['prev'] = node
            self.first = node

    def delete(self, key):
        node = self.first
        if self.first['key'] == key:
            self.deleteFirst()
            return
        while node['next']:
            if node['key'] == key:
                node['prev']['next'] = node['next']
                node['next']['prev'] = node['prev']
                return
            node = node['next']
        if self.last['key'] == key:
            self.deleteLast()

    def deleteFirst(self):
        if self.first == self.last:
            self.first = self.last = None
        else:
            self.first['next']['prev'] = None
            self.first = self.first['next']

    def deleteLast(self):
        if self.first == self.last:
            self.first = self.last = None
        else:
            self.last['prev']['next'] = None
            self.last = self.last['prev']

    def show(self):
        if not self.first:
            print('')
            return
        node = self.first
        res = [node['key']]
        while node['next']:
            node = node['next']
            res.append(node['key'])
        print((' '.join(res)))

def run():
    n = int(eval(input()))
    linked_list = LinkedList()
    for _ in range(n):
        order = [o.strip() for o in input().split()]
        if order[0] == 'insert':
            linked_list.insert(order[1])
        elif order[0] == 'delete':
            linked_list.delete(order[1])
        elif order[0] == 'deleteFirst':
            linked_list.deleteFirst()
        elif order[0] == 'deleteLast':
            linked_list.deleteLast()
    linked_list.show()

if __name__ == '__main__':
    run()