from collections import deque



queue = deque()



for _ in range(int(eval(input()))):

    commands = input().split(" ")

    if commands[0] == "insert":

        queue.appendleft(commands[1])

    elif commands[0] == "delete":

        try:

            queue.remove(commands[1])

        except ValueError:

            pass

    elif commands[0] == "deleteFirst":

        queue.popleft()

    elif commands[0] == "deleteLast":

        queue.pop()



print((" ".join(queue)))
import sys

from collections import deque

n = int(eval(input()))

q = deque()

for i in range(n):

    c = sys.stdin.readline()[:-1]

    if c[0] == 'i':

        q.appendleft(c[7:])

    elif c[6] == ' ':

        try:

            q.remove(c[7:])

        except:

            pass

    elif c[6] == 'F':

        q.popleft()

    else:

        q.pop()

print((*q))
from collections import deque

queue = deque()
for _ in range(int(eval(input()))):
    commands = input().split(" ")
    if commands[0] == "insert":
        queue.appendleft(commands[1])
    elif commands[0] == "delete":
        try:
            queue.remove(commands[1])
        except ValueError:
            pass
    elif commands[0] == "deleteFirst":
        queue.popleft()
    elif commands[0] == "deleteLast":
        queue.pop()
print((" ".join(queue)))

import sys
from collections import deque

n = int(eval(input()))
q = deque()
for i in range(n):
    c = sys.stdin.readline()[:-1]
    if c[0] == "i":
        q.appendleft(c[7:])
    elif c[6] == " ":
        try:
            q.remove(c[7:])
        except:
            pass
    elif c[6] == "F":
        q.popleft()
    else:
        q.pop()
print((*q))

+import sys -queue = deque() -for _ in range(int(eval(input()))): -    commands = input().split(" ") -    if commands[0] == "insert": -        queue.appendleft(commands[1]) -    elif commands[0] == "delete": +n = int(eval(input())) +q = deque() +for i in range(n): +    c = sys.stdin.readline()[:-1] +    if c[0] == "i": +        q.appendleft(c[7:]) +    elif c[6] == " ": -            queue.remove(commands[1]) -        except ValueError: +            q.remove(c[7:]) +        except: -    elif commands[0] == "deleteFirst": -        queue.popleft() -    elif commands[0] == "deleteLast": -        queue.pop() -print((" ".join(queue))) +    elif c[6] == "F": +        q.popleft() +    else: +        q.pop() +print((*q))