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:
from collections import deque
import sys

n = int(input())
q = deque()
for i in range(n):
    s = sys.stdin.readlines()
    if s[0] == "i":
        q.appendleft(s[7])
    elif s[6] == "F":
        q.popleft()
    elif s[6] == "L":
        q.pop()
    else:
        try:
            q.remove(s[7])
        except ValueError:
            pass

print(" ".join(q))

Submission status: Runtime Error

Solution code:
class Node:
	elm = None
	next = None
	prev = None

class MyQueue:
	head = tail = None
	def enq(self, x):
		n = Node()
		n.elm = x
		if self.head == None:
			self.head = self.tail = n
		else:
			self.tail.next = n
			n.prev = self.tail
			self.tail = n

	def deq(self):
		if self.head == None:
			return None
		x = self.head.elm
		self.head = self.head.next
		if self.head: self.head.prev = None
		return x

	def pop(self):
		if self.tail == None:
			return None
		x = self.tail.elm
		self.tail = self.tail.prev
		if self.tail: self.tail.next = None
		return x

class MyList:
	head = tail = None
	lookup = {}

	def insert(self, x):
		n = Node()
		n.elm = x
		if self.head == None:
			self.head = self.tail = n
		else:
			n.next = self.head
			self.head.prev = n
			self.head = n
		if not x in self.lookup:
			self.lookup[x] = MyQueue()
		self.lookup[x].enq(n)

	def delete(self, x):
		n = self.lookup[x].deq()
		self.__delete_node(n)

	def deleteFirst(self):
		self.lookup[self.head.elm].deq()
		self.__delete_node(self.head)

	def deleteLast(self):
		self.lookup[self.tail.elm].pop()
		self.__delete_node(self.tail)

	def __delete_node(self, n):
		if n == None: 
			return
		if n == self.head:
			self.head = n.next
		if n == self.tail:
			self.tail = n.prev
		if n.prev:
			n.prev.next = n.next
		if n.next:
			n.next.prev = n.prev

	def __traverse(self):
		n = self.head
		while n:
			yield n.elm
			n = n.next

	def __str__(self):
		return " ".join([str(s) for s in self.__traverse()])

myList = MyList()
n = int(raw_input())
for _ in xrange(n):
	line = raw_input()
	if line[0]=='i':
		myList.insert(int(line[7:]))
	elif line[6]=='F':
		myList.deleteFirst()
	elif line[6]=='L':
		myList.deleteLast()
	else:
		myList.delete(int(line[7:]))
print myList

Submission status: Runtime Error

Solution code:
class MyDLList:
    head = tail = None
    size = 0

    def append_left(self, elm):
        if self.is_empty():
            self.head = self.tail = [elm, None, None]
            # elm, prev, next
        else:
            cur = [elm, None, self.head]
            self.head[1] = cur
            self.head = cur
        self.size += 1

    def is_empty(self):
        return self.size == 0

    def list_search(self, elm):
        cur = self.head
        i = 1
        while i < self.size and cur[0] != elm:
            cur = cur[2]
            i += 1
        if cur[0] != elm:
            cur = None
        return cur

    def delete(self, elm):
        cur = self.list_search(elm)
        if cur:
            if cur == self.head:
                deleted = self.delete_first()
            elif cur == self.tail:
                deleted = self.delete_last()
            else:
                deleted = cur[0]
                cur[1][2] = cur[2]
                cur[2][1] = cur[1]
                self.size -= 1
        else:
            deleted = None
        return deleted

    def delete_first(self):
        cur = self.head
        self.head[2][1] = None
        self.head = self.head[2]
        self.size -= 1
        return cur[0]

    def delete_last(self):
        cur = self.tail
        self.tail[1][2] = None
        self.tail = self.tail[1]
        self.size -= 1
        return cur[0]

    def __str__(self):
        cur = self.head
        result = ""
        while cur != self.tail:
            result += cur[0] + " "
            cur = cur[2]
        result += cur[0]
        return result

n = int(input())

dl = MyDLList()


for i in range(n):
    x = list(map(str, input().split()))
    if x[0] == "insert":
        dl.append_left(x[1])
    elif x[0] == "delete":
        dl.delete(x[1])
    elif x[0] == "deleteFirst":
        dl.delete_first()
    elif x[0] == "deleteLast":
        dl.delete_last()

print(dl)

Submission status: Runtime Error

Solution code:
from collections import deque

