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:
n=int(input())
dll=[]

for i in range(n):
    line=input()
    d=line.split(" ")
    if d[0]=="insert":
        dll=[int(d[1])]+dll

    elif d[0]=="delete":
        ind=dll.index(int(d[1]))
        dll.pop(ind)

    elif d[0]=="deleteFirst":
        dll.pop(0)
    elif d[0]=="deleteLast":
        dll.pop()

for i in range(len(dll)):
    print(dll[i],end="")
    if i==len(dll)-1:
        print()
    else:
        print(" ",end="")

Submission status: Runtime Error

Solution code:
#! python3
# doubly_linked_list.py

keys = []

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

print(' '.join([str(k) for k in keys]))

Submission status: Runtime Error

Solution code:
def pr(a):
    for i in range(len(a)):
        print(a[i],end="")
        if i == len(a)-1:
            print("")
        else :
            print(" ",end="")

n = int(input())
a = []
for i in range(n):
    x = input().split()
    if x[0] == "insert":
        a.insert(0,int(x[1]))
    elif x[0] == "delete":
        a.remove(int(x[1]))
    elif x[0] == "deleteFirst":
        a.pop(0)
    elif x[0] == "deleteLast":
        a.pop()

pr(a)

Submission status: Runtime Error

Solution code:
from collections import deque
d = deque()
n = int(input())
for i in range(n):
    s = input().split()
    if s[0] == 'insert': d.appendleft(int(s[1])
    elif s[0] =='delete': 
        if s[1] in d:
            d.remove(s[1])
        else: pass
    elif s[0] =='deleteFirst': d.popleft()
    else: d.pop()

  print(*d)

Submission status: Runtime Error

Solution code:
from collections import deque
d = deque()
n = int(input())
for i in range(n):
    s = input().split()
    if str(s[0][6]) =='F': d.popleft()
    elif: str(s[0][6]) =='L':d.pop()
    elif str(s[0][0]) == 'i': d.appendleft(int(s[1]))
    else : 
        if int(s[1]) in d:
            d.remove(int(s[1]))
        else: pass
    
    

print(*d)

Submission status: Runtime Error

Solution code:
from collections import deque
d = deque()
n = int(input())
for i in range(n):
    s = input().split()
    if str(s[0][6]) =='F': d.popleft()
    elif: str(s[0][6]) =='L':d.pop()
    elif str(s[0][0]) == 'i': d.appendleft(int(s[1]))
    else : 
        if int(s[1]) in d:
            d.remove(int(s[1]))
        else: pass
print(*d)

Submission status: Runtime Error

Solution code:
#ALDS_3_C 16D8103010K Ko Okasaki

from collections import deque

def pr(A,n):
    for i in range(n):
        if i!=n-1:
            print(A[i],end=" ")
        else:
            print(A[i])

n=int(input())
que_r=deque()


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

    if s[0]=="insert":
        que_r.appendleft(int(s[1]))
    elif s[0]=="delete":
        que_r.remove(int(s[1]))
    elif s[0]=="deleteFirst":
        gav=que_r.popleft()
    else:
        gav=que_r.pop()

pr(que_r,len(que_r))

Submission status: Runtime Error

Solution code:
from collections import deque

def pr(A,n):
    for i in range(n):
        if i!=n-1:
            print(A[i],end=" ")
        else:
            print(A[i])

n=int(input())
que_r=deque()


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

    if s[0]=="insert":
        que_r.appendleft(int(s[1]))
    elif s[0]=="delete":
        que_r.remove(int(s[1]))
    elif s[0]=="deleteFirst":
        gav=que_r.popleft()
    else:
        gav=que_r.pop()

pr(que_r,len(que_r))

Submission status: Runtime Error

Solution code:
from collections import deque

def pr(A,n):
    for i in range(n):
        if i!=n-1:
            print(A[i],end=" ")
        else:
            print(A[i])

n=int(input())
que_r=deque()
c=0

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

    if s[0]=="insert":
        que_r.appendleft(int(s[1]))
    elif s[0]=="delete" and que_r.count(int(s[1]))==0:
        que_r.remove(int(s[1]))
    elif s[0]=="deleteFirst":
        gav=que_r.popleft()
    else:
        gav=que_r.pop()

pr(que_r,len(que_r))

Submission status: Runtime Error

Solution code:
def pr(A,n):
    for i in range(n):
        if i!=n-1:
            print(A[i],end=" ")
        else:
            print(A[i])

n=int(input())
que_r=deque()

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

    if s[0]=="insert":
        que_r.appendleft(int(s[1]))
    elif s[0]=="delete" and que_r.count(int(s[1]))>=1:
        que_r.remove(int(s[1]))
    elif s[0]=="deleteFirst":
        gav=que_r.popleft()
    elif s[0]=="deleteLast":
        gav=que_r.pop()

pr(que_r,len(que_r))

Submission status: Runtime Error

Solution code:
def pr(data,next,head,tail):
    i = head
    while(1):
        if i == -1:
            print("")
            break
        print(data[i],end = "")
        i = next[i]
        if i != -1 :
            print(" ",end="")

def ins_f(data,next,prev,x,head,tail):
    size = len(data)
    if head != -1 :
        data.append(x)
        size += 1
        next.append(head)
        prev.append(-1)
        prev[head] = size -1
        head = size -1
    else :
        data.append(x)
        size += 1
        next.append(-1)
        prev.append(-1)
        tail = size-1
        head = size-1
    return head,tail

def dl(data,next,prev,x,head,tail):
    i = head
    while(1):
        if data[i] == x:
            if i == head:
                head = dl_f(next,prev,head)
                break
            elif i == tail:
                tail = dl_l(next,prev,tail)
                break
            else :
                prev[next[i]] = prev[i]
                next[prev[i]] = next[i]
                break
        elif i == tail:
            break
        i = next[i]
    return head,tail

def dl_f(next,prev,head,tail):
    if head == -1:
        return head
    elif next[head] == -1:
        head = -1
        tail = -1
    else:
        prev[next[head]] = -1
        head = next[head]
    return head,tail

def dl_l(next,prev,head,tail):
    if tail == -1:
        return tail
    elif prev[tail] == -1:
        head = -1
        tail = -1
    else:
        next[prev[tail]] = -1
        tail = prev[tail]
    return head,tail

n = int(input())
data = []
next = []
prev = []
head = -1
tail = -1
size = len(data)

for i in range(n):
    x = input().split()
    if x[0] == "insert":
        head,tail = ins_f(data,next,prev,x[1],head,tail)
    elif x[0] == "delete":
        head,tail = dl(data,next,prev,x[1],head,tail)
    elif x[0] == "deleteFirst":
        head,tail = dl_f(next,prev,head,tail)
    elif x[0] == "deleteLast":
        head,tail = dl_l(next,prev,head,tail)
pr(data,next,head,tail)

Submission status: Runtime Error

Solution code:
def pr(data,next,head,tail):
    i = head
    while(1):
        if i == -1:
            print("")
            break
        print(data[i],end = "")
        i = next[i]
        if i != -1 :
            print(" ",end="")

def ins_f(data,next,prev,x,head,tail):
    size = len(data)
    if head != -1 :
        data.append(x)
        size += 1
        next.append(head)
        prev.append(-1)
        prev[head] = size -1
        head = size -1
    else :
        data.append(x)
        size += 1
        next.append(-1)
        prev.append(-1)
        tail = size-1
        head = size-1
    return head,tail

def dl(data,next,prev,x,head,tail):
    i = head
    while(1):
        if data[i] == x:
            if i == head:
                head = dl_f(next,prev,head)
                break
            elif i == tail:
                tail = dl_l(next,prev,tail)
                break
            else :
                prev[next[i]] = prev[i]
                next[prev[i]] = next[i]
                break
        elif i == tail:
            break
        i = next[i]
    return head,tail

def dl_f(next,prev,head,tail):
    if head == -1:
        return head
    elif next[head] == -1:
        head = -1
        tail = -1
    else:
        prev[next[head]] = -1
        head = next[head]
    return head,tail

def dl_l(next,prev,head,tail):
    if tail == -1:
        return tail
    elif prev[tail] == -1:
        head = -1
        tail = -1
    else:
        next[prev[tail]] = -1
        tail = prev[tail]
    return head,tail

n = int(input())
data = []
next = []
prev = []
head = -1
tail = -1
size = len(data)

for i in range(n):
    x = input().split()
    if x[0] == "insert":
        head,tail = ins_f(data,next,prev,x[1],head,tail)
    elif x[0] == "delete":
        head,tail = dl(data,next,prev,x[1],head,tail)
    elif x[0] == "deleteFirst":
        head,tail = dl_f(next,prev,head,tail)
    elif x[0] == "deleteLast":
        head,tail = dl_l(next,prev,head,tail)
#    print(data,head,tail)
pr(data,next,head,tail)

Submission status: Runtime Error

Solution code:
from collections import deque

n=int(input())
que_r=deque()
data=deque()

for i in range(n):
    s=input()
    l=len(s)
    if s[0]=="i":
        que_r.appendleft(s[7:])
    elif s[6]==" ":
        try:
            que_r.remove(s[7:])
        except: pass
    elif l>10:
        que_r.popleft()
    elif l>6:
        que_r.pop()

pr(*que_r)

Submission status: Runtime Error

Solution code:
n = int(input())
c = [0]*n
s = []
a = []

for i in range(n):
    c[i] = list(input().split())
    
    if c[i][0]=='insert':
        s.append(c[i][1])
    elif c[i][0]=='delete':
        s.remove(c[i][1])
    elif c[i][0]=='deleteFirst':
        del s[len(s)-1]
    elif c[i][0]=='deleteLast':
        del s[0]
    else
        continue

for i in range(len(s),0,-1):
    a.append(s[i-1])
    
print(*a)

Submission status: Runtime Error

Solution code:
class DLL:
    class Node:
        def __init__(self, x, y, z):
            self.v = x
            self.prv = y
            self.nxt = z

    def __init__(self):
        init = DLL.Node(None, None, None)
        init.prv = init
        init.nxt = init
        self.size = 0
        self.init = init

    def insert(self, x):
        i = self.init
        j = i.nxt
        k = DLL.Node(x, i, j)
        i.nxt = k
        j.prv = k
        self.size += 1

    def deleteFirst(self):
        #if self.size != 0:
        i = self.init
        k = i.nxt
        j = k.nxt
        i.nxt = j
        j.prv = i
        self.size -= 1

    def deleteLast(self):
        #if self.size != 0:
        i = self.init
        k = i.prv
        j = k.prv
        i.prv = j
        j.nxt = i
        self.size -= 1

    def delete(self, x):
        #if self.size != 0:
        i = self.init
        k = i.nxt
        while 1:
            if k.v == x:
                i = k.prv
                j = k.nxt
                i.nxt = j
                j.prv = i
                self.size -= 1
                break
            else:
                if k.nxt == i:
                    break
                else:
                    k = k.nxt

    def getlist(self):
        f = self.init
        s = f.nxt
        l = f.prv
        lt = []
        while 1:
            if s != l:
                lt.append(s.v)
                s = s.nxt
            else:
                lt.append(l)
                break
        return ' '.join(lt)

n = int(input())
L = DLL()

for i in range(n):
    """
    com = input()
    if com[0] == "deleteFirst":
        L.deleteFirst()
    elif com == "deleteLast":
        L.deleteLast()
    else:
        C = com.split()
        if C[0] == "insert":
            L.insert(int(C[1]))
        elif C[0] == "delete":
            L.delete(int(C[1]))
    #L.prt()
    """

    com = input()
    if com[0] == "i":
        C = com.split()
        L.insert(int(C[1]))
    else:
        if com[6] == "F":
            L.deleteFirst()
        elif com[6] == "L":
            L.deleteLast()
        else:
            C = com.split()
            L.delete(int(C[1]))
print(L.getlist())

Submission status: Runtime Error

Solution code:
class DLL:
    class Node:
        def __init__(self, x, y, z):
            self.v = x
            self.prv = y
            self.nxt = z

    def __init__(self):
        init = DLL.Node(None, None, None)
        init.prv = init
        init.nxt = init
        self.size = 0
        self.init = init

    def insert(self, x):
        i = self.init
        j = i.nxt
        k = DLL.Node(x, i, j)
        i.nxt = k
        j.prv = k
        self.size += 1

    def deleteFirst(self):
        #if self.size != 0:
        i = self.init
        k = i.nxt
        j = k.nxt
        i.nxt = j
        j.prv = i
        self.size -= 1

    def deleteLast(self):
        #if self.size != 0:
        i = self.init
        k = i.prv
        j = k.prv
        i.prv = j
        j.nxt = i
        self.size -= 1

    def delete(self, x):
        #if self.size != 0:
        i = self.init
        k = i.nxt
        while 1:
            if k.v == x:
                i = k.prv
                j = k.nxt
                i.nxt = j
                j.prv = i
                self.size -= 1
                break
            else:
                if k.nxt == i:
                    break
                else:
                    k = k.nxt

    def getlist(self):
        f = self.init
        s = f.nxt
        l = f.prv
        lt = []
        while 1:
            if s != l:
                lt.append(s.v)
                s = s.nxt
            else:
                lt.append(l.v)
                break

        return ' '.join(lt)


n = int(input())
L = DLL()

for i in range(n):
    """
    com = input()
    if com[0] == "deleteFirst":
        L.deleteFirst()
    elif com == "deleteLast":
        L.deleteLast()
    else:
        C = com.split()
        if C[0] == "insert":
            L.insert(int(C[1]))
        elif C[0] == "delete":
            L.delete(int(C[1]))
    #L.prt()
    """

    com = input()
    if com[0] == "i":
        C = com.split()
        L.insert(int(C[1]))
    else:
        if com[6] == "F":
            L.deleteFirst()
        elif com[6] == "L":
            L.deleteLast()
        else:
            C = com.split()
            L.delete(int(C[1]))
print(L.getlist())

Submission status: Runtime Error

Solution code:
n = int(input())
list = []
check = 0

for i in range(n):
	l = input().split()
	
	if l[0] == "insert":
		list.insert(0,int(l[1]))
		
	elif l[0] == "delete":
		for j in range(len(list)):
			if list[j] == int(l[1]):
				check = 1
		if check == 1:
			list.remove(int(l[1]))
			
	elif l[0] == "deleteFirst":
		del list[0]
		
	elif l[0] == "deleteLast":
		del list[len(list)-1]
	check = 0


for k in range(len(list)):
	if k<len(list)-1:
		print(list[k],end=' ')
	else:
		print(list[k],end='')

Submission status: Runtime Error

Solution code:
a=int(input())
list=[]

for i in range(a):
    order=input().split()
    if order[0]=="insert":
        list.append(order[1])
    elif order[0]=="delete":
        list.remove(order[1])
    elif order[0]=="deleteFirst":
        list.pop(0)
    elif order[0]=="deleteLast":
        list.pop(len(list)-1)

print(*list)

Submission status: Runtime Error

Solution code:
a=int(input())
list=[]

for i in range(a):
    order=input().split()
    if order[0]=="insert":
        list.appendleft(order[1])
    elif order[0]=="delete":
        if order[1] in list:
            list.remove(order[1])
    elif order[0]=="deleteFirst":
        list.pop(0)
    elif order[0]=="deleteLast":
        list.pop(len(list)-1)

print(*list)

Submission status: Runtime Error

Solution code:
from collections import deque
a=int(input())
list=deque([])

for i in range(a):
    order=input().split()
    if order[0]=="insert":
        list.appendleft(order[1])
    elif order[0]=="delete":
        if order[1] in list:
            list.remove(order[1])
    elif order[0]=="deleteFirst":
        list.pop(0)
    elif order[0]=="deleteLast":
        list.pop(len(list)-1)

print(*list)

Submission status: Runtime Error

Solution code:
from collections import deque
a=int(input())
list=deque([])

for i in range(a):
    order=input().split()
    if order[0]=="insert":
        list.appendleft(order[1])
    elif order[0]=="delete":
        if order[1] in list:
            list.remove(order[1])
    elif order[0]=="deleteFirst":
        list.pop()
    elif order[0]=="deleteLast":
        list.pop()

print(*list)

Submission status: Runtime Error

Solution code:
#include <list>
#include <string>
using namespace std;
#define ll long long
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    string com;
    int key;
    list<ll> lst;
    list<ll>::iterator it,i=lst.end();
    while(n--){
        cin>>com;
        if(com=="insert"){
            cin>>key;
            lst.push_front(key);
        }
        else if(com=="delete"){
            cin>>key;
            for(it=lst.begin();it!=i;it++){
                if(*it==key){
                    lst.erase(it);
                    break;
                }
            }
        }
        else if(com=="deleteFirst") lst.pop_front();
        else                        lst.pop_back();
         
    }
    i--;
    for(it=lst.begin();it!=i;it++)  cout<<*it<<" ";
    cout<<*i<<"\n";
    return 0;
}
Compile Error Logs:


