from collections import deque



n = int(eval(input()))



q = deque()



for _ in range(n):

	com = eval(input())

	if com[0] == "i":

		q.appendleft(com[7:])

	elif len(com) == 11:

		q.popleft()

	elif len(com) == 10:

		q.pop()

	else:

		try:

			q.remove(com[7:])

		except:

			pass





print((*q))



from collections import deque

from sys import stdin



n = int(eval(input()))



q = deque()



for _ in range(n):

	cmd = stdin.readline().strip().split()

	if cmd[0] == "insert":

		q.appendleft(cmd[1])

	elif cmd[0] == "deleteFirst":

		q.popleft()

	elif cmd[0] == "deleteLast":

		q.pop()

	elif cmd[0] == "delete":

		try:

			q.remove(cmd[1])

		except:

			pass



print((*q))



from collections import deque

n = int(eval(input()))
q = deque()
for _ in range(n):
    com = eval(input())
    if com[0] == "i":
        q.appendleft(com[7:])
    elif len(com) == 11:
        q.popleft()
    elif len(com) == 10:
        q.pop()
    else:
        try:
            q.remove(com[7:])
        except:
            pass
print((*q))

from collections import deque
from sys import stdin

n = int(eval(input()))
q = deque()
for _ in range(n):
    cmd = stdin.readline().strip().split()
    if cmd[0] == "insert":
        q.appendleft(cmd[1])
    elif cmd[0] == "deleteFirst":
        q.popleft()
    elif cmd[0] == "deleteLast":
        q.pop()
    elif cmd[0] == "delete":
        try:
            q.remove(cmd[1])
        except:
            pass
print((*q))

+from sys import stdin -    com = eval(input()) -    if com[0] == "i": -        q.appendleft(com[7:]) -    elif len(com) == 11: +    cmd = stdin.readline().strip().split() +    if cmd[0] == "insert": +        q.appendleft(cmd[1]) +    elif cmd[0] == "deleteFirst": -    elif len(com) == 10: +    elif cmd[0] == "deleteLast": -    else: +    elif cmd[0] == "delete": -            q.remove(com[7:]) +            q.remove(cmd[1])