if __name__ == '__main__':
    n = int(input())
    L = deque()
    for i in range(n):
        cmd = input().split()

        if cmd[0] == 'insert':
            L.appendleft(cmd[1])
        if cmd[0] == 'delete':
            L.remove(cmd[1])
        if cmd[0] == 'deleteFirst':
            L.popleft()
        if cmd[0] == 'deleteLast':
            L.pop()
    print(*L)

Submission status: Runtime Error

Solution code:
from collections import deque

if __name__ == '__main__':
    n = int(input())
    L = deque()
    for i in range(n):
        cmd = input().split()

        if cmd[0] == 'insert':
            L.appendleft(cmd[1])
        elif cmd[0] == 'delete':
            L.remove(cmd[1])
        elif cmd[0] == 'deleteFirst':
            L.popleft()
        elif cmd[0] == 'deleteLast':
            L.pop()
    print(*L)

Submission status: Runtime Error

Solution code:
from collections import deque

if __name__ == '__main__':
	n = int(input())
	L = deque()

	for i in range(n):
		cmdline = input().split()

		if cmdline[0] == "insert":
			L.appendleft(cmdline[1])
		elif cmdline[0] == "delete":
			L.remove(cmdline[1])
		elif cmdline[0] == "deleteFirst":
			L.popleft()
		elif cmdline[0] == "deleteLast":
			L.pop()

	print(" ".join(L))

Submission status: Runtime Error

Solution code:
def linearSearch(A, key):
    i = 0
    A.append(key)
    while A[i] != key:
        i += 1
    if i == n:
        return False
    return i


if __name__ == '__main__':
    n = int(input())
    S = list(map(int, input().split()))
    q = int(input())
    T = list(map(int, input().split()))
    cnt = 0

    for key in T:
        if linearSearch(S,key) is not False:
            cnt += 1

    print(cnt)

Submission status: Runtime Error

Solution code:
N = int(input())

A = []

for i in xrange(N):
	b= input()
	if (" " in b):
		b, c = b.split()
		c = int(c)
	
	if b == "insert":
		A.insert(0, c)
	elif b == "delete":
		if (c in A):
			A.remove(c)
	elif b == "deleteFirst":
		A.pop(0)
	elif b == "deleteLast":
		A.pop()

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

Submission status: Runtime Error

Solution code:
N = int(input())

A = []
pop = A.pop
remove = A.remove
insert = A.insert
split = b.split

for i in range(N):
	b= input()
	if (" " in b):
		b, c = split()
		c = int(c)
	
	if b == "insert":
		insert(0, c)
	elif b == "delete":
		if (c in A):
			remove(c)
	elif b == "deleteFirst":
		pop(0)
	elif b == "deleteLast":
		pop()

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

Submission status: Runtime Error

Solution code:
from collections in deque

N = int(input())

A = deque()

for i in range(N):
	b= input()
	if b == "deleteFirst":
		A.popleft()
	elif b == "deleteLast":
		A.pop()
	else:
		b, c = b.split()
		c = int(c)
	
		if b == "insert":
			A.appendleft(c)
		elif b == "delete":
			if (c in A):
				A.remove(c)

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

Submission status: Runtime Error

Solution code:
n = int(input())
dll =[]
for i in range(n):
    command = input().split()
    if command[0] == 'insert':
        dll.insert(0, command[1])
    elif command[0] == 'delete':
       # for i in range(len(dll)):
            #if dll[i] == command[1]: 
                #dll.pop(i)
                #break
        indexes = [i for i, x in enumerate(dll) if x == command[1]]
        dll.pop(indexes[0])
    elif command[0] == 'deleteFirst':
        dll.pop(0)
    else:
        dll.pop()

print(*dll)

Submission status: Runtime Error

Solution code:
n = int(input())
dll =[]
for i in range(n):
    command = input().split()
    if command[0] == 'insert':
        dll.insert(0, command[1])
    elif command[0] == 'delete':
       # for i in range(len(dll)):
            #if dll[i] == command[1]: 
                #dll.pop(i)
                #break
        dll.remove(command[1])
    elif command[0] == 'deleteFirst':
        dll.pop(0)
    else:
        dll.pop()

print(*dll)

Submission status: Runtime Error

Solution code:
n = int(input())
dll =[]
for i in range(n):
    command = input().split()
    if command[0] == 'insert':
        dll.insert(0, command[1])
    elif command[0] == 'delete':
        try:
            dll.remove(command[1])
        except:
            pass
    elif command[0] == 'deleteFirst':
        dll.pop(0)
    else:
        dll.pop()
    print(dll[i], sep=" ")