ステータス
Judge: 10/10
C++
CPU: 00:32 sec
Memory: 32472 KB
Length: 637 B
2015-03-23 23:30
テストケースの判定結果
Case #
Verdict
CPU Time
Memory
In
Out
Case Name
Case #1
: Accepted
00:00
1216
88
2
01.in
Case #2
: Accepted
00:00
1216
203
10
02.in
Case #3
: Accepted
00:00
1216
375
10
03.in
Case #4
: Accepted
00:00
1216
105
23
04.in
Case #5
: Accepted
00:00
1212
643
58
05.in
Case #6
: Accepted
00:00
1216
52
2
06.in
Case #7
: Accepted
00:00
1216
1058
110
07.in
Case #8
: Accepted
00:00
1216
1031
116
08.in
Case #9
: Accepted
00:28
1220
22392494
5
09.in
Case #10
: Accepted
00:32
32472
25527813
1288799
10.in
< prev |

/ 

| next > 
 


 
Judge Input #  ( | )

Judge Output #  ( | )

Submission status: Runtime Error

Solution code:
#include <list>
#include <string>
using namespace std;
#define ll long long
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    string com;
    int key;
    list<ll> lst;
    list<ll>::iterator it,i=lst.end();
    while(n--){
        cin>>com;
        if(com=="insert"){
            cin>>key;
            lst.push_front(key);
        }
        else if(com=="delete"){
            cin>>key;
            for(it=lst.begin();it!=i;it++){
                if(*it==key){
                    lst.erase(it);
                    break;
                }
            }
        }
        else if(com=="deleteFirst") lst.pop_front();
        else                        lst.pop_back();
         
    }
    i--;
    for(it=lst.begin();it!=i;it++)  cout<<*it<<" ";
    cout<<*i<<"\n";
    return 0;
}

