from collections import deque

n = int(input())

q = deque()

for _ in range(n):
	com = 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 n = int(input()) n int(input()) int input() input q = deque() q deque() deque for _ in range(n):
	com = 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 _ range(n) range n com = input() com input() 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 com[0] == "i" com[0] com 0 "i" q.appendleft(com[7:]) q.appendleft q appendleft com[7:] com 7: 7 elif len(com) == 11:
		q.popleft()
	 len(com) == 11 len(com) len com 11 q.popleft() q.popleft q popleft elif len(com) == 10:
		q.pop()
	 len(com) == 10 len(com) len com 10 q.pop() q.pop q pop try:
			q.remove(com[7:])
		except:
			pass except:
			pass q.remove(com[7:]) q.remove q remove com[7:] com 7: 7 print(*q) print *q q n = int(input()) int(input()) n com = input() input() com q = deque() deque() q
from collections import deque

n = int(input())

q = deque()

for _ in range(n):
	com = 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)