#print(*dll)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

import sys
import os
from collections import deque


N = int(input())
q = deque()

for i in range(N):
    lst = input().split()
    command = lst[0]
    if command == 'insert':
        v = int(lst[1])
        q.appendleft(v)
    elif command == 'delete':
        v = int(lst[1])
        q.remove(v)
    elif command == 'deleteFirst':
        q.popleft()
    elif command == 'deleteLast':
        q.pop()
print(*list(q))

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Here your code !
import sys
n = int(input())
output = []
for i in range(n):
    order,data =input().split() 
    if order == "insert":
        output.append(int(data))
    elif order == "deleteFirst":
        output.pop()
    elif order == "deleteLast":
        output.popleft()
    elif order == "delete":
        try:
            output.remove(int(data))
        except:
            pass
output.reverse()
print(" ".join(map(str,output)))

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Here your code !
n = int(input())
output = []
for i in range(n):
    order,data =input().split() 
    if order == "insert":
        output.append(int(data))
    elif order == "deleteFirst":
        output.pop()
    elif order == "deleteLast":
        output.popleft()
    elif order == "delete":
        try:
            output.remove(int(data))
        except:
            pass
output.reverse()
print(" ".join(map(str,output)))

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Here your code !
import sys

from collections import deque
n = int(input())
output = []
for i in range(n):
    order,data =input().split() 
    if order == "insert":
        output.append(int(data))
    elif order == "deleteFirst":
        output.pop()
    elif order == "deleteLast":
        output.popleft()
    elif order == "delete":
        try:
            output.remove(int(data))
        except:
            pass
output.reverse()
print(" ".join(map(str,output)))

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Here your code !
import sys
from collections import deque
n = int(input())
output = []
for i in range(n):
    order,data =input().split() 
    if order == "insert":
        output.append(int(data))
    elif order == "deleteFirst":
        output.pop()
    elif order == "deleteLast":
        output.popleft()
    elif order == "delete":
        try:
            output.remove(int(data))
        except:
            pass
output.reverse()
print(" ".join(map(str,output)))

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Here your code !
import sys
from collections import deque
n = int(input())
output = []
for i in range(n):
    order,data =input().split() 
    if order == "insert":
        output.append(int(data))
    elif order == "deleteFirst":
        output.pop()
    elif order == "deleteLast":
        output.popleft()
    elif order == "delete":
        try:
            output.remove(int(data))
        except:
            pass
output.reverse()
print(" ".join(output))
#print(" ".join(map(str,output)))

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Here your code !
import sys
from collections import deque
n = int(input())
output = []
for i in range(n):
    order,data =input().split() 
    if order == "insert":
        output.append(int(data))
    elif order == "deleteFirst":
        output.pop()
    elif order == "deleteLast":
        output.popleft()
    elif order == "delete":
        try:
            output.remove(int(data))
        except:
            pass
#output.reverse()
print(" ".join(output))
#print(" ".join(map(str,output)))

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Here your code !
import sys
from collections import deque
n = int(input())
output = []
for i in range(n):
    order,data =input().split() 
    if order == "insert":
        output.append(int(data))
    elif order == "deleteFirst":
        output.pop()
    elif order == "deleteLast":
#        output.popleft()
    elif order == "delete":
        try:
            output.remove(int(data))
        except:
            pass
output.reverse()
print(" ".join(output))
#print(" ".join(map(str,output)))

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Here your code !
import sys
from collections import deque
n = int(input())
output = []
for i in range(n):
    order,data =input().split() 
    if order == "insert":
        output.append(int(data))
    elif order == "deleteFirst":
        output.pop()
    elif order == "deleteLast":
#        output.popleft()
        output.pop()
    elif order == "delete":
        try:
            output.remove(int(data))
        except:
            pass
output.reverse()
print(" ".join(output))
#print(" ".join(map(str,output)))

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Here your code !
import sys
from collections import deque
n = int(input())
output = []
for i in range(n):
    order,data =input().split() 
    if order == "insert":
        output.append(int(data))
    elif order == "deleteFirst":
        output.pop()
    elif order == "deleteLast":
        output.popleft()

    elif order == "delete":
        try:
#            output.remove(int(data))
        except:
            pass