Submission status: Runtime Error

Solution code:

#include <list>
#include <string>
using namespace std;
#define ll long long
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    string com;
    int key;
    list<ll> lst;
    list<ll>::iterator it,i=lst.end();
    while(n--){
        cin>>com;
        if(com=="insert"){
            cin>>key;
            lst.push_front(key);
        }
        else if(com=="delete"){
            cin>>key;
            for(it=lst.begin();it!=i;it++){
                if(*it==key){
                    lst.erase(it);
                    break;
                }
            }
        }
        else if(com=="deleteFirst") lst.pop_front();
        else                        lst.pop_back();
         
    }
    i--;
    for(it=lst.begin();it!=i;it++)  cout<<*it<<" ";
    cout<<*i<<"\n";
    return 0;
}

Submission status: Runtime Error

Solution code:
n = int(input())

linked_list = []

for _ in range(n):
    command = input()

    if "insert" in command:
        x = command.split()[-1]
        linked_list.insert(0, x)
    elif command == "deleteFirst":
        del linked_list[0]
    elif command == "deleteLast":
        del linked_list[-1]
    elif "delete" in command:
        x = command.split()[-1]
        del linked_list[linked_list.index(x)]

print(*linked_list)

Submission status: Runtime Error

Solution code:
n = int(input())
output = []
for i in range(n):
    li = input().split(' ')
    if(li[0] == 'insert'):
        output.insert(0, int(li[1]))
    elif(li[0] == 'delete'):
        output.remove(int(li[1]))
    elif(li[0] == 'deleteFirst'):
        del output[0]
    elif(li[0] == 'deleteLast'):
        del output[-1]
