Problem:


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. 

Input

The input is given in the following format:

n

command1 

command2 

...

commandn 

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 

Output

Print all the element (key) in the list after the given operations. Two consequtive keys should be separated by a single space.

Constraints

The number of operations ≤ 2,000,000

The number of delete operations ≤ 20

0 ≤ value of a key ≤ 109

The number of elements in the list does not exceed 106

For a delete, deleteFirst or deleteLast operation, there is at least one element in the list.

Sample Input 1

7
insert 5
insert 2
insert 3
insert 1
delete 3
insert 6
delete 5

Sample Output 1

6 1 2

Sample Input 2

9
insert 5
insert 2
insert 3
insert 1
delete 3
insert 6
delete 5
deleteFirst
deleteLast

Sample Output 2

1

Template in C
-->


Sample input:
7
insert 5
insert 2
insert 3
insert 1
delete 3
insert 6
delete 5


Sample output:
6 1 2

Submission status: Runtime Error

Solution code:
import sys


class Deque:
    class Node:  # ??????????????????
        def __init__(self, x, y=None, z=None):
            self.key = x
            self.next = y
            self.prev = z

        def search(self, x):  # listSearch??¨???????????????????????????????????????
            if(self.key == x or self.key is None):
                return self
            else:
                return self.prev.search(x)

        def delete(self):
            self.prev.next = self.next
            self.next.prev = self.prev

    def __init__(self):
        self.size = 0
        self.head = Deque.Node(None)
        self.tail = Deque.Node(None, self.head, None)
        self.head.prev = self.tail

    # insert x:??£??????????????????????????????x?????????????´???????????¶????
    def insert(self, x):
        p = Deque.Node(x, self.head, self.head.prev)
        self.head.prev.next = p
        self.head.prev = p
        self.size += 1

    # deleteFirst:??£????????????????????????????´???????????????????
    def deleteFirst(self):
        if self.size == 0:
            raise IndexError
        self.head.prev.delete()
        self.size -= 1

    # deleteLast:??£???????????????????°????????´???????????????????
    def deleteLast(self):
        if self.size == 0:
            raise IndexError
        self.tail.next.delete()
        self.size -= 1

    # ???????????????????????¢?´¢
    def listSearch(self, x):
        return self.head.prev.search(x)

    # ??¢?´¢?????\????£?
    def listSearch2(self, x):
        node = self.tail.next
        while(node.key is not None):
            if(node.key == x):
                return node
            else:
                node = node.next

    # delete:x???????????????????´??????????????????°?????¢?´¢????????¨
    def delete(self, x):
        if self.size == 0:
            raise IndexError
        node = self.listSearch(x)
        if(node.key is not None):
            node.delete()
        self.size -= 1

    # ??????
    def printList(self):
        ret = []
        node = self.head.prev
        while node.key is not None:
            ret.append(str(node.key))
            node = node.prev
        print(" ".join(ret))


n = int(input())
d = Deque()
for inpt in sys.stdin.read().splitlines():
    i = inpt.split()
    #print(i)
    if i[0] == "insert":
        x = int(i[1])
        d.insert(x)
    if i[0] == "delete":
        x = int(i[1])
        d.delete(x)
    if i[0] == "deleteFirst":
        d.deleteFirst()
    if i[0] == "deleteLast":
        d.deleteLast()
d.printList()

Submission status: Runtime Error

Solution code:
#ALDS1_3-C Elementary data structures - Doubly Linked List
import collections
q = collections.deque()
cmds={"insert":lambda cmd: q.appendleft(cmd[1]),
      "delete":lambda cmd: q.remove(cmd[1]) if (q.count(cmd[1]) > 0) else "none",
      "deleteFirst":lambda cmd: L.popleft(),
      "deleteLast": lambda cmd: L.pop()
     }

n=int(input())
for i in range(n):
    cmd=input().split()
    cmds[cmd[0]](cmd)
