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
import time
class NodeList:

    class Node:
        def __init__(self, left, x, right):
            self.key = x
            self.right = right
            self.left = left
        
        def __repr__(self):
            return str(self.key) 
        
        def printDetail(self):
            print(str(self.left) + ' ' + str(self) + ' ' + str(self.right))

    def __init__(self):
        self.head = NodeList.Node(None,None,None)
        self.head.right = self.head
        self.head.left = self.head
    
    def insert(self, x):
        newNode = NodeList.Node(None, x, None)
        newNode.right = self.head.right
        newNode.right.left = newNode
        self.head.right = newNode
        newNode.left = self.head


    def print(self):
        point = self.head.right 
        start = self.head.right
        flag = False
        while point != self.head:
            sys.stdout.write(str(point))
            if point.right:
                point = point.right
            if flag and point == start:
                break
            if point != self.head:
                sys.stdout.write(' ')
            flag = True
        sys.stdout.write('\n')

    def printAll(self):
        print(self.head)
        point = self.head.right
        while point != self.head:
            point.printDetail()
            point = point.right
            
        sys.stdout.write('\n')

    def delete(self,point):
        point.right.left = point.left
        point.left.right = point.right

    def searchDelete(self, x):
        point = self.head.right
        while point != self.head:
            if point.key == x:
                break
            point = point.right
        self.delete(point)

    def deleteFirst(self):
        self.delete(self.head.right)
    
    def deleteLast(self):
        point = self.head
        while point.right != self.head:
            point = point.right
        #print(point.key)
        #time.sleep(3)
        self.delete(point)

from sys import stdin
node = NodeList()
n = int(input())
for i in range(n):
    #print(i)
    query = stdin.readline().split()
    if query[0][0] == 'i':
        node.insert(int(query[1]))
    elif query[0][0] == 'd':
        node.searchDelete(int(query[1]))
    elif query[0][6] == 'F':
        node.deleteFirst()
    elif query[0][6] == 'L':
        node.deleteLast()

node.print()

Submission status: Runtime Error

Solution code:
import sys
import time
class NodeList:

    class Node:
        def __init__(self, left, x, right):
            self.key = x
            self.right = right
            self.left = left
        
        def __repr__(self):
            return str(self.key) 
        
        def printDetail(self):
            print(str(self.left) + ' ' + str(self) + ' ' + str(self.right))

    def __init__(self):
        self.head = NodeList.Node(None,None,None)
        self.head.right = self.head
        self.head.left = self.head
    
    def insert(self, x):
        newNode = NodeList.Node(None, x, None)
        newNode.right = self.head.right
        newNode.right.left = newNode
        self.head.right = newNode
        newNode.left = self.head


    def print(self):
        point = self.head.right 
        start = self.head.right
        flag = False
        while point != self.head:
            sys.stdout.write(str(point))
            if point.right:
                point = point.right
            if flag and point == start:
                break
            if point != self.head:
                sys.stdout.write(' ')
            flag = True
        sys.stdout.write('\n')

    def printAll(self):
        print(self.head)
        point = self.head.right
        while point != self.head:
            point.printDetail()
            point = point.right
            
        sys.stdout.write('\n')

    def delete(self,point):
        point.right.left = point.left
        point.left.right = point.right

    def searchDelete(self, x):
        point = self.head.right
        while point != self.head:
            if point.key == x:
                break
            point = point.right
        self.delete(point)

    def deleteFirst(self):
        self.delete(self.head.right)
    
    def deleteLast(self):
        point = self.head
        while point.right != self.head:
            point = point.right
        #print(point.key)
        #time.sleep(3)
        self.delete(point)

from sys import stdin
node = NodeList()
n = int(input())
for i in range(n):
    #print(i)
    query = stdin.readline().split()
    c = list(query[0])
    if c[0] == 'i':
        node.insert(int(query[1]))
    elif c[0] == 'd':
        node.searchDelete(int(query[1]))
    elif c[6] == 'F':
        node.deleteFirst()
    elif c[6] == 'L':
        node.deleteLast()

node.print()

Submission status: Runtime Error

Solution code:
n = int(input())
A = [list(map(str,input().split())) for _ in range(n)]
B = []