str_l = [str(o) for o in output]
print(' '.join(str_l))

Submission status: Runtime Error

Solution code:
import sys


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


class DoublyLinkedList():
    def __init__(self):
        self.head = Node()
        self.head.next = self.head
        self.head.prev = self.head

    def insert(self, x):
        node = Node(key=x, prev=self.head, next=self.head.next)
        self.head.next.prev = node
        self.head.next = node

    def search(self, x):
        node = self.head.next
        while node is not self.head and node.key != x:
            node = node.next
        return node

    def delete_key(self, x):
        if node is self.head:
            return None
        node = self.search(x)
        self._delete(node)

    def _delete(self, node):
        node.prev.next = node.next
        node.next.prev = node.prev

    def deleteFirst(self):
        self._delete(self.head.next)

    def deleteLast(self):
        self._delete(self.head.prev)

    def getKeys(self):
        node = self.head.next
        keys = []
        while node is not self.head:
            keys.append(node.key)
            node = node.next
        return " ".join(keys)


L = DoublyLinkedList()
n = int(input())
for i in sys.stdin:
    if 'insert' in i:
        x = i[7:-1]
        L.insert(x)
    elif 'deleteFirst' in i:
        L.deleteFirst()
    elif 'deleteLast' in i:
        L.deleteLast()
    elif 'delete' in i:
        x = i[7:-1]
        L.delete_key(x)
    else:
        pass
