import collections
d=collections.deque()
for _ in range(int(input())):
 e=input()
 if'i'==e[0]:d.appendleft(e.split()[1])
 else:
  if' '==e[6]:
   m=e.split()[1]
   if m in d:d.remove(m)
  elif len(e)%2:d.popleft()
  else:d.pop()
print(*d) import collections collections d=collections.deque() d collections.deque() collections.deque collections deque for _ in range(int(input())):
 e=input()
 if'i'==e[0]:d.appendleft(e.split()[1])
 else:
  if' '==e[6]:
   m=e.split()[1]
   if m in d:d.remove(m)
  elif len(e)%2:d.popleft()
  else:d.pop() _ range(int(input())) range int(input()) int input() input e=input() e input() input if'i'==e[0]:d.appendleft(e.split()[1])
 else:
  if' '==e[6]:
   m=e.split()[1]
   if m in d:d.remove(m)
  elif len(e)%2:d.popleft()
  else:d.pop() 'i'==e[0] 'i' e[0] e 0 if' '==e[6]:
   m=e.split()[1]
   if m in d:d.remove(m)
  elif len(e)%2:d.popleft()
  else:d.pop() ' '==e[6] ' ' e[6] e 6 m=e.split()[1] m e.split()[1] e.split() e.split e split 1 if m in d:d.remove(m)
   m in d m d elif len(e)%2:d.popleft()
   len(e)%2 len(e) len e 2 print(*d) print *d d e=input() input() e d=collections.deque() collections.deque() d m=e.split()[1] e.split()[1] m
import collections
d=collections.deque()
for _ in range(int(input())):
 e=input()
 if'i'==e[0]:d.appendleft(e.split()[1])
 else:
  if' '==e[6]:
   m=e.split()[1]
   if m in d:d.remove(m)
  elif len(e)%2:d.popleft()
  else:d.pop()
print(*d)