output.reverse()
print(" ".join(output))
#print(" ".join(map(str,output)))

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Here your code !
n = int(input())
output = []
for i in range(n):
    order,data =input().split() 
    if order == "insert":
        output.append(int(data))
    elif order == "deleteFirst":
        output.pop()
    elif order == "deleteLast":
        output.popleft()

    elif order == "delete":
        try:
            output.remove(int(data))
        except:
            pass
output.reverse()
print(" ".join(output))
#print(" ".join(map(str,output)))

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Here your code !
n = int(input())
output = []
for i in range(n):
    order,data =input().split() 
    if order == "insert":
        output.append(int(data))
#    elif order == "deleteFirst":
#        output.pop()
#    elif order == "deleteLast":
#        output.popleft()

#   elif order == "delete":
#        try:
#            output.remove(int(data))
#        except:
#            pass
output.reverse()
print(" ".join(output))
#print(" ".join(map(str,output)))

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Here your code !
n = int(input())
output = []
for i in range(n):
    order,data =input().split() 
#    if order == "insert":
#        output.append(int(data))
#    elif order == "deleteFirst":
#        output.pop()
#    elif order == "deleteLast":
#        output.popleft()

#   elif order == "delete":
#        try:
#            output.remove(int(data))
#        except:
#            pass
output.reverse()
print(" ".join(output))
#print(" ".join(map(str,output)))

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Here your code !
n = int(input())
output = []
for i in range(n):
    order,data =input().split() 
#    if order == "insert":
#        output.append(int(data))
#    elif order == "deleteFirst":
#        output.pop()
#    elif order == "deleteLast":
#        output.popleft()

#   elif order == "delete":
#        try:
#            output.remove(int(data))
#        except:
#            pass
#output.reverse()
print(" ".join(output))
#print(" ".join(map(str,output)))

Submission status: Runtime Error

Solution code:

n = int(input())
output = []
for i in range(n):
    order,data =input().split() 
#    if order == "insert":
#        output.append(int(data))
#    elif order == "deleteFirst":
#        output.pop()
#    elif order == "deleteLast":
#        output.popleft()

#   elif order == "delete":
#        try:
#            output.remove(int(data))
#        except:
#            pass
#output.reverse()
print(" ".join(output))
#print(" ".join(map(str,output)))

Submission status: Runtime Error

Solution code:

n = int(input())
output = []
for i in range(n):
    order,data = input().split() 
#    if order == "insert":
#        output.append(int(data))
#    elif order == "deleteFirst":
#        output.pop()
#    elif order == "deleteLast":
#        output.popleft()

#   elif order == "delete":
#        try:
#            output.remove(int(data))
#        except:
#            pass
#output.reverse()
print(" ".join(output))
#print(" ".join(map(str,output)))

Submission status: Runtime Error

Solution code:

n = int(input())
output = []
for i in range(n):
    order,data = map(str,input().split() )
#    if order == "insert":
#        output.append(int(data))
#    elif order == "deleteFirst":
#        output.pop()
#    elif order == "deleteLast":
#        output.popleft()

#   elif order == "delete":
#        try:
#            output.remove(int(data))
#        except:
#            pass
#output.reverse()
print(" ".join(output))
#print(" ".join(map(str,output)))

Submission status: Runtime Error

Solution code:

n = int(input())
output = []
for i in range(n):
    order,data = map(input().split())
#    if order == "insert":
#        output.append(int(data))
#    elif order == "deleteFirst":
#        output.pop()
#    elif order == "deleteLast":
#        output.popleft()

#   elif order == "delete":
#        try:
#            output.remove(int(data))
#        except:
#            pass
#output.reverse()
print(" ".join(output))
#print(" ".join(map(str,output)))

Submission status: Runtime Error

Solution code:

n = int(input())
output = []
for i in range(n):
    order,data = map(int,input().split())
#    if order == "insert":
#        output.append(int(data))
#    elif order == "deleteFirst":
#        output.pop()
#    elif order == "deleteLast":
#        output.popleft()

#   elif order == "delete":
#        try:
#            output.remove(int(data))
#        except:
#            pass
#output.reverse()
print(" ".join(output))
#print(" ".join(map(str,output)))

Submission status: Runtime Error

Solution code:

n = int(input())
output = []
for i in range(n):
    order = map(str,input().split())
    if order[0] == "insert":
        output.append(int(order[1]))
    elif order[0] == "deleteFirst":
        output.pop()
    elif order[0] == "deleteLast":
        output.popleft()