print(L.getKeys())

Submission status: Runtime Error

Solution code:
# ALDS1_3_C.

def show(a):
    # 配列の中身を出力する。
    _str = ""
    for i in range(len(a) - 1):
        _str += str(a[i]) + " "
    _str += str(a[len(a) - 1])
    print(_str)

def main():
    n = int(input())
    list = []
    for i in range(n):
        command = input().split()
        if len(command) > 1:
            if command[0][0] == 'i': list.append(int(command[1]))
            else: list.remove(int(command[1]))
        else:
            if command[0][6] == 'F': del list[0]
            else: list.pop()
    show(list)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
from collections import deque

n = int(input())
ops = [tuple(input().split()) for i in range(n)]

ary = deque([])


def insert(ary, x):
    ary.appendleft(x)


def delete(ary, x):
    if x in ary:
        ind = ary.index(x)
        ary = ary[:ind] + ary[ind + 1:]


def delete_first(ary):
    ary.popleft()


def delete_last(ary):
    ary.pop()


def operate(ary, op):
    cmd = op[0]

    if cmd == 'insert':
        x = int(op[1])
        insert(ary, x)
    elif cmd == 'delete':
        x = int(op[1])
        delete(ary, x)
    elif cmd == 'deleteFirst':
        delete_first(ary)
    elif cmd == 'deleteLast':
        delete_last(ary)


