
import collections,sys
def s():
  d = collections.deque()
  input()
  for e in sys.stdin:
    if "i"==e[0]: d.appendleft(e[7:-1])
    else:
      if " "==e[6]:
        m = e[7:0-1]
        if m in d: d.remove(m)
      elif "i"==e[7]: d.popleft()
      else: d.pop()
  print(*d)

s()
 import collections,sys collections sys def s():
  d = collections.deque()
  input()
  for e in sys.stdin:
    if "i"==e[0]: d.appendleft(e[7:-1])
    else:
      if " "==e[6]:
        m = e[7:0-1]
        if m in d: d.remove(m)
      elif "i"==e[7]: d.popleft()
      else: d.pop()
  print(*d) s d = collections.deque() d collections.deque() collections.deque collections deque input() input for e in sys.stdin:
    if "i"==e[0]: d.appendleft(e[7:-1])
    else:
      if " "==e[6]:
        m = e[7:0-1]
        if m in d: d.remove(m)
      elif "i"==e[7]: d.popleft()
      else: d.pop()
   e sys.stdin sys stdin if "i"==e[0]: d.appendleft(e[7:-1])
    else:
      if " "==e[6]:
        m = e[7:0-1]
        if m in d: d.remove(m)
      elif "i"==e[7]: d.popleft()
      else: d.pop()
   "i"==e[0] "i" e[0] e 0 if " "==e[6]:
        m = e[7:0-1]
        if m in d: d.remove(m)
      elif "i"==e[7]: d.popleft()
      else: d.pop()
   " "==e[6] " " e[6] e 6 m = e[7:0-1] m e[7:0-1] e 7:0-1 7 0-1 0 1 if m in d: d.remove(m)
       m in d m d elif "i"==e[7]: d.popleft()
       "i"==e[7] "i" e[7] e 7 print(*d) print *d d s() s def s():
  d = collections.deque()
  input()
  for e in sys.stdin:
    if "i"==e[0]: d.appendleft(e[7:-1])
    else:
      if " "==e[6]:
        m = e[7:0-1]
        if m in d: d.remove(m)
      elif "i"==e[7]: d.popleft()
      else: d.pop()
  print(*d) def s():
  d = collections.deque()
  input()
  for e in sys.stdin:
    if "i"==e[0]: d.appendleft(e[7:-1])
    else:
      if " "==e[6]:
        m = e[7:0-1]
        if m in d: d.remove(m)
      elif "i"==e[7]: d.popleft()
      else: d.pop()
  print(*d) s

import collections,sys
def s():
  d = collections.deque()
  input()
  for e in sys.stdin:
    if "i"==e[0]: d.appendleft(e[7:-1])
    else:
      if " "==e[6]:
        m = e[7:0-1]
        if m in d: d.remove(m)
      elif "i"==e[7]: d.popleft()
      else: d.pop()
  print(*d)

s()