#   elif order == "delete":
#        try:
#            output.remove(int(data))
#        except:
#            pass
#output.reverse()
print(" ".join(output))
#print(" ".join(map(str,output)))

Submission status: Runtime Error

Solution code:
import collections from deque
dq = deque()
num = int(input())

for i in range(num):
    order = imput().split()

    if com[0] == 'insert':
        dq.appendleft(com[1])
    elif com[0] == 'deleteFirst':
        dq.popleft()
    elif com[0] == 'deleteLast':
        dq.pop()
    else:
        if com[1] in dq:
            dq.remove(com[1])

print(' '.join(dq))

Submission status: Runtime Error

Solution code:
import collections from deque
dq = deque()

for i in range(int(input())):
    order = imput().split()

    if com[0] == 'insert':
        dq.appendleft(com[1])
    elif com[0] == 'deleteFirst':
        dq.popleft()
    elif com[0] == 'deleteLast':
        dq.pop()
    else:
        if com[1] in dq:
            dq.remove(com[1])

print(' '.join(dq))

Submission status: Runtime Error

Solution code:
from collections import deque
dq = deque()

for i in range(int(input())):
    order = imput().split()

    if com[0] == 'insert':
        dq.appendleft(com[1])
    elif com[0] == 'deleteFirst':
        dq.popleft()
    elif com[0] == 'deleteLast':
        dq.pop()
    else:
        if com[1] in dq:
            dq.remove(com[1])

print(' '.join(dq))

Submission status: Runtime Error

Solution code:
from collections import deque
dq = deque()

for i in range(int(input())):
    order = imput().split()

    if order[0] == 'insert':
        dq.appendleft(com[1])
    elif order[0] == 'deleteFirst':
        dq.popleft()
    elif order[0] == 'deleteLast':
        dq.pop()
    else:
        if order[1] in dq:
            dq.remove(com[1])

print(' '.join(dq))

Submission status: Runtime Error

Solution code:
from collections import deque
import sys

dq = deque()
num = int(input())
line = sys.stdin.readlines()

for i in range(num):

    order = line[i].split()
    
    if order[0] == 'insert':
        dq.appendleft(com[1])
    elif order[0] == 'deleteFirst':
        dq.popleft()
    elif order[0] == 'deleteLast':
        dq.pop()
    else:
        if order[1] in dq:
            dq.remove(com[1])

print(' '.join(dq))

Submission status: Runtime Error

Solution code:
#4.4
a = int(input())
val = []

for i in range(0, a):
    tmp = list(input().split())
    if tmp[0] == 'insert':
        val.insert(0, int(tmp[1]))
    elif tmp[0] == 'delete':
        index = val.index(int(tmp[1]))
        val.pop(index)
    elif tmp[0] == 'deleteFirst':
        val.pop(0)
    elif tmp[0] == 'deleteLast':
        val.pop(-1)

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

Submission status: Runtime Error

Solution code:
class MyList(list):
    def __init__(self):
        self.__init__ = list

    def cmd(self,command):
        if command == 'deleteFirst':
            self.pop(0)
        elif command == 'deleteLast':
            self.pop(-1)
        else:
            ope, num = command.split()
            num = int(num)
            if ope == 'insert':
                self.insert(0,num)
            else:
                self.remove(num)


if __name__ == '__main__' :
    l = MyList()
    n = input()
    for i in range(n):
        l.cmd(raw_input())

    for i in range(len(l)-1):
        print l[i],
    print l[-1]

Submission status: Runtime Error

Solution code:
n = input()
l = []
for i in range(int(n)):
	command = input()
	print(command)
	if command[0] == 'i':
		l.insert([(command[6:])])
	else:
		if command[7] == " ":
			if  command[6:] in l:
				l.remove(command[6:])
		else:
			if command[7] == 'L':
				l.pop()
			else:
				l.pop(0)
for i in l[:-1]:
	print(i, end=' ')
print(l[-1])

Submission status: Runtime Error

Solution code:
n = input()
l = []
for i in range(int(n)):
	command = input()
	if command[0] == 'i':
		l.insert([(command[6:])])
	else:
		if command[7] == " ":
			if  command[6:] in l:
				l.remove(command[6:])
		else:
			if command[7] == 'L':
				l.pop()
			else:
				l.pop(0)
for i in l[:-1]:
	print(i, end=' ')