print(*q)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 21 08:50:28 2017

@author: syaga
"""

COMMAND = ["insert", "delete", "deleteFirst", "deleteLast"]

if __name__ == "__main__":
    n = int(input())
    com = []
    for i in range(n):
        com.append(input().split())
    ans = []
    for i in com:
        if i[0] == COMMAND[0]:
            ans.insert(0, i[1])
        elif i[0] == COMMAND[1]:
            ans.remove(i[1])
        elif i[0] == COMMAND[2]:
            ans.pop(0)
        elif i[0] == COMMAND[3]:
            ans.pop()
    print(" ".join(ans))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 21 09:13:28 2017

@author: syaga
"""

COMMAND = ["insert", "delete", "deleteFirst", "deleteLast"]

if __name__ == "__main__":
    n = int(input())
    com = []
    for i in range(n):
        com.append(input().split())
    ans = []
    for i in com:
        if i[0] == COMMAND[0]:
            ans.append(i[1])
        elif i[0] == COMMAND[1]:
            if i[1] in ans:
                ind = ans.index(i[1], -1)
                del ans[ind]
        elif i[0] == COMMAND[2]:
            ans.pop()
        elif i[0] == COMMAND[3]:
            ans.pop(0)
    ans.reverse()
    print(" ".join(ans))

Submission status: Runtime Error

Solution code:
n=int(raw_input())
lst = []
for _ in range(n):
    cmd = raw_input().split()
    if cmd[0] == "insert":
        lst.insert(0, int(cmd[1]))
    elif cmd[0] == "delete":
        lst.remove(int(cmd[1]))
    if cmd[0] == "deleteFirst":
        if len(lst) > 0:
            lst.pop(0)
    if cmd[0] == "deleteLast":
        if len(lst) > 0:
            lst.pop(-1)
print " ".join(map(str,lst))

Submission status: Runtime Error

Solution code:
from collections import deque
n = int(input())
a = deque()
for i in range(n):
    s = input().split(" ")
    if s[0] == "insert":
        a.appendleft(int(s[1]))
    elif s[0] == "delete":
        a.remove(int(s[1]))
    elif s[0] == "deleteLast":
        a.pop()
    elif s[0] == "deleteFirst":
        a.popleft()
b = list(a)
for i in range(len(b)):
    if i == len(b)-1:
        print(b[i])
    else:
        print(b[i],end=" ")

Submission status: Runtime Error

Solution code:
from collections import deque
dq = deque()
for _ in [None]*int(input()):
    s = input()
    if s == "deleteFirst":
        dq.popleft()
    elif s == "deleteLast":
        dq.pop()
    else:
        a, b = s.split()
        if a == "insert":
            dq.insert(0, b)
        else:
            dq.remove(b)
print(" ".join(dq))

Submission status: Runtime Error

Solution code:
from collections import deque
dq = deque()
for _ in [None]*int(input()):
    s = input()
    if s == "deleteFirst":
        dq.popleft()
    elif s == "deleteLast":
        dq.pop()
    else:
        a, b = s.split()
        if a == "insert":
            dq.appendleft(b)
        else:
            dq.remove(b)
print(" ".join(dq))

Submission status: Runtime Error

Solution code:
import sys

class Node:
    def __init__(self, num):
        self.prev = None
        self.next = None
        self.num = num
    def delete(self):
        if self.prev is not None:
            self.prev.next = self.next
        if self.next is not None:
            self.next.prev = self.prev
        
class LinkedList:
    def __init__(self):
        self.node_list = []
    def add(self, num):
        node = Node(num)
        node.prev = node_list[-1]
        self.node_list[-1].next = node
        self.node_list.append(node)
    def delete(self, num):
        for node in self.node_list:
            if node.num == num:
                node.delete()
                break
    def delete_first(self):
        self.node_list[0].delete()
        self.node_list.pop(0)
    def delete_last():
        self.node_list[-1].delete()
        self.node_list.pop()
    def __str__(self):
        s = ""
        for n in node_list:
            s += str(n.num) + " "
        s.strip()
        return s
            
