import collections,sys
d=collections.deque()
input()
for e in sys.stdin.readlines():
 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.pop()
  else:d.popleft()
print(*d) import collections,sys collections sys d=collections.deque() d collections.deque() collections.deque collections deque input() input for e in sys.stdin.readlines():
 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.pop()
  else:d.popleft() e sys.stdin.readlines() sys.stdin.readlines sys.stdin sys stdin readlines 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.pop()
  else:d.popleft() '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.pop()
  else:d.popleft() ' '==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.pop()
   len(e)%2 len(e) len e 2 print(*d) print *d d d=collections.deque() collections.deque() d m=e.split()[1] e.split()[1] m
import collections,sys
d=collections.deque()
input()
for e in sys.stdin.readlines():
 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.pop()
  else:d.popleft()
print(*d)
