output_description: Print all the element (key) in the list after the given operations. Two
  consequtive keys should be separated by a single space.
input_description: The input is given in the following format:
  
  _n_  
  _command_ 1  
  _command_ 2  
  ...  
  _command n_  
  
  In the first line, the number of operations _n_ is given. In the following _n_
  lines, the above mentioned operations are given in the following format:
  
    * insert x
    * delete x
    * deleteFirst 
    * deleteLast
attempt: class Node:
      def __init__(self, num, next=None, prev=None):
          self.num = num
          self.next = next
          self.prev = prev
  
  
  class Doubly:
      def __init__(self):
          self.start = self.end = None
  
      def insert(self, x):
          it = Node(x)
          if self.end is None:
              self.end = self.start = it
          else:
              it.next = self.start
              self.start.prev = it
              self.start = it
  
      def delete(self, x):
          poin = self.start
          while poin is not None:
              if poin.num == x:
                  if poin.prev is None and poin.next is None:
                      self.start = self.end = None
                  elif poin is self.start:  # 先頭
                      self.start.next.prev = None
                      self.start = poin.next
                  elif poin is self.end:  # 末尾
                      poin.prev.next = None
                      self.end = poin.prev
                  else:
                      poin.prev.next = poin.next
                      poin.next.prev = poin.prev
                  break
              poin = poin.next
  
      # def deleteFirst(self):
      #     self.start=self.start.next
      # def deleteLast(self):
      #     self.end.prev.next =None
      #     self.end=self.end.prev
      def deleteFirst(self):
          if self.start is self.end:
              self.start = self.end = None
          else:
              self.start.next.prev = None
              self.start = self.start.next
  
      def deleteLast(self):
          if self.start is self.end:
              self.start = self.end = None
          else:
              self.end.prev.next = None
              self.end = self.end.prev
  
      def print(self):
          var = self.start
          lis = []
          while var is not None:
              lis.append(var.num)
              var = var.next
          return " ".join(lis)
  
  
  from sys import stdin
  
  N = int(input())
  DB = Doubly()
  # code=[input().split() for k in range(N)]
  # for _ in range(N):
  #     c=input().split()
  #     if len(c)==1:
  #         eval('DB.'+c[0]+'()')
  #     else:
  #         eval('DB.'+c[0]+'(c[1])')
  for _ in range(N):
      cmd = stdin.readline().strip().split()
      if cmd[0] == "insert":
          DB.insert(cmd[1])
      elif cmd[0] == "delete":
          DB.delete(cmd[1])
      elif cmd[0] == "deleteFirst":
          DB.deleteFirst()
      elif cmd[0] == "deleteLast":
          DB.deleteLast()
  print(DB.print())
  
problem_description: Doubly Linked List
  
  Your task is to implement a double linked list.
  
  Write a program which performs the following operations:
  
    * insert x: insert an element with key x into the front of the list.
    * delete x: delete the first element which has the key of x from the list. If there is not such element, you need not do anything.
    * deleteFirst: delete the first element from the list. 
    * deleteLast: delete the last element from the list.
samples: [{"input": "7\n    insert 5\n    insert 2\n    insert 3\n    insert 1\n    delete 3\n    insert 6\n    delete 5", "output": "6 1 2"}, {"input": "9\n    insert 5\n    insert 2\n    insert 3\n    insert 1\n    delete 3\n    insert 6\n    delete 5\n    deleteFirst\n    deleteLast", "output": "1"}]