def main():
    linked_list = LinkedList()
    c_num = int(sys.stdin.readline().strip())
    for i in range(0, c_num):
        line = sys.stdin.readline().strip().split(" ")
        op = line[0]
        if op == "insert":
            linked_list.add(int(line[1]))
        if op == "delete":
            linked_list.delete(int(line[1]))
        if op == "deleteFirst":
            linked_list.delete_first()
        if op == "deleteLast":
            linked_list.delete_last()
    print str(linked_list)
    
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import sys

class Node:
    def __init__(self, num):
        self.prev = None
        self.next = None
        self.num = num
    def delete(self):
        if self.prev is not None:
            self.prev.next = self.next
        if self.next is not None:
            self.next.prev = self.prev
        
class LinkedList:
    def __init__(self):
        self.node_list = []
    def add(self, num):
        node = Node(num)
        node.prev = self.node_list[-1]
        self.node_list[-1].next = node
        self.node_list.append(node)
    def delete(self, num):
        for node in self.node_list:
            if node.num == num:
                node.delete()
                break
    def delete_first(self):
        self.node_list[0].delete()
        self.node_list.pop(0)
    def delete_last():
        self.node_list[-1].delete()
        self.node_list.pop()
    def __str__(self):
        s = ""
        for n in node_list:
            s += str(n.num) + " "
        s.strip()
        return s
            
def main():
    linked_list = LinkedList()
    c_num = int(sys.stdin.readline().strip())
    for i in range(0, c_num):
        line = sys.stdin.readline().strip().split(" ")
        op = line[0]
        if op == "insert":
            linked_list.add(int(line[1]))
        if op == "delete":
            linked_list.delete(int(line[1]))
        if op == "deleteFirst":
            linked_list.delete_first()
        if op == "deleteLast":
            linked_list.delete_last()
    print str(linked_list)
    
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import sys

def main():
    linked_list = []
    c_num = int(sys.stdin.readline().strip())
    for i in range(0, c_num):
        line = sys.stdin.readline().strip().split(" ")
        op = line[0]
        n = int(line[1])
        if op == "insert":
            linked_list.insert(0, n)
        if op == "delete":
            for (i, num) in enumerate(linked_list):
                if n == num:
                    linked_list.pop(i)
                    break
        if op == "deleteFirst":
            linked_list.pop(0)
        if op == "deleteLast":
            linked_list.pop()
    s = ""
    for i in linked_list:
        s += str(i) + " "
    print s.strip()
    
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import sys

l = []

n = int(sys.stdin.readline().strip())

def delete(lst,x):
	lst.remove(x)

def deleteFirst(lst):
	lst.pop(0)
def deleteLast(lst):
	lst.pop(len(lst)-1)
for i in range(n):
	c = sys.stdin.readline().strip().split(" ")
	if c[0]=="insert":
		l.append(int(c[1]))
	elif c[0]=="delete":
		delete(l,int(c[1]))
	elif c[0]=="deleteFirst":
		deleteFirst(l)
	elif c[0]=="deleteLast":
		deleteLast(l)

for a in l[::-1]:
	print(a),

Submission status: Runtime Error

Solution code:
n = int(input())
array = []
for i in range(n):
    cmd, *key = input().split()
    if type(key) == list:
        for i in key:
            key = i
    if cmd == "insert":
        array.insert(0, key)
    elif cmd == "delete":
        array.remove(key)
    elif cmd == "deleteFirst":
        del array[0]
    else:
        array.pop()
for i in range(len(array)):
    if i == len(array) - 1:
        print(array[i])
    else:
        print(array[i], end=" ")

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
???????????£????????????
??\?????????????????????????????????????????£???????????????????£??????????????????????

