from collections import deque

n = int(input())
d = deque()
for _i in range(n):
    order = input()
    if order == 'deleteFirst':
        d.popleft()
    elif order == 'deleteLast':
        d.pop()
    else:
        order, key = order.split()
        if order == 'insert':
            d.appendleft(key)
        elif order == 'delete':
            try:
                d.remove(key)
            except ValueError:
                pass
        else:
            raise ValueError('Invalid order: {order}')

print(' '.join(d))
 from collections import deque n = int(input()) n int(input()) int input() input d = deque() d deque() deque for _i in range(n):
    order = input()
    if order == 'deleteFirst':
        d.popleft()
    elif order == 'deleteLast':
        d.pop()
    else:
        order, key = order.split()
        if order == 'insert':
            d.appendleft(key)
        elif order == 'delete':
            try:
                d.remove(key)
            except ValueError:
                pass
        else:
            raise ValueError('Invalid order: {order}') _i range(n) range n order = input() order input() input if order == 'deleteFirst':
        d.popleft()
    elif order == 'deleteLast':
        d.pop()
    else:
        order, key = order.split()
        if order == 'insert':
            d.appendleft(key)
        elif order == 'delete':
            try:
                d.remove(key)
            except ValueError:
                pass
        else:
            raise ValueError('Invalid order: {order}') order == 'deleteFirst' order 'deleteFirst' d.popleft() d.popleft d popleft elif order == 'deleteLast':
        d.pop()
     order == 'deleteLast' order 'deleteLast' d.pop() d.pop d pop order, key = order.split() order order.split() order.split order split key if order == 'insert':
            d.appendleft(key)
        elif order == 'delete':
            try:
                d.remove(key)
            except ValueError:
                pass
        else:
            raise ValueError('Invalid order: {order}') order == 'insert' order 'insert' d.appendleft(key) d.appendleft d appendleft key elif order == 'delete':
            try:
                d.remove(key)
            except ValueError:
                pass
         order == 'delete' order 'delete' try:
                d.remove(key)
            except ValueError:
                pass
         except ValueError:
                pass
         d.remove(key) d.remove d remove key raise ValueError('Invalid order: {order}') ValueError('Invalid order: {order}') ValueError 'Invalid order: {order}' print(' '.join(d)) print ' '.join(d) ' '.join ' ' join d d = deque() deque() d order, key = order.split() order.split() order order = input() input() order n = int(input()) int(input()) n key = order.split() order.split() key
from collections import deque

n = int(input())
d = deque()
for _i in range(n):
    order = input()
    if order == 'deleteFirst':
        d.popleft()
    elif order == 'deleteLast':
        d.pop()
    else:
        order, key = order.split()
        if order == 'insert':
            d.appendleft(key)
        elif order == 'delete':
            try:
                d.remove(key)
            except ValueError:
                pass
        else:
            raise ValueError('Invalid order: {order}')

print(' '.join(d))

