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: import sys
  
  head = -1
  tail = -1
  dll = []
  for i in range(int(sys.stdin.readline())):
      line = sys.stdin.readline()
  
      if line[6] == "F":
          if head == tail:
              dll = []
              head = -1
              tail = -1
          else:
              nxt = dll[head][2]  #
              if nxt >= 0:
                  dll[nxt][1] = -1
              if tail == head:
                  tail = -1
              head = nxt
      elif line[6] == "L":
          if head == tail:
              dll = []
              head = -1
              tail = -1
          else:
              prv = dll[tail][1]
              if prv >= 0:
                  dll[prv][2] = -1
              if tail == head:
                  head = -1
              tail = prv
  
      elif line[0] == "i":  # 'insert':
          x = int(line[7:])
          dll.append([x, -1, head])
          llen = len(dll) - 1
          if head == -1:
              tail = llen
          else:
              dll[head][1] = llen
          head = llen
      elif line[0] == "d":  # 'delete':
          x = int(line[7:])
          cur = head
          while cur >= 0:
              if dll[cur][0] == x:
                  nxt = dll[cur][2]
                  prv = dll[cur][1]
                  dll[nxt][1] = prv
                  dll[prv][2] = nxt
                  if nxt == -1:
                      tail = prv
                  if prv == -1:
                      head = nxt
                  break
              cur = dll[cur][2]
  
  print(dll[head][0], end="")
  cur = dll[head][2]
  while cur >= 0:
      print("", dll[cur][0], end="")
      cur = dll[cur][2]
  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"}]