print(l[-1])

Submission status: Runtime Error

Solution code:
n = input()
l = []
for i in range(int(n)):
	command = input()
	print(command)
	if command[0] == 'i':
		l.insert(command[7:])
	else:
		if command[6] == " ":
			if command[7:] in l:
				l.remove(command[7:])
		else:
			if command[7] == 'L':
				l.pop()
			else:
				l.pop(0)
for i in l[:-1]:
	print(i, end=' ')
print(l[-1])

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Here your code !
import collections
s=int(input())
deq =collections.deque()

for i in range(s):
    n=input().split()
    if n[0]=="insert":
        deq.appendleft(n[1])
    elif n[0]=="delete":
        deq.remove(n[1])
    elif n[0]=="deleteFirst":
        deq.popleft()
    elif n[0]=="deleteLast":
        deq.pop()
        
print(" ".join(list(deq)))

Submission status: Runtime Error

Solution code:
from collections import deque

def doubly_lined_list(n, A):
	Q = deque()

	for i in range(n):
		if A[i][0] == 'insert':
			Q.appendleft(A[i][1])
		elif A[i][0] == 'delete':
			Q.remove(A[i][1])
		elif A[i][0] == 'deleteFirst':
			Q.popleft()
		elif A[i][0] == 'deleteLast':
			Q.pop()

	print(' '.join(Q))

if __name__ == '__main__':
	n = int(input())
	A = []

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

	doubly_lined_list(n, A)

Submission status: Runtime Error

Solution code:
def insert_ele(x):
    lin.insert(0,x)
def delete_ele(x):
    lin.remove(x)
def deleteFirst():
    lin.pop(0)
def deleteLast():
    lin.pop()

cnt = input()
lin = []

for i in range(int(cnt)):
    com = input().split()
    if com[0] == "insert":
        insert_ele(int(com[1]))
    if com[0] == "delete":
        delete_ele(int(com[1]))
    if com[0] == "deleteFirst":
        deleteFirst()
    if com[0] == "deleteLast":
        deleteLast()

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

Submission status: Runtime Error

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

for i in range(n):
	cmdline = input().split()

	if cmdline[0] == "insert":
		L.appendleft(cmdline[1])
	elif cmdline[0] == "delete":
		L.remove(cmdline[1])
	elif cmdline[0] == "deleteFirst":
		L.popleft()
	elif cmdline[0] == "deleteLast":
		L.pop()

print(" ".join(L))

Submission status: Runtime Error

Solution code:
#ALDS1_3-C Elementary data structures - Doubly Linked List
n=int(input())
L=[]
for i in range(n):
    cmd=input().split()
    if(cmd[0]=="insert"):
        [cmd[1]]+L
    if(cmd[0]=="delete" and cmd[1] in L):
        L.remove(cmd[1])
    if(cmd[0]=="deleteFirst"):
        L.pop(0)
    if(cmd[0]=="deleteLast"):
        L.pop()
    print(L)
s=""
for i in L:
    s+=i+" "
print(s[:-1])

Submission status: Runtime Error

Solution code:
#ALDS1_3-C Elementary data structures - Doubly Linked List
n=int(input())
cmds={"insert":lambda cmd,L: [cmd[1]]+L,
      "delete":lambda cmd,L: L.remove(cmd[1]),
      "deleteFirst":lambda cmd,L: L.pop(0),
      "deleteLast": lambda cmd,L: L.pop()
     }
L=[]
for i in range(n):
    cmd=input().split()
    L = cmds[cmd[0]](cmd,L)
s=""
for i in L:
    s+=i+" "
print(s[:-1])

Submission status: Runtime Error

Solution code:
#ALDS1_3-C Elementary data structures - Doubly Linked List
n=int(input())
cmds={"insert":lambda cmd: L.insert(0,cmd[1]),
      "delete":lambda cmd: L.remove(cmd[1]),
      "deleteFirst":lambda cmd: L.pop(0),
      "deleteLast": lambda cmd: L.pop()
     }
L=[]
for i in range(n):
    cmd=input().split()
    cmds[cmd[0]](cmd)
s=""
for i in L:
    s+=i+" "
print(s[:-1])

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.next.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.tail.next.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.tail.next
        while node.key is not None:
            ret.append(node.key)
            node = node.next
        print(" ".join(ret))


n = int(input())
d = Deque()
for inpt in sys.stdin.read().splitlines():
    i = inpt.split()
    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()