from collections import deque
q = deque()

for _ in range(int(input())):
	b=input()
	if b[0] == 'i':
		q.appendleft(b[7:])
	elif b[6] == ' ':
		try:
			q.remove(b[7:])
		except:
			pass
	elif len(b) > 10:
		q.popleft()
	elif len(b) > 6:
		q.pop()
print(*q) from collections import deque q = deque() q deque() deque for _ in range(int(input())):
	b=input()
	if b[0] == 'i':
		q.appendleft(b[7:])
	elif b[6] == ' ':
		try:
			q.remove(b[7:])
		except:
			pass
	elif len(b) > 10:
		q.popleft()
	elif len(b) > 6:
		q.pop() _ range(int(input())) range int(input()) int input() input b=input() b input() input if b[0] == 'i':
		q.appendleft(b[7:])
	elif b[6] == ' ':
		try:
			q.remove(b[7:])
		except:
			pass
	elif len(b) > 10:
		q.popleft()
	elif len(b) > 6:
		q.pop() b[0] == 'i' b[0] b 0 'i' q.appendleft(b[7:]) q.appendleft q appendleft b[7:] b 7: 7 elif b[6] == ' ':
		try:
			q.remove(b[7:])
		except:
			pass
	 b[6] == ' ' b[6] b 6 ' ' try:
			q.remove(b[7:])
		except:
			pass
	 except:
			pass
	 q.remove(b[7:]) q.remove q remove b[7:] b 7: 7 elif len(b) > 10:
		q.popleft()
	 len(b) > 10 len(b) len b 10 q.popleft() q.popleft q popleft elif len(b) > 6:
		q.pop() len(b) > 6 len(b) len b 6 q.pop() q.pop q pop print(*q) print *q q q = deque() deque() q b=input() input() b
from collections import deque
q = deque()

for _ in range(int(input())):
	b=input()
	if b[0] == 'i':
		q.appendleft(b[7:])
	elif b[6] == ' ':
		try:
			q.remove(b[7:])
		except:
			pass
	elif len(b) > 10:
		q.popleft()
	elif len(b) > 6:
		q.pop()
print(*q)