[operate(ary, op) for op in ops]
print(' '.join([str(_) for _ in ary]))

Submission status: Runtime Error

Solution code:
def assign(linked_list, commmand, x):
    if command == 'insert':
        linked_list.insert(0, int(x))
    if command == 'delete':
        linked_list.remove(int(x))
    if command == 'deleteFirst':
        linked_list.deleteFirst(int(x))
    if command == 'deleteLast':
        linked_list.deleteLast(int(x))

n = int(input())
linked_list = []
for i in range(n):
    command, x = input().split()
    assign(linked_list, command, x)
# print(linked_list)
print(' '.join(map(str, linked_list)))

Submission status: Runtime Error

Solution code:
def assign(linked_list, commmand, x):
    if command == 'insert':
        linked_list.insert(0, int(x))
    if command == 'delete':
        linked_list.remove(int(x))
    if command == 'deleteFirst':
        linked_list.pop(0)
    if command == 'deleteLast':
        linked_list.pop()

n = int(input())
linked_list = []
for i in range(n):
    command, x = input().split()
    assign(linked_list, command, x)
# print(linked_list)
print(' '.join(map(str, linked_list)))

Submission status: Runtime Error

Solution code:
def assign(linked_list, commmand, x):
    if command == 'insert':
        linked_list.insert(0, int(x))
    if command == 'delete':
        linked_list.remove(int(x))
    if command == 'deleteFirst':
        linked_list.pop(0)
    if command == 'deleteLast':
        linked_list.pop()

n = int(input())
linked_list = []
for i in range(n):
    input_line = input().split()
    if len(input_line) == 2:
        command, x = input_line
    else:
        command, x = input_line[0], -1
    assign(linked_list, command, x)
print(' '.join(map(str, linked_list)))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
#-*- coding: utf-8 -*-


class Node:
    def __init__(self, val):
        self.val = val
        self.prev = None
        self.next = None


