# coding=utf-8

from collections import deque

n = int(eval(input()))

deque = deque()

input_lines = [input().split() for x in range(n)]



for i in range(n):

    inp = input_lines[i]

    if inp[0] == 'deleteFirst':

        deque.popleft()

    elif inp[0] == 'deleteLast':

        deque.pop()

    elif inp[0] == 'insert':

        deque.appendleft(inp[1])

    else:

        if inp[1] in deque:

            deque.remove(inp[1])



print((' '.join(deque)))
from collections import deque

import sys

 

deque = deque()

num = int(sys.stdin.readline())

line = sys.stdin.readlines()

 

for i in range(num):

 

    order = line[i].split()

 

    if order[0] == 'insert':

        deque.appendleft(order[1])

    elif order[0] == 'deleteFirst':

        deque.popleft()

    elif order[0] == 'deleteLast':

        deque.pop()

    else:

        if order[1] in deque:

            deque.remove(order[1])

 

print((' '.join(deque)))
# coding=utf-8
from collections import deque

n = int(eval(input()))
deque = deque()
input_lines = [input().split() for x in range(n)]
for i in range(n):
    inp = input_lines[i]
    if inp[0] == "deleteFirst":
        deque.popleft()
    elif inp[0] == "deleteLast":
        deque.pop()
    elif inp[0] == "insert":
        deque.appendleft(inp[1])
    else:
        if inp[1] in deque:
            deque.remove(inp[1])
print((" ".join(deque)))

from collections import deque
import sys

deque = deque()
num = int(sys.stdin.readline())
line = sys.stdin.readlines()
for i in range(num):
    order = line[i].split()
    if order[0] == "insert":
        deque.appendleft(order[1])
    elif order[0] == "deleteFirst":
        deque.popleft()
    elif order[0] == "deleteLast":
        deque.pop()
    else:
        if order[1] in deque:
            deque.remove(order[1])
print((" ".join(deque)))

-# coding=utf-8 +import sys -n = int(eval(input())) -input_lines = [input().split() for x in range(n)] -for i in range(n): -    inp = input_lines[i] -    if inp[0] == "deleteFirst": +num = int(sys.stdin.readline()) +line = sys.stdin.readlines() +for i in range(num): +    order = line[i].split() +    if order[0] == "insert": +        deque.appendleft(order[1]) +    elif order[0] == "deleteFirst": -    elif inp[0] == "deleteLast": +    elif order[0] == "deleteLast": -    elif inp[0] == "insert": -        deque.appendleft(inp[1]) -        if inp[1] in deque: -            deque.remove(inp[1]) +        if order[1] in deque: +            deque.remove(order[1])