for i in range(n):
    if A[i][0] == 'insert':
        B.insert(0,int(A[i][1]))
    elif A[i][0] == 'delete':
        B.remove(int(A[i][1]))
    elif A[i][0] == 'deleteFirst':
        del B[0]
    elif A[i][0] == 'deleteLast':
        del B[-1]
  

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

Submission status: Runtime Error

Solution code:
class Node:
	def __init__(self, key):
		self._key = key
		self._prev = None 
		self._next = None

def list_search(head, key):
	cur = head._next
	while cur._key != None and cur._key != key:
		cur = cur._next 
	return cur 

def initiation():
	head = Node(None)
	head._prev = head 
	head._next = head
	return head  

def delete_node(node):
	if node._key == None:
		return 
	node._prev._next = node._next 
	node._next._prev = node._prev 
	node._prev = node._next = node._key = None

def deleteFirst(head):
	delete_node(head._next)

def deleteLast(head):
	delete_node(head._prev)

def delete(head, key):
	delete_node(list_search(head, key))

def insert(head, x):
	node = Node(x)
	node._next = head._next 
	head._next._prev = node 
	node._prev = head 
	head._next = node 



if __name__ == "__main__":
	num_command = int(input())
	head = initiation()
	for i in range(num_command):
		command = input().split()
		order = command[0]
		if order == 'insert':
			value = command[1]
			insert(head, value)
		elif order == 'delete':
			value = command[1]
			delete(head, value)
		elif order == 'deleteFirst':
			deleteFirst(head)
		else:
			deleteLast(head)
	cur = head._next 
	while cur._next._key != None
		print(str(cur._key), end = ' ')
		cur = cur._next
	print(str(cur._key))

Submission status: Runtime Error

Solution code:
from collections import deque

n = int(input())
d = deque()
for _i in range(n):
    line = input().split()
    order = line[0]
    if order in ('insert', 'delete'):
        key = int(line[1])
    if order == 'insert':
        d.appendleft(key)
    elif order == 'delete':
        d.remove(key)
    elif order == 'deleteFirst':
        d.popleft()
    elif order == 'deleteLast':
        d.pop()
    else:
        raise ValueError('Invalid order: {order}')

i = 0
while True:
    try:
        if i == 0:
            print(d.popleft(), end='')
        else:
            print(f' {d.popleft()}', end='')
        i += 1
    except IndexError:
        break
print()

Submission status: Runtime Error

Solution code:
n = int(input())
cmds = [input().split(' ') for _ in range(n)]

dl_list = []
for cmd in cmds:
    if cmd[0] == 'insert':
        dl_list.insert(0, int(cmd[1]))
    elif cmd[0] == 'delete':
        dl_list.remove(int(cmd[1]))
    elif cmd[0] == 'deleteFirst':
        del dl_list[0]
    elif cmd[0] == 'deleteLast':
        del dl_list[-1]

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

Submission status: Runtime Error

Solution code:
n = int(input())
l = []
for i in range(n):
    c, d = input().split()
    if c[0] == 'i':
        l.append(d)
    else:
        l.remove(d)

print(" ".join(sorted(l)))

Submission status: Runtime Error

Solution code:
n = int(input())
l = []
for i in range(n):
    s = input()
    if s == "deleteFirst":
        l.pop(0)
        continue
    if s == "deleteLast":
        l.pop()
        continue

    c, d = s.split()
    if c == 'insert':
        l.append(d)
    elif c == "delete":
        l.remove(d)

print(" ".join(l[::-1]))

Submission status: Runtime Error

Solution code:
class Node:
    def __init__(self, d, next):
        self.d = d
        self.next = next

    def __str__(self):
        if self.next is None:
            return "(" + self.d + ")"
        else:
            return "(" + self.d + "," + str(self.next) + ")"

# import time

n = int(input())
node = None
for i in range(n):
    # time.sleep(0.1)
    s = input()
    # print(s)
    if s == "deleteFirst":
        node = node.next
    elif s == "deleteLast":
        if node.next is None:
            node = None
        n = node
        while n.next.next is not None:
            n = n.next
        n.next = None
    else:
        c, d = s.split()
        if c == 'insert':
            n = Node(d, node)
            n.next = node
            node = n
        elif c == "delete":
            n = node
            if n.d == d:
                node = n.next
            else:
                while n.next is not None:
                    if n.next.d == d:
                        n.next = n.next.next
                        break
                    n = n.next
    # print(node)