class LinkedList:
    def __init__(self):
        self.head = Node(None)
        self.head.prev = self.head
        self.head.next = self.head

    def insertNode(self, p):
        p.prev = self.head
        p.next = self.head.next
        self.head.next.prev = p
        self.head.next = p

    def searchNode(self, val):
        p = self.head.next
        while p != self.head and p.val != val:
            p = p.next
        return p

    def deleteNode(self, p):
        if p == self.head:
            return
        p.prev.next = p.next
        p.next.prev = p.prev

    def insert(self, val):
        self.insertNode(Node(val))

    def delete(self, val):
        p = self.searchNode(val)
        self.deleteNode(p)

    def deleteFirst(self):
        self.eleteNode(self.head.next)

    def deleteLast(self):
        self.deleteNode(self.head.prev)

    def show(self):
        p = self.head.next
        while p != self.head:
            print p.val,
            p = p.next
        print


if __name__ == '__main__':
    n = int(raw_input())
    i = 0
    link = LinkedList()
    while i != n:
        line = raw_input().split()
        if line[0] == 'insert':
            link.insert(int(line[1]))
        elif line[0] == 'delete':
            link.delete(int(line[1]))
        elif line[0] == 'deleteFirst':
            link.deleteFirst()
        elif line[0] == 'deleteLast':
            link.deleteLast()
        i += 1
    link.show()

Submission status: Runtime Error

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

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:
#!/usr/bin/env python
#-*- coding: utf-8 -*-

import sys


class LinkedList:
    def __init__(self):
        self.l = []

    def insert(self, val):
        self.l.append(val)

    def delete(self, val):
        i = len(self.l) - 1
        while i >= 0 and l[i] != val:
            i -= 1
        del self.l[i]

    def deleteFirst(self):
        self.l.pop()

    def deleteLast(self):
        del self.l[0]

    def show(self):
        for i in range(len(l) - 1, 0 - 1, -1):
            print self.l[i],
        print


if __name__ == '__main__':
    n = int(raw_input())
    link = LinkedList()
    i = 0
    for i in range(n):
        t = raw_input().split()
        if t[0] == 'insert':
            link.insert(t[1])
        elif t[0] == 'delete':
            link.delete(t[1])
        elif t[0] == 'deleteFirst':
            link.deleteFirst()
        elif t[0] == 'deleteLast':
            link.deleteLast()
        i += 1
    link.show()

Submission status: Runtime Error

Solution code:
#coding:utf-8
from collections import deque

n = int(input())
day = deque()
for i in range(n):
    order = list(input().split())
    if order[0] == "insert":
        day.appendleft(order[1])
    if order[0] == "delete":
        day.remove(order[1])
    if order[0] == "deleteFirst":
        day.popleft()
    if order[0] == "deleteLast":
        day.pop()

day = " ".join(day)              
print(day)

Submission status: Runtime Error

Solution code:
%%cython
import numpy as np
n = int(input())
A = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))


def solve(i, num):
    if num == 0:
        global sw
        sw = 1
        return 0
    if i >= n or num < 0:
        return 0
    return solve(i+1, num), solve(i+1, num-A[i])

for num in m:
    i = 0
    sw = 0
    solve(i,num)
    if sw == 0:
        print("no")
    if sw == 1:
        print("yes")

Submission status: Runtime Error

Solution code:
%load_ext Cython

#coding:utf-8
import numpy as np
n = int(input())
A = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))


def solve(i, num):
    if num == 0:
        global sw
        sw = 1
        return 0
    if i >= n or num < 0:
        return 0
    return solve(i+1, num), solve(i+1, num-A[i])

for num in m:
    i = 0
    sw = 0
    solve(i,num)
    if sw == 0:
        print("no")
    if sw == 1:
        print("yes")

Submission status: Runtime Error

Solution code:
#coding:utf-8
from collections import deque
from numba import jit
n = int(input())

@jit
def ord(order): 
    if order[0] == "insert":
        day.appendleft(order[1])
    elif order[0] == "delete":
        try:
            day.remove(order[1])
        except:
            continue
    elif order[0] == "deleteFirst":
        day.popleft()
    elif order[0] == "deleteLast":
        day.pop()


day = deque()
for i in range(n):
    order = list(input().split())
    ord(order)
day = " ".join(day)              
print(day)