insert x: ??£?????????????????????????????? x ?????????????´?????¶?????¶???????
delete x: ?????? x ??????????????????????´??????£????????????????????????????????????????????????????´?????????¨???????????´????????????????????????
deleteFirst?????????????????????????´???????????????????
deleteLast: ????????????????°????????´???????????????????
"""

class Dlist:
    MAX = 1000000
    
    def __init__(self):
        """ ????????????????????? """
        self.si = 0
        self.ei = 0
        self.cnt = 0
        self.data = [0 for r in range(Dlist.MAX)]

    def insert(self,x):
        """ ??£?????????????????????????????? x ?????????????´?????¶?????¶???? """
        self.si -= 1
        if self.si < 0:
            self.si = Dlist.MAX - 1
        self.data[self.si] = x
        self.cnt += 1

    def delete(self,x):
        """ ?????? x ??????????????????????´??????£????????????????????????????????????????????????????´?????????¨???????????´????????????????????????"""
        if self.cnt > 0:
            self.hit = False
            for i in range(self.cnt):
                pi = self.si + i
                if pi >= Dlist.MAX:
                    pi -= Dlist.MAX
                if self.data[pi] == x:
                    hit = True
                    break
            if hit == True:
                for j in range(i, self.cnt):
                    pi = self.si + j
                    if pi >= Dlist.MAX:
                        pi -= Dlist.MAX
                    ni = pi + 1
                    if ni >= Dlist.MAX:
                        ni -= Dlist.MAX
                    self.data[pi] = self.data[ni]
                self.ei -= 1
                if self.ei < 0 :
                    self.ei = Dlist.MAX - 1
                self.cnt -= 1
            
    def deleteFirst(self):
        """ ?????????????????????????´???????????????? """
        if self.cnt > 0:
            self.data[self.si] = 0
            self.si += 1
            if self.si >= Dlist.MAX:
                self.si = 0
            self.cnt -= 1

    def deleteLast(self):
        """ ????????????????°????????´???????????????????"""
        if self.cnt > 0:
            self.ei -= 1
            if self.ei < 0 :
                self.ei = Dlist.MAX - 1
            self.data[self.ei] = 0
            self.cnt -= 1

    def getList(self):
        return self.data[self.si:self.ei]

# ?????????
num = int(input().strip())
dl = Dlist()

for i in range(num):
    cmd = list(input().strip().split())
    if cmd[0] == "insert":
        dl.insert(cmd[1])
    elif cmd[0] == "delete":
        dl.delete(cmd[1])
    elif cmd[0] == "deleteFirst":
        dl.deleteFirst()
    elif cmd[0] == "deleteLast":
        dl.deleteLast()

#    print("cmd={} si={} ei={} cnt={}".format(cmd[0], dl.si, dl.ei, dl.cnt))
#    print(dl.data)

print(" ".join(map(str,dl.getList())))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
???????????£????????????
??\?????????????????????????????????????????£???????????????????£??????????????????????

insert x: ??£?????????????????????????????? x ?????????????´?????¶?????¶???????
delete x: ?????? x ??????????????????????´??????£????????????????????????????????????????????????????´?????????¨???????????´????????????????????????
deleteFirst?????????????????????????´???????????????????
deleteLast: ????????????????°????????´???????????????????
"""

# ?????????
num = int(input().strip())
dl = []

for i in range(num):
    cmd = list(input().strip().split())
    if cmd[0] == "insert":
        dl.insert(0,cmd[1])
    elif cmd[0] == "delete":
        dl.remove(cmd[1])
    elif cmd[0] == "deleteFirst":
        dl.pop(0)
    elif cmd[0] == "deleteLast":
        dl.pop()

print(" ".join(map(str,dl)))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
???????????£????????????
??\?????????????????????????????????????????£???????????????????£??????????????????????

