from collections import deque



n = int(eval(input()))

d = deque()

for _i in range(n):

    line = input().split()

    order = line[0]

    if order == 'deleteFirst':

        d.popleft()

    elif order == 'deleteLast':

        d.pop()

    else:

        key = line[1]

        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(eval(input()))

d = deque()

for _i in range(n):

    order = eval(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(eval(input()))
d = deque()
for _i in range(n):
    line = input().split()
    order = line[0]
    if order == "deleteFirst":
        d.popleft()
    elif order == "deleteLast":
        d.pop()
    else:
        key = line[1]
        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(eval(input()))
d = deque()
for _i in range(n):
    order = eval(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)))

-    line = input().split() -    order = line[0] +    order = eval(input()) -        key = line[1] +        order, key = order.split()