while node.next is not None:
    d = node.d
    print(d, "", end="")
    node = node.next
print(node.d)

Submission status: Runtime Error

Solution code:
class Node():
    def __init__(self,value,prv,nxt):
        self.value = value
        self.prv = prv
        self.nxt = nxt

class LinkedList():

    def __init__(self,head,tail):
        self.head = head
        self.tail = tail

    def insert(self,value):
        if self.head == None:
            self.head = Node(value,None,None)
            self.tail = self.head
        else:
            node = Node(value,None,self.head)
            if self.head.nxt == self.tail: #when only one node exists.
                self.head.prv = node
                self.head = node
            else:
                self.head.prv = node
                self.head = node

    def delete(self,value):
        check_node = self.head
        while True:
            if check_node.value == value:
                if check_node.nxt == None:
                    self.deleteLast()
                else:
                    check_node.prv.nxt = check_node.nxt
                    check_node.nxt.prv = check_node.prv
                break
            else:
                check_node = check_node.nxt

    def deleteFirst(self):
        if self.head.nex == None:
            self.head == None
        else:
            self.head = self.head.nxt

    def deleteLast(self):
        self.tail.prv.nxt = None
        self.tail = self.tail.prv

n = int(input())
linkedList = LinkedList(None,None)

def getAnswer(linkedList):
    answer = []
    check = linkedList.head
    while True:
        answer.append(check.value)
        if check.nxt == None:
            break
        else:
            check = check.nxt

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

for _ in range(n):
    line = input()
    if not (line == "deleteFirst" and line == "deleteLast"):
        command = line.split(" ")[0]
        value = int(line.split(" ")[1])
    else:
        command = line

    if command == "insert":
        linkedList.insert(value)
    elif command == "delete":
        linkedList.delete(value)
    elif command == "deleteFirst":
        linkedList.deleteFirst()
    elif command == "deleteLast":
        linkedList.deleteLast()

getAnswer(linkedList)

Submission status: Runtime Error

Solution code:
class Node():
    def __init__(self,value,prv,nxt):
        self.value = value
        self.prv = prv
        self.nxt = nxt

class LinkedList():

    def __init__(self,head,tail):
        self.head = head
        self.tail = tail

    def insert(self,value):
        if self.head == None:
            self.head = Node(value,None,None)
            self.tail = self.head
        else:
            node = Node(value,None,self.head)
            if self.head.nxt == self.tail: #when only one node exists.
                self.head.prv = node
                self.head = node
            else:
                self.head.prv = node
                self.head = node

    def delete(self,value):
        check_node = self.head
        while True:
            if check_node.value == value:
                if check_node == self.tail:
                    self.deleteLast()
                elif check_node == self.head:
                    self.head = check_node.nxt
                    check_node.nxt.prv = None
                else:
                    check_node.prv.nxt = check_node.nxt
                    check_node.nxt.prv = check_node.prv
                break
            else:
                check_node = check_node.nxt

    def deleteFirst(self):
        if self.head.nxt == None:
            self.head == None
        else:
            self.head = self.head.nxt

    def deleteLast(self):
        self.tail.prv.nxt = None
        self.tail = self.tail.prv

n = int(input())
linkedList = LinkedList(None,None)

def getAnswer(linkedList):
    answer = []
    check = linkedList.head
    while True:
        answer.append(check.value)
        if check.nxt == None:
            break
        else:
            check = check.nxt

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

for _ in range(n):
    line = input()
    #print(line)
    if not line == "deleteFirst" and not line == "deleteLast":
        command = line.split(" ")[0]
        value = int(line.split(" ")[1])
    else:
        command = line

    if command == "insert":
        linkedList.insert(value)
    elif command == "delete":
        linkedList.delete(value)
    elif command == "deleteFirst":
        linkedList.deleteFirst()
    elif command == "deleteLast":
        linkedList.deleteLast()

    #getAnswer(linkedList)

getAnswer(linkedList)

Submission status: Runtime Error

Solution code:
n = int(input())
a = [input() for _ in range(n)]
queue = []