insert x: ??£?????????????????????????????? x ?????????????´?????¶?????¶???????
delete x: ?????? x ??????????????????????´??????£????????????????????????????????????????????????????´?????????¨???????????´????????????????????????
deleteFirst?????????????????????????´???????????????????
deleteLast: ????????????????°????????´???????????????????
"""

# ?????????
num = int(input().strip())
dl = []

for i in range(num):
    cmd = list(input().strip().split())
    if cmd[0] == "insert":
        dl.insert(0,cmd[1])
    elif cmd[0] == "delete":
        try:
            dl.remove(cmd[1])
        except ValueError:
            i = 1
        else:
            raise
    elif cmd[0] == "deleteFirst":
        dl.pop(0)
    elif cmd[0] == "deleteLast":
        dl.pop()

print(" ".join(map(str,dl)))

Submission status: Runtime Error

Solution code:
n = int(input())
data = []

for i in range(n):
	command,x = input().split()
	if command == 'insert':
		data.insert(0,x)
	elif command == 'delete':
		if x in data:
			data.remove(x)
	elif command == 'deleteFirst':
		data.pop(0)
	elif command == 'deleteLast':
		data.pop()

print(*data)

Submission status: Runtime Error

Solution code:
n=int(input())

for i in range(n):
    cmd=input().split()
    if cmd[0]=="insert":
        dl_list.insert(0,cmd[1])
    elif cmd[0]=="delete":
        try:
            dl_list.remove(cmd[1])
        except:
            print("Error")
    elif cmd[0]=="deleteFirst":
        del dl_list[0]
    elif cmd[0]=="deleteLast":
        del dl_list[-1]

print(*dl_list)

Submission status: Runtime Error

Solution code:
n=int(input())

dl_list=[]

for i in range(n):
    cmd=input().split()
    if cmd[0]=="insert":
        dl_list.insert(0,cmd[1])
    elif cmd[0]=="delete":
        try:
            dl_list.remove(cmd[1])
        except:
            pass
    elif cmd[0]=="deleteFirst":
        del dl_list[0]
    elif cmd[0]=="deleteLast":
        del dl_list[-1]

print(" ".join(dl_list)

Submission status: Runtime Error

Solution code:

class DoublyLinkedList:
    def insert(L, key):
        L.insert(0, key)
    
    def delete(L, key):
        idx = L.index(key)
        L.pop(idx)
    
    def deleteFirst(L):
        L.pop(0)
    
    def deleteLast(L):
        L.pop()

N = int(input())
C = []
for i in range(N):
    C.append(input().split())


DLL = DoublyLinkedList()
L = []
for i in C:
    if C[i][0] == "insert":
        DLL.insert(L, C[i][1])
    elif C[i][0] == "delete":
        DLL.delete(L, C[i][1])
    elif C[i][0] == "deleteFirst":
        DLL.deleteFirst(L)
    elif C[i][0] == "deleteLast":
        DLL.deleteLast(L)
    else:
        raise ValueError("Wrong Command")

print(' '.join(map(str, C)))

Submission status: Runtime Error

Solution code:

class DoublyLinkedList:
    def insert(L, key):
        L.insert(0, key)
    
    def delete(L, key):
        idx = L.index(key)
        L.pop(idx)
    
    def deleteFirst(L):
        L.pop(0)
    
    def deleteLast(L):
        L.pop()

N = int(input())
C = []
for i in range(N):
    C.append(input().split())


DLL = DoublyLinkedList()
L = []
for i in C:
    if i[0] == "insert":
        DLL.insert(L, i[1])
    elif i[0] == "delete":
        DLL.delete(L, i[1])
    elif i[0] == "deleteFirst":
        DLL.deleteFirst(L)
    elif i[0] == "deleteLast":
        DLL.deleteLast(L)
    else:
        raise ValueError("Wrong Command")

print(' '.join(map(str, C)))

Submission status: Runtime Error

Solution code:

class DoublyLinkedList:
    def insert(self, L, key):
        L.insert(0, key)
    
    def delete(self, L, key):
        idx = L.index(key)
        L.pop(idx)
    
    def deleteFirst(self, L):
        L.pop(0)
    
    def deleteLast(self, L):
        L.pop()

N = int(input())
C = []
for i in range(N):
    C.append(input().split())

DLL = DoublyLinkedList()
L = []
for i in C:
    if i[0] == "insert":
        DLL.insert(L, int(i[1]))
    elif i[0] == "delete":
        DLL.delete(L, int(i[1]))
    elif i[0] == "deleteFirst":
        DLL.deleteFirst(L)
    elif i[0] == "deleteLast":
        DLL.deleteLast(L)
    else:
        raise ValueError("Wrong Command")

print(' '.join(map(str, L)))

Submission status: Runtime Error

Solution code:
n = int(input())

class cell:
    def __init__(self, data, before, _next):
        self.data = data
        self.before = before
        self._next = _next

def search(ddl, data):
    for ind,item in enumerate(ddl):
        if item.data == data:
            return ind
    return None

def getItem(ddl, index):
    if len(ddl) > index and index >= 0:
        return ddl[index]
    return None

ddl = []
for i in range(n):
    inp = input().split()
    if len(inp) == 2:
        op, data = inp
        data = int(data)
    else: op, data = inp[0], None
    if op == 'insert':
        if len(ddl) == 0:
            _next = None
        else:
            _next = ddl[0]
        c = cell(data, None, _next)
        ddl = [c] + ddl
    elif op == 'delete':
        ind = search(ddl, data)
        if ind != None:
            ddl[ind - 1].next = getItem(ddl, ind + 1)
            if getItem(ddl, ind+1) is not None:
                ddl[ind + 1].prev = getItem(ddl, ind - 1)
            ddl = ddl[:ind] + ddl[ind+1:]
    elif op == 'deleteFirst':
        ddl = ddl[1:]
        ddl[0].prev = None
    elif op == 'deleteLast':
        ddl = ddl[:-1]
        ddl[-1]._next = None

print(' '.join([str(item.data) for item in ddl]))

Submission status: Runtime Error

Solution code:
n = int(input())

class cell:
    def __init__(self, data, before, _next):
        self.data = data
        self.before = before
        self._next = _next

def search(ddl, data):
    for ind,item in enumerate(ddl):
        if item.data == data:
            return ind
    return None

def getItem(ddl, index):
    if len(ddl) > index and index >= 0:
        return ddl[index]
    return None

ddl = []
for i in range(n):
    inp = input().split()
    if len(inp) == 2:
        op, data = inp
        data = int(data)
    else: op, data = inp[0], None
    if op == 'insert':
        if len(ddl) == 0:
            _next = None
        else:
            _next = ddl[0]
        c = cell(data, None, _next)
        ddl = [c] + ddl
    elif op == 'delete':
        ind = search(ddl, data)
        if ind != None:
            ddl[ind - 1].next = getItem(ddl, ind + 1)
            if getItem(ddl, ind+1) is not None:
                ddl[ind + 1].prev = getItem(ddl, ind - 1)
            ddl = ddl[:ind] + ddl[ind+1:]
    elif op == 'deleteFirst':
        ddl = ddl[1:]
        ddl[0].prev = None
    elif op == 'deleteLast':
        ddl = ddl[:-1]
        if len(ddl) != 0:
         ddl[-1]._next = None

print(' '.join([str(item.data) for item in ddl]))

Submission status: Runtime Error

Solution code:
from collections import deque
n = int(input())
deq = deque()
sub_deq = {}
for i in range(n):
    cmd = input()
    if cmd == 'deleteFirst':
        while 1:
            data = deq.pop()
            if data[1]:
                data[1] = 0
                break
    elif cmd == 'deleteLast':
        while 1:
            data = deq.popleft()
            if data[1]:
                data[1] = 0
                break
    else:
        cmd, val = cmd.split()
        if cmd == 'insert':
            data = [val, 1]
            deq.append(data)
            if val not in sub_deq:
                sub_deq[val] = [data]
            else:
                sub_deq[val].append(data)
        elif cmd == 'delete':
            if val in sub_deq:
                deq_v = sub_deq[val]
                while 1:
                    data = deq_v.pop()
                    if data[1]:
                        data[1] = 0
                        break
print(*(data[0] for data in reversed(deq) if data[1]))

Submission status: Runtime Error

Solution code:
from collections import deque
from sys import stdin
n = int(input())
ddl = deque()
for i in stdin:
    inp = i.split()
    if len(inp) == 2:
        op, data = inp
        data = int(data)
    else: op, data = inp[0], None
    if op == 'insert':
        ddl.appendleft(data,)
    elif op == 'delete':
        ddl.remove(data)
    elif op == 'deleteFirst':
        ddl.popleft()
    elif op == 'deleteLast':
        ddl.pop()

print(' '.join([str(item) for item in ddl]))

Submission status: Runtime Error

Solution code:
n = int(raw_input())
linked = []
for i in range(n):
    command  = raw_input()
    if command == 'deleteFirst':
        linked.pop(0)
    elif command == 'deleteLast':
        linked.pop()
    elif 'insert' in command:
        _, num = command.split()
        linked.insert(0, num)
    elif 'delete' in command:
        _, num = command.split()
        try:
            linked.remove(num)
        except exception:
            pass
        
for i in range(len(linked)):
    print linked[i],

Submission status: Runtime Error

Solution code:
n=input()
l=[]
for i in range(int(n)):
    m = input().split()
    if m[0] == "insert":
        l.insert(0, int(m[1]))
        
    elif m[0] == "delete":
        l.remove(int(m[1]))
        
    elif m[0] == "deleteFirst":
        l.pop(0)
        
    else:
        l.pop()
        
if len(l) > 1:
    for i in range(len(l)-1):
        print(l[i],end=" ")

print(l[len(l)-1])

Submission status: Runtime Error

Solution code:
n=input()
l=[]
for i in range(int(n)):
    m = input().split()
    if m[0] == "insert":
        l.insert(0, int(m[1]))
        
    elif m[0] == "delete":
        l.remove(int(m[1]))
        
    elif m[0] == "deleteFirst":
        l.pop(0)
        
    else:
        l.pop()
        
if len(l) > 1:
    [print(l[i],end=" ")for i in range(len(l)-1)]

print(l[len(l)-1])

Submission status: Runtime Error

Solution code:
from collections import deque

n = int(input())
dq = deque()

for _ in range(n):
    command = input().split()
    if command[0] == 'delete':
        dq.remove(int(command[1]))
    elif command[0] == 'insert':
        dq.appendleft(int(command[1]))
    elif command[0] == 'deleteFirst':
        dq.popleft()
    else:
        dq.pop()

print(*list(dq))

Submission status: Runtime Error

Solution code:
N = int(input())

Commands = []
for i in range(N):
    c, n = input().strip().split()
    Commands.append([c, int(n)])

A = []
for c in Commands:
    if c[0] == 'insert':
        A.insert(0, c[1])
    elif c[0] == 'delete':
        A.remove(c[1])
    elif c[0] == 'deleteFirst':
        A.delete(0)
    elif c[0] == 'deleteLast':
        A.delete(len(A))
    else:
        'error'

print(*A)

Submission status: Runtime Error

Solution code:
N = int(input())

Commands = []
for i in range(N):
    l = input().split()
    if len(l) > 1:
        Commands.append([l[0], int(l[1])])
    else:
        Commands.append([l[0]])

A = []
for c in Commands:
    if c[0] == 'insert':
        A.insert(0, c[1])
    elif c[0] == 'delete':
        A.remove(c[1])
    elif c[0] == 'deleteFirst':
        del A[0]
    elif c[0] == 'deleteLast':
        del A[-1]
    else:
        'error'

print(*A)

Submission status: Runtime Error

Solution code:
from collections import deque
queue = deque([])
n = int(input())
for _ in range(n):
    command = input()
    if command == "deleteFirst":
        _ = queue.popleft()
    elif command == "deleteLast":
        _ = queue.pop()
    elif "delete" in command:
        queue.remove(command[-1])
    else:
        queue.appendleft(command[-1])
print(" ".join(queue))

Submission status: Runtime Error

Solution code:
from collections import deque
queue = deque([])
n = int(input())
for _ in range(n):
    command = input()
    if command == "deleteFirst":
        _ = queue.popleft()
    elif command == "deleteLast":
        _ = queue.pop()
    elif "delete" in command:
        _, x = command.split()
        queue.remove(x)
    else:
        _, x = command.split()
        queue.appendleft(x)
print(" ".join(queue))

Submission status: Runtime Error

Solution code:
def order_each(orders):
    import sys
    linked = []
    for i in orders:
        order = i[0]
        if order == "insert":
            linked.insert(0, i[1])
        elif order == "delete":
            linked.remove(i[1])
        elif order == "deleteFirst":
            linked.pop(0)
        elif order == "deleteLast":
            linked.pop()

    print(' '.join(linked))


orders = []

n = int(input())

for i in range(n):
    orders.append(list(input().split()))

order_each(orders)

Submission status: Runtime Error

Solution code:
def order_each(orders):
    from collections import deque
    linked = deque([])
    for i in orders:
        order = i[0]
        if order == "insert":
            linked.appendleft(i[1])
        elif order == "delete":
            linked.remove(i[1])
        elif order == "deleteFirst":
            linked.popleft()
        elif order == "deleteLast":
            linked.pop()

    print(' '.join(linked))


orders = []

n = int(input())

for i in range(n):
    orders.append(list(input().split()))

order_each(orders)

Submission status: Runtime Error

Solution code:
NEXT = 2
DATA = 1
PREV = 0
def dll_processor(operations):

    front = None
    end = None

    for o in operations:
        if o[0] == "insert":
            front, end = insert(front, end, o[1])
        elif o[0] == "delete":
            front, end = delete(front, end, o[1])
        elif o[0] == "deleteFirst":
            front, end = delete_first(front, end)
        elif o[0] == "deleteLast":
            front, end = delete_last(front, end)
        #print(get_list(front))

    return get_list(front)

def get_list(front):
    if not front:
        return []

    l = []
    target = front
    while True:
        l.append(target[DATA])
        if not target[NEXT]:
            break
        target = target[NEXT]
    return l

def insert(front, end, target):
    node = [None, target, None]
    if front:
        front[PREV] = node
        node[NEXT] = front
        return node, end
    else:
        return node, node

def delete(front, end,target):

    delete_node = front
    while not delete_node[DATA] == target:
        delete_node = delete_node[NEXT]
        if delete_node == None:
            return front, end

    if delete_node[PREV] == None:
        delete_node[NEXT][PREV] = None
        return delete_node[NEXT], end
    elif delete_node[NEXT] == None:
        delete_node[PREV][NEXT] = None
        return front, delete_node[PREV]
    else:
        delete_node[NEXT][PREV] = delete_node[PREV]
        delete_node[PREV][NEXT] = delete_node[NEXT]
        return front, end

def delete_last(front, end):

    if not end[PREV]:
        return None, None
    else:
        end[PREV][NEXT] = None
        return front, end[PREV]

def delete_first(front, end):

    if not front[NEXT]:
        return None, None
    else:
        front[NEXT][PREV] = None
        return front[NEXT], end

def main():
    n_list = int(input())
    target_list = [input().split() for i in range(n_list)]
    print(*dll_processor(target_list))

if __name__ ==