# 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] == 'insert':

        deque.appendleft(inp[1])

    elif inp[0] == 'deleteFirst':

        deque.popleft()

    elif inp[0] == 'deleteLast':

        deque.pop()

    else:

        if inp[1] in deque:

            deque.remove(inp[1])



print((*deque))
# coding=utf-8

from collections import deque

n = int(eval(input()))

deque = deque()

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



for i in range(n):

    inp = input_lines[i].split()

    if inp[0] == 'insert':

        deque.appendleft(inp[1])

    elif inp[0] == 'deleteFirst':

        deque.popleft()

    elif inp[0] == 'deleteLast':

        deque.pop()

    else:

        if inp[1] in deque:

            deque.remove(inp[1])



print((*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] == "insert":
        deque.appendleft(inp[1])
    elif inp[0] == "deleteFirst":
        deque.popleft()
    elif inp[0] == "deleteLast":
        deque.pop()
    else:
        if inp[1] in deque:
            deque.remove(inp[1])
print((*deque))

# coding=utf-8
from collections import deque

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

-input_lines = [input().split() for x in range(n)] +input_lines = [eval(input()) for x in range(n)] -    inp = input_lines[i] +    inp = input_lines[i].split()