for command in a:
    if 'insert 'in command:
        queue.append(command.replace('insert ', ''))
    elif 'delete 'in command:
        queue.remove(command.replace('delete ', ''))

print(' '.join(map(str, reversed(queue)))

Submission status: Runtime Error

Solution code:
from collections import deque
n = int(input())
a = [input() for _ in range(n)]
queue = deque()

for command in a:
    if 'insert 'in command:
        queue.append(command.replace('insert ', ''))
    elif 'delete 'in command:
        queue.remove(command.replace('delete ', ''))
    elif 'deleteFirst' in command:
        queue.popleft()
    elif 'deleteLast' in command:
        queue.pop()

print(' '.join(map(str, reversed(queue))))

Submission status: Runtime Error

Solution code:
class Node:
    def __init__(self, key, prev, next):
        self.key = key
        self.prev = prev
        self.next = next
    

class MyDLL:
    def __init__(self):
        self.linkedlist = []
        self.length = 0
    
    def isEmpty(self):
        if self.length==0:
            return True
        return False
    
    def insert(self, x):
        # 連結リストの先頭にキー x を持つ要素を継ぎ足す。
        if self.isEmpty():
            # 連結リストが空の時
            new = Node(x, None, None)
            self.linkedlist.insert(0, new)         
        else:
            # 連結リストが空ではない時
            old = self.linkedlist[0] # 今まで先頭にいたノード
            new = Node(x, None, old) # 新しく先頭になるノード
            old.prev = new           # 今まで先頭にいたノードの前に新しいノードを登録
            self.linkedlist.insert(0, new)
        self.length += 1 # 連結リストの長さを更新

    def delete(self, x):
        # キー x を持つ最初の要素を連結リストから削除する。そのような要素が存在しない場合は何もしない。
        for node in self.linkedlist:
            if node.key==x:# キー x を持つ最初の要素    
                if node.prev is None:# 先頭だった時
                    node.next.prev = None # 次の要素の前の要素をNoneにする
                elif node.next is None:# 最後尾だった時
                    node.prev.next = None
                else:# 途中だった時
                    prev_node = node.prev
                    next_node = node.next
                    prev_node.next = next_node
                    next_node.prev = prev_node
                self.linkedlist.remove(node)# listから削除      
                break # キーxを持つ最初だけで良いのでbreak
        
    def deleteFirst(self):
        # リストの先頭の要素を削除する。
        if not self.isEmpty():
            first = self.linkedlist.pop(1)
            if self.length>1:
                first.next.prev = None
        else:
            print("List is empty")
        
    def deleteLast(self):
        # リストの末尾の要素を削除する。        
        if not self.isEmpty():
            last = self.linkedlist.pop()
            if self.length>1:
                last.prev.next = None
        else:
            print("List is empty")
        


def main():
    n = int(input())
    commands = [input().split() for i in range(n)]
    commands = [{'order': order, 'value': int(value)} for order, value in commands]
    dll = MyDLL()
    for c in commands:        
        if c['order']=='insert':
            dll.insert(c['value'])
        elif c['order']=='delete':
            dll.delete(c['value'])
        elif c['order']=='deleteFirst':
            dll.deleteFirst()
        elif c['order']=='deleteLast':
            dll.deleteLast()
    print(' '.join([str(node.key) for node in dll.linkedlist]))

main()

Submission status: Runtime Error

Solution code:
class Node:
    def __init__(self, key, prev, next):
        self.key = key
        self.prev = prev
        self.next = next
    

class MyDLL:
    def __init__(self):
        self.linkedlist = []
        self.length = 0
    
    def isEmpty(self):
        if self.length==0:
            return True
        return False
    
    def insert(self, x):
        # 連結リストの先頭にキー x を持つ要素を継ぎ足す。
        if self.isEmpty():
            # 連結リストが空の時
            new = Node(x, None, None)            
        else:
            # 連結リストが空ではない時
            old = self.linkedlist[0] # 今まで先頭にいたノード
            new = Node(x, None, old) # 新しく先頭になるノード
            old.prev = new           # 今まで先頭にいたノードの前に新しいノードを登録
        self.linkedlist.insert(0, new)
        self.length += 1 # 連結リストの長さを更新

    def delete(self, x):
        # キー x を持つ最初の要素を連結リストから削除する。そのような要素が存在しない場合は何もしない。
        for node in self.linkedlist:
            if node.key==x:# キー x を持つ最初の要素    
                if node.prev is None:# 先頭だった時
                    node.next.prev = None # 次の要素の前の要素をNoneにする
                elif node.next is None:# 最後尾だった時
                    node.prev.next = None
                else:# 途中だった時
                    prev_node = node.prev
                    next_node = node.next
                    prev_node.next = next_node
                    next_node.prev = prev_node
                self.linkedlist.remove(node)# listから削除 
                self.length -= 1     
                break # キーxを持つ最初だけで良いのでbreak
        
    def deleteFirst(self):
        # リストの先頭の要素を削除する。
        if not self.isEmpty():
            first = self.linkedlist.pop(0)
            if self.length>1:
                first.next.prev = None
            self.length -= 1 
        else:
            print("List is empty")
        
    def deleteLast(self):
        # リストの末尾の要素を削除する。        
        if not self.isEmpty():
            last = self.linkedlist.pop()
            if self.length>1:
                last.prev.next = None
            self.length -= 1 
        else:
            print("List is empty")
        
    def print(self):
        if not self.isEmpty():
            print(' '.join([node.key for node in self.linkedlist]))
        else:
            print('')

def main():
    input()
    n = 1786329# int(input())
    commands = (input() for i in range(n)) # generator式リスト内包表記
    # commands = ({'order': c[0], 'value': c[1]} if len(c)==2 else {'order': c[0]} for c in commands)
    dll = MyDLL()
    # for c in commands:
    #     if c['order']=='insert':
    #         dll.insert(c['value'])
    #     elif c['order']=='delete':
    #         dll.delete(c['value'])
    #     elif c['order']=='deleteFirst':
    #         dll.deleteFirst()
    #     elif c['order']=='deleteLast':
    #         dll.deleteLast()
    #     else:
    #         print("the command dont't exist")
    #         print(c)
    for c in commands:
        if 'insert' in c:
            dll.insert(c.split()[1])
        elif 'deleteFirst' in c:
            dll.deleteFirst()
        elif 'deleteLast' in c:
            dll.deleteLast()
        elif 'delete' in c:
            dll.delete(c.split()[1])
        else:
            print("the command dont't exist")
            print(c)
    dll.print()    


if __name__=='__main__':    
    main()

Submission status: Runtime Error

Solution code:
n = int(input())
commands = [input().split() for _ in range(n)]

l = []
for com in commands:
    val = com[1]
    com = com[0]
    if com=='insert':
        l.insert(0, val)
    elif com=='delete':
        l.remove(val)
    elif com=='deleteFirst':
        l.pop(0)
    elif com=='deleteLast':
        l.pop()
s = ' '.join(l)
print(s)

Submission status: Runtime Error

Solution code:
n = int(input())
commands = [input().split() for _ in range(n)]

l = []
for com in commands:
    if com[0]=='insert':
        l.insert(0, com[1])
    elif com[0]=='delete':
        l.remove(com[1])
    elif com[0]=='deleteFirst':
        l.pop(0)
    elif com[0]=='deleteLast':
        l.pop()
s = ' '.join(l)
print(s)

Submission status: Runtime Error

Solution code:
n = int(input())
commands = [input().split() for _ in range(n)]

l = []
for com in commands:
    print(l)
    if com[0]=='insert':
        l.insert(0, com[1])
    elif com[0]=='delete':
        try:
            l.remove(com[1])
    elif com[0]=='deleteFirst':
        l.pop(0)
    elif com[0]=='deleteLast':
        l.pop()
s = ' '.join(l)
print(s)

Submission status: Runtime Error

Solution code:
from collections import deque

n = int(input())
commands = [input().split() for _ in range(n)]

l = deque([])
for com in commands:
    if com[0]=='insert':
        l.insert(0, com[1])
    elif com[0]=='delete':
        try:
            l.remove(com[1])
        except:
            pass
    elif com[0]=='deleteFirst':
        l.pop(0)
    elif com[0]=='deleteLast':
        l.pop()
s = ' '.join(l)
print(s)

Submission status: Runtime Error

Solution code:
from collections import deque

n = int(input())
commands = [input() for _ in range(n)] # splitとかしてると間に合わない

l = deque()
for com in commands:
    if com[0]=='i':
        l.appendleft(com[7:])
    elif com[6]=='F':
        l.popleft()
    elif com[6]=='L':
        l.pop()
    else:
        l.remove(com[7:])

s = ' '.join(l)
print(s)

Submission status: Runtime Error

Solution code:
class Node:
    def __init__(self, key):
        self.key = key
        self.prev = None
        self.next = None
    

class MyDLL:
    def __init__(self):
        # 番兵：仮想的な先頭
        self.sentinel = Node(None)
        self.sentinel.prev = self.sentinel
        self.sentinel.next = self.sentinel
    
    def insert(self, x):
        # 連結リストの先頭にキー x を持つ要素を継ぎ足す。
        new = Node(x)
        new.next = self.sentinel.next # 新しく先頭.next = 番兵.next = 今まで先頭
        self.sentinel.next.prev = new # 番兵.next.prev = 今まで先頭.prev = 新しく先頭
        self.sentinel.next = new      # 番兵.next = 新しく先頭
        new.prev = self.sentinel      # 新しく先頭.prev = 番兵

    def listSearch(self, x):
        cursor = self.sentinel.next # 番兵の次の要素から巡る
        while (cursor != self.sentinel) & (cursor.key != x):
            cursor = cursor.next
        return cursor
    
    def deleteNode(self, node):
        # あるノードを削除するとき
        # 例 A - B - C でBを削除
        if node!=self.sentinel: # Bは番兵ではないことを確認
            node.prev.next = node.next # B.prev.next = A.next = B.next = C
            node.next.prev = node.prev # B.next.prev = C.prev = B.prev = A

    def deleteKey(self, x):
        self.deleteNode(self.listSearch(x))
        
    def deleteFirst(self):
        # リストの先頭の要素を削除する。
        self.deleteNode(self.sentinel.next)
        
    def deleteLast(self):
        # リストの末尾の要素を削除する。        
        self.deleteNode(self.sentinel.prev)
        
    def print(self):
        cursor = self.sentinel.next
        count = 0
        while cursor != self.sentinel:
            if count==0:
                print(cursor.key)
            else:
                print(' '+ cursor.key)
            count +=1
            cursor = cursor.next   


def main():
    input()
    n = 1786329# int(input())
    # n = int(input())
    commands = (input() for i in range(n)) # generator式リスト内包表記
    dll = MyDLL()
    for c in commands:
        if 'insert' in c:
            dll.insert(c.split()[1])
        elif 'First' in c:
            dll.deleteFirst()
        elif 'Last' in c:
            dll.deleteLast()
        elif 'delete' in c:
            dll.deleteKey(c.split()[1])
        else:
            print("the command dont't exist")
            print(c)
    dll.print()

main()

Submission status: Runtime Error

Solution code:
from collections import deque
n = int(input())
dList = deque()

for _ in range(n):
  op = list(map(str,input().split()))
  if(op[0] == "insert"):
    dList.appendleft(op[1])
  elif(op[0] == "delete"):
    try:
        dList.remove(op[1])
    except:
        pass
  elif(op[0] == "deleteFirst"):
    dList.popleft()
  elif(op[0] == "deleteLast") :
    dList.pop()

print(*dList[1])

Submission status: Runtime Error

Solution code:
from collections import deque

n = int(input())

dlist = deque()

for i in range(n):
    arr = input().split()
    cmd = ''
    key = 0
    cmd = arr[0]
    if len(arr) > 1:
        key = arr[1]
    if cmd == 'insert':
        dlist.appendleft(key)
    elif cmd == 'delete':
        try:
            dlist.remove(key)
        except:
            #
    elif cmd == 'deleteFirst':
        dlist.pop()
    elif cmd == 'deleteLast':
        dlist.popleft()

print(' '.join(dlist))

Submission status: Runtime Error

Solution code:
array = []
def func_insert(num):
    array.insert(0, num)

def func_delete(num):
    array.remove(num)

def func_deleteFirst():
    array.pop(0)

def func_deleteLast():
    array.pop()


n = int(input())
for _ in range(n):
    command, key = input().split()
    if command == 'insert':
        func_insert(key)

    elif command == 'delete':
        func_delete(key)

    elif command == 'deleteFirst':
        func_deleteFirst()

    else:
        func_deleteLast()

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

Submission status: Runtime Error

Solution code:
array = []
def func_insert(num):
    array.insert(0, num)

def func_delete(num):
    array.remove(num)

def func_deleteFirst():
    array.pop(0)

def func_deleteLast():
    array.pop()


n = int(input())
for _ in range(n):
    command = input().split()
    if command[0] == 'insert':
        func_insert(command[1])

    elif command[0] == 'delete':
        func_delete(command[1])

    elif command[0] == 'deleteFirst':
        func_deleteFirst()

    else:
        func_deleteLast()

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

Submission status: Runtime Error

Solution code:
n = input()
array = []
for i in range(n):
	inst = raw_input().split()
	if inst[0] == "insert":
		array.insert(0,inst[1])
	if inst[0] == "delete":
		array.remove(inst[1])
	if inst[0] == "deleteFirst":
		del array[0]
	if inst[0] == "deleteLast":
		del array[len(array)-1]
print " ".join(i for i in array)

Submission status: Runtime Error

Solution code:
n = input()
array = []
for i in range(n):
	inst = raw_input().split()
	if inst[0] == "insert":
		array.insert(0,inst[1])
	if inst[0] == "delete":
		if inst[1] in array:
			array.remove(inst[1])
	if inst[0] == "deleteFirst":
		array.pop[0]
	if inst[0] == "deleteLast":
		array.pop([len(array)-1])
print " ".join(i for i in array)

Submission status: Runtime Error

Solution code:
n = input()
array = []
for i in range(n):
	inst = raw_input().split()
	if inst[0] == "insert":
		array.insert(0,inst[1])
	if inst[0] == "delete":
		if inst[1] in array:
			array.remove(inst[1])
	if inst[0] == "deleteFirst":
		array.pop[0]
	if inst[0] == "deleteLast":
		array.pop(len(array)-1)
print " ".join(i for i in array)

Submission status: Runtime Error

Solution code:
from collections import deque
import sys

dlist = deque()

func = {'insert':dlist.appendleft, 'delete':dlist.remove, 'deleteFirst':dlist.popleft, 'deleteLast':dlist.pop}

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

for line in sys.stdin:
    command = line.split()
    if len(command) == 2:
        command[1] = int(command[1])
    func[command[0]](*command[1:])

print(*dlist)

Submission status: Runtime Error

Solution code:
n=int(raw_input())
l = []
for x in xrange(n):
    cmd, a = raw_input().split()
    cmd = str(cmd)
    a = int(a)
    if cmd is "insert":
        l.insert(0, a)
    elif cmd is "delete":
        l.pop(a)
    elif cmd is "deleteFirst":
        l.pop(0)
    elif cmd is "deleteLast":
        l.pop()
print l

Submission status: Runtime Error

Solution code:
n=int(raw_input())
l = []
for x in xrange(n):
    cmd = raw_input().split()
    cmd = str(cmd[0])
    if cmd is "insert":
        l.insert(0, int(cmd[1])
    elif cmd is "delete":
        l.pop(int(cmd[1])
    elif cmd is "deleteFirst":
        l.pop(0)
    elif cmd is "deleteLast":
        l.pop()
print l

Submission status: Runtime Error

Solution code:
n=int(raw_input())
l = []
for x in xrange(n):
    msg = raw_input().split()
    cmd = str(msg[0])
    if cmd == "insert":
        l.insert(0, int(msg[1]))
    elif cmd == "delete":
        l.pop(int(msg[1]))
    elif cmd == "deleteFirst":
        l.pop(0)
    elif cmd == "deleteLast":
        l.pop()

for x in l:
    print x,

Submission status: Runtime Error

Solution code:
n=int(raw_input())
l = []
for x in xrange(n):
    msg = raw_input().split()
    cmd = msg[0]
    if cmd == "insert":
        l.insert(0, msg[1])
    elif cmd == "delete":
        l.remove(msg[1])
    elif cmd == "deleteFirst":
        l.pop(0)
    elif cmd == "deleteLast":
        l.pop()

for x in l:
    print int(x),