Problem:


Doubly Linked List

Your task is to implement a double linked list.

Write a program which performs the following operations:

insert x: insert an element with key x into the front of the list.

delete x: delete the first element which has the key of x from the list. If there is not such element, you need not do anything.

deleteFirst: delete the first element from the list. 

deleteLast: delete the last element from the list. 

Input

The input is given in the following format:

n

command1 

command2 

...

commandn 

In the first line, the number of operations n is given. In the following n lines, the above mentioned operations are given in the following format:

insert x

delete x

deleteFirst 

deleteLast 

Output

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

Constraints

The number of operations ≤ 2,000,000

The number of delete operations ≤ 20

0 ≤ value of a key ≤ 109

The number of elements in the list does not exceed 106

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

Sample Input 1

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

Sample Output 1

6 1 2

Sample Input 2

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

Sample Output 2

1

Template in C
-->


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


Sample output:
6 1 2

Submission status: Runtime Error

Solution code:
import sys

class Deque:
    class Cell2:
        def __init__(self, x, y = None, z = None):
            self.data = x
            self.next = y
            self.prev = z

    def __init__(self):
        head = Deque.Cell2(None)
        head.next = head        
        head.prev = head
        self.size = 0
        self.head = head

    def push_front(self, x):
        h = self.head
        q = h.next
        p = Deque.Cell2(x, q, h)
        h.next = p
        q.prev = p
        self.size += 1

    def pop_back(self):
        if self.size == 0: raise IndexError
        h = self.head
        q = h.prev
        p = q.prev
        p.next = h
        h.prev = p
        self.size -= 1
        del gc.garbage[:]
        return q.data

    def pop_front(self):
        if self.size == 0: raise IndexError
        h = self.head
        q = h.next
        p = q.next
        p.prev = h
        h.next = p
        self.size -= 1
        del gc.garbage[:]
        return q.data

    def delete(self,x):
        h=self.head.next
        while h.data!=x:
            h=h.next
            if h==self.head: return
        q=h.next
        p=h.prev
        q.prev=p
        p.next=q
        self.size -= 1
        del gc.garbage[:]
        return

    def __str__(self):
        if self.size == 0: return
        buff = ''
        n = self.size
        cp = self.head.next
        while n > 1:
            buff += '%s ' % cp.data
            cp = cp.next
            n -= 1
        buff += '%s' % cp.data
        return buff
    
A=Deque()
n=int(raw_input())
while n:
    s = (raw_input().split())
    if s[0] == 'insert':
        A.push_front(int(s[1]))
    elif s[0] == 'delete':
        A.delete(int(s[1]))
    elif s[0] == 'deleteFirst':
        A.pop_front()
    elif s[0] == 'deleteLast':
        A.pop_back()
    n -=1
    
    print A
    print

Submission status: Runtime Error

Solution code:
import sys

class Deque:
    class Cell2:
        def __init__(self, x, y = None, z = None):
            self.data = x
            self.next = y
            self.prev = z

    def __init__(self):
        head = Deque.Cell2(None)
        head.next = head        
        head.prev = head
        self.size = 0
        self.head = head

    def push_front(self, x):
        h = self.head
        q = h.next
        p = Deque.Cell2(x, q, h)
        h.next = p
        q.prev = p
        self.size += 1

    def pop_back(self):
        if self.size == 0: raise IndexError
        h = self.head
        q = h.prev
        p = q.prev
        p.next = h
        h.prev = p
        self.size -= 1
        return q.data

    # 先頭のデータを取り出す
    def pop_front(self):
        if self.size == 0: raise IndexError
        h = self.head
        q = h.next
        p = q.next
        p.prev = h
        h.next = p
        self.size -= 1
        del gc.garbage[:]
        return q.data

    # xをもつセルを削除する
    def delete(self,x):
        h=self.head.next
        while h.data!=x:
            h=h.next
            if h==self.head: return
        q=h.next
        p=h.prev
        q.prev=p
        p.next=q
        self.size -= 1
        del gc.garbage[:]
        return

    # 表示
    def __str__(self):
        if self.size == 0: return
        buff = ''
        n = self.size
        cp = self.head.next
        while n > 1:
            buff += '%s ' % cp.data
            cp = cp.next
            n -= 1
        buff += '%s' % cp.data
        return buff
    
A=Deque()
n=int(raw_input())
while n:
    s = (raw_input().split())
    if s[0] == 'insert':
        A.push_front(int(s[1]))
    elif s[0] == 'delete':
        A.delete(int(s[1]))
    elif s[0] == 'deleteFirst':
        A.pop_front()
    elif s[0] == 'deleteLast':
        A.pop_back()
    n -=1
    
    print A
    print

Submission status: Runtime Error

Solution code:
import sys,gc

    
A=[]
n=int(raw_input())
while n:
    s = raw_input()
    if s[0] == 'i'
        A.insert(0,s[7:])
    elif s[6] == ' ':
        try:
            A.remove(s[7:])
        except:
            pass
    elif s[6] == 'F':
        A.pop(0)
    elif s[6] == 'L':
        A.pop()
    n -=1
    
for e in A:
    print int(e),

Submission status: Runtime Error

Solution code:
import sys,gc

    
A=[]
fp =0
bp =0

n=int(raw_input())
while n:
    s = raw_input()
    if s[0] == 'i':
        A.append(s[7:])
        fp += 1
    elif s[6] == ' ':
        i=-1
        try:
            while True:
                i = A[i+1:].index(s[7:])
        finally:
            if i!=-1:
                del A[i]
                fp -=1
    elif s[6] == 'F':
        A.pop()
        fp -=1
    elif s[6] == 'L':
        A[bp]=-1
        bp +=1
    n -=1

for e in A[bp:fp+1][::-1]:
    if e!=-1:
        print int(e),

Submission status: Runtime Error

Solution code:
n = int(raw_input())
cmdlist = [raw_input().split() for i in range(n)]

cmddict = {
	"insert":"%s.insert(0,%d)",
	"delete":"%s.remove(%d)",
	"deleteFirst":"%s.pop(0)",
	"deleteLast":"%s.pop()",
}

mylist = []
for cmd in cmdlist:
	try:
		cmd[1] = int(cmd[1])
		exec(cmddict[cmd[0]] % ("mylist", cmd[1]))
		
	except IndexError:
		exec(cmddict[cmd[0]] % ("mylist"))
		
for i in mylist:
	print i,

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin
n = int(stdin.readline())
dll = []
while n:
    n -= 1
    cmd = stdin.readline().rstrip()
    if cmd.startswith('insert '):
        dll.insert(0, cmd[7:])
    elif cmd.startswith('delete '):
        dll.remove(cmd[7:])
    elif cmd.startswith('deleteFirst'):
        del dll[0]
    elif cmd.startswith('deleteLast'):
        del dll[-1]
print(*dll)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# -*- coding:utf-8 -*-
#from __future__ import print_function
import time
import sys
import io
import re
import math
start = time.clock()
i = 0
ans=[]
n=int(raw_input())
for _ in range(n):
    (a,b)=map(str, raw_input().split())
    if a=='insert': ans.insert(0,b)
    elif a=='deleteFirst': del ans[0]
    elif a=='deleteLast': del ans[-1]
    else: ans.remove(b)
for i in ans:
    print i

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# -*- coding:utf-8 -*-
#from __future__ import print_function
import time
import sys
import io
import re
import math
start = time.clock()
i = 0
ans=[]
n=int(raw_input())
for _ in range(n):
    (a,b)=map(str, raw_input().split())
    if a=='insert': ans.insert(0,b)
    elif a=='deleteFirst': del ans[0]
    elif a=='deleteLast': del ans[-1]
    else: ans.remove(b)
print ' '.join(ans)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# -*- coding:utf-8 -*-
#from __future__ import print_function
import time
import sys
import io
import re
import math
start = time.clock()
i = 0
ans=[]
n=int(raw_input())
for _ in range(n):
    a=raw_input().split()
    if a[0]=='insert': ans.insert(0,a[1])
    elif a[0]=='deleteFirst': del ans[0]
    elif a[0]=='deleteLast': del ans[-1]
    else: ans.remove(a[1])
print ' '.join(ans)

Submission status: Runtime Error

Solution code:
aya7581026@Ayas-Mac-mini:alds$ cat ./al3c.py
#!/usr/bin/env python
# -*- coding:utf-8 -*-
#from __future__ import print_function
import time
import sys
import io
import re
import math
start = time.clock()
i = 0
ans=[]
n=int(raw_input())
for _ in range(n):
    a=raw_input().split()
    if a[0]=='insert': ans.insert(0,a[1])
    elif a[0]=='deleteFirst': del ans[0]
    elif a[0]=='deleteLast': del ans[-1]
#    else: ans.remove(str(a[1]))
    else:
        if a[1] in ans:
            ans.remove(a[1])
#    print ans
print ' '.join(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(raw_input())
ls = []
for i in range(n):
    cmd = map(str, raw_input().split())
    if cmd[0] == "insert":
        ls.append(cmd[1])
    elif cmd[0] == "deleteFirst":
        del ls[len(ls)-1:]
    elif cmd[0] == "deleteLast":
        del ls[1:]
    else:
        for i in range(len(ls)-1,0,-1):
            if ls[i] == cmd[1]:
            a = ls.pop(i)
print " ".join(map(str, ls[::-1]))

Submission status: Runtime Error

Solution code:
n = int(raw_input())
ls = []
for i in range(n):
    cmd = raw_input()
    if cmd[0] == "i":
        ls.insert(0,cmd[7])
    elif cmd[6] == " ":
        ls.remove(cmd[7])
    elif cmd[6] == "F":
        ls.pop(0)
    else:
        ls.pop(-1)

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

Submission status: Runtime Error

Solution code:
from collections import deque

n = int(input())

q = deque()
for i in range(n):
    cmd = input().strip()
    if cmd == 'deleteFirst':
        q.popleft()
        continue
    if cmd == 'deleteLast':
        q.pop()
        continue
    cmd, x = cmd.split()
    if cmd == 'insert':
        q.appendleft(x)
        continue
    if cmd == 'delete':
        q.remove(x)
        continue

print(' '.join(q))

Submission status: Runtime Error

Solution code:
n = int(input())

q = deque()
for i in range(n):
    cmd = input().strip()
    if cmd == 'deleteFirst':
        q.popleft()
        continue
    if cmd == 'deleteLast':
        q.pop()
        continue
    cmd, x = cmd.split()
    x = int(x)
    if cmd == 'insert':
        q.appendleft(x)
        continue
    if cmd == 'delete':
        try:
            q.remove(x)
        except:
            pass
        continue

print(' '.join(q))

Submission status: Runtime Error

Solution code:
n = int(input())

q = deque()
for i in range(n):
    cmd = input().strip()
    if cmd == 'deleteFirst':
        q.popleft()
        continue
    if cmd == 'deleteLast':
        q.pop()
        continue
    cmd, x = cmd.split()
    x = int(x)
    if cmd == 'insert':
        q.appendleft(x)
        continue
    if cmd == 'delete':
        try:
            q.remove(x)
        except:
            pass
        continue

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

Submission status: Runtime Error

Solution code:
n = int(input())
q = []
bottom = 0
for i in range(n):
    cmd = input()
    if cmd[0] == 'i':
        q.append(cmd[7:])
    elif cmd[6] == ' ':
        try:
            q.pop(~q[::-1].index(cmd[7:]))
        except:
            pass
    elif cmd[6] == 'F':
        q.pop()
    else:
        bottom += 1
 
print(' '.join(q[bottom:][::-1]))

Submission status: Runtime Error

Solution code:
n = int(input())
q = []
bottom = 0
for i in range(n):
    cmd = input()
    if cmd[0] == 'i':
        q.append(cmd[7:])
    elif cmd[6] == ' ':
        try:
            q.pop(~q[::-1].index(cmd[7:]))
        except:
            pass
    elif cmd[6] == 'F':
        q.pop()
    else:
        bottom += 1
 
print ' '.join(q[bottom:][::-1])

Submission status: Runtime Error

Solution code:
from code import InteractiveConsole as C

n = int(C.raw_input())
q = []
bottom = 0
for i in range(n):
    cmd = C.raw_input()
    if cmd[0] == 'i':
        q.append(cmd[7:])
    elif cmd[6] == ' ':
        try:
            q.pop(~q[::-1].index(cmd[7:]))
        except:
            pass
    elif cmd[6] == 'F':
        q.pop()
    else:
        bottom += 1

print(' '.join(q[bottom:][::-1]))

Submission status: WA: Presentation Error

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

Submission status: WA: Presentation Error

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

Submission status: WA: Presentation Error

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

Submission status: WA: Presentation Error

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

Submission status: WA: Presentation Error

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

Submission status: WA: Presentation Error

Solution code:
class Node():
    def __init__(self, key):
        self.prev = None
        self.next = None
        self.key = key
    
class Solution:
    def display(self):
        cur = nil.next
        while True:
            if cur == nil:
                break
            print(cur.key, end=' ')
            cur = cur.next
    
    def insert(self, key):
        x = Node(key)

        if nil.next == None:
            nil.next = x
            nil.prev = x
            x.prev = nil
            x.next = nil
        else:
            x.next = nil.next
            nil.next.prev = x
            nil.next = x
            x.prev = nil

    def listSearch(self, key):
        cur = nil.next
        while cur != nil:
            if cur.key == key:
                break
            cur = cur.next
        return cur
    
    def deleteNode(self, node):
        if node == nil:
            return
        node.prev.next = node.next
        node.next.prev = node.prev

    def delete(self, key):
        self.deleteNode(self.listSearch(key))
    
    def deleteFirst(self):
        self.deleteNode(nil.next)
    
    def deleteLast(self):
        self.deleteNode(nil.prev)


myList = Solution()
nil = Node(None)

for _ in range(int(input())):
    s = input()
    try:
        com, val = s.split()
        val = int(val)
    except ValueError:
        com = s
    
    if com == 'insert':
        head = myList.insert(val)
    elif com == 'delete':
        head = myList.delete(val)
    elif com == 'deleteFirst':
        head = myList.deleteFirst()
    elif com == 'deleteLast':
        head = myList.deleteLast()

myList.display()

Submission status: WA: Presentation Error

Solution code:
class Node():
    def __init__(self, key):
        self.prev = None
        self.next = None
        self.key = key
    
class Solution:
    def display(self):
        cur = nil.next
        while True:
            if cur == nil:
                break
            print(cur.key, end=' ')
            cur = cur.next
    
    def insert(self, key):
        x = Node(key)

        if nil.next == None:
            nil.next = x
            nil.prev = x
            x.prev = nil
            x.next = nil
        else:
            x.next = nil.next
            nil.next.prev = x
            nil.next = x
            x.prev = nil

    def listSearch(self, key):
        cur = nil.next
        while cur != nil:
            if cur.key == key:
                break
            cur = cur.next
        return cur
    
    def deleteNode(self, node):
        if node == nil:
            return
        node.prev.next = node.next
        node.next.prev = node.prev

    def delete(self, key):
        self.deleteNode(self.listSearch(key))
    
    def deleteFirst(self):
        self.deleteNode(nil.next)
    
    def deleteLast(self):
        self.deleteNode(nil.prev)


myList = Solution()
nil = Node(None)

for _ in range(int(input())):
    s = input()
    try:
        com, val = s.split()
        val = int(val)
    except ValueError:
        com = s
    
    if com == 'insert':
        head = myList.insert(val)
    elif com == 'delete':
        head = myList.delete(val)
    elif com == 'deleteFirst':
        head = myList.deleteFirst()
    elif com == 'deleteLast':
        head = myList.deleteLast()

myList.display()
print()

Submission status: WA: Presentation Error

Solution code:
import sys

class Node():
    def __init__(self, key):
        self.prev = None
        self.next = None
        self.key = key
    
class Solution:
    def display(self):
        cur = nil.next
        while True:
            if cur == nil:
                break
            print(cur.key, end=' ')
            cur = cur.next
    
    def insert(self, key):
        x = Node(key)

        if nil.next == None:
            nil.next = x
            nil.prev = x
            x.prev = nil
            x.next = nil
        else:
            x.next = nil.next
            nil.next.prev = x
            nil.next = x
            x.prev = nil

    def listSearch(self, key):
        cur = nil.next
        while cur != nil:
            if cur.key == key:
                break
            cur = cur.next
        return cur
    
    def deleteNode(self, node):
        if node == nil:
            return
        node.prev.next = node.next
        node.next.prev = node.prev

    def delete(self, key):
        self.deleteNode(self.listSearch(key))
    
    def deleteFirst(self):
        self.deleteNode(nil.next)
    
    def deleteLast(self):
        self.deleteNode(nil.prev)


myList = Solution()
nil = Node(None)

for _ in range(int(input())):
    s = input()
    try:
        com, val = s.split()
        val = int(val)
    except ValueError:
        com = s
    
    if com == 'insert':
        head = myList.insert(val)
    elif com == 'delete':
        head = myList.delete(val)
    elif com == 'deleteFirst':
        head = myList.deleteFirst()
    elif com == 'deleteLast':
        head = myList.deleteLast()

myList.display()
sys.stdout.write('\n')

Submission status: WA: Presentation Error

Solution code:
class Node():
    def __init__(self, key):
        self.prev = None
        self.next = None
        self.key = key
    
class Solution:
    def display(self):
        cur = nil.next
        while True:
            if cur == nil:
                break
            print(cur.key, end=' ')
            cur = cur.next
    
    def insert(self, key):
        x = Node(key)

        if nil.next == None:
            nil.next = x
            nil.prev = x
            x.prev = nil
            x.next = nil
        else:
            x.next = nil.next
            nil.next.prev = x
            nil.next = x
            x.prev = nil

    def listSearch(self, key):
        cur = nil.next
        while cur != nil:
            if cur.key == key:
                break
            cur = cur.next
        return cur
    
    def deleteNode(self, node):
        if node == nil:
            return
        node.prev.next = node.next
        node.next.prev = node.prev

    def delete(self, key):
        self.deleteNode(self.listSearch(key))
    
    def deleteFirst(self):
        self.deleteNode(nil.next)
    
    def deleteLast(self):
        self.deleteNode(nil.prev)


myList = Solution()
nil = Node(None)

for _ in range(int(input())):
    s = input()
    try:
        com, val = s.split()
        val = int(val)
    except ValueError:
        com = s
    
    if com == 'insert':
        myList.insert(val)
    elif com == 'delete':
        myList.delete(val)
    elif com == 'deleteFirst':
        myList.deleteFirst()
    elif com == 'deleteLast':
        myList.deleteLast()

myList.display()

Submission status: WA: Presentation Error

Solution code:
n = int(input())
a = [int(input().split(sep=" ")[1])]
for i in range(n - 1):
    command = input()
    if(command == "deleteFirst"):
        a.pop(0)
    elif(command == "deleteLast"):
        a.pop()
    else:
        command,num = command.split(sep = " ")
        num = int(num)
        if(command == "delete"):
            a.remove(num)
        else:
            a.append(num)
for num in a:
    print(num,end=" ")
print()

Submission status: WA: Presentation Error

Solution code:
import sys
from collections import deque


def main():
    line = sys.stdin.readlines()
    deq = deque()
    for i in range(1, int(line[0]) + 1):
        input_command = line[i]

        if input_command[0] == 'i':         # 'insert index'
            deq.appendleft(input_command[7:])
        elif input_command[0] == 'd':
            if input_command[6] == ' ':     # 'delete index'
                key = input_command[7:]
                if key in deq:
                    deq.remove(key)
            elif input_command[6] == 'F':   # 'deleteFirst':
                deq.popleft()
            elif input_command[6] == 'L':   # 'deleteLast':
                deq.pop()

    print(' '.join(deq))
    return


main()

Submission status: WA: Presentation 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._key != None:
		print(str(cur._key), end = ' ')
		cur = cur._next

Submission status: WA: Presentation 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}')

while True:
    try:
        print(d.popleft(), end=' ')
    except IndexError:
        break
print()

Submission status: WA: Presentation 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}')

while True:
    try:
        print(d.popleft(), end=' ')
    except IndexError:
        break

Submission status: WA: Presentation 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

Submission status: WA: Presentation Error

Solution code:
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_C&lang=jp
class LinkedList():
    def __init__(self):
        self.head = None
    
    def insert(self, x):
        if self.head is None:
            self.head = LinkedListElement(x)
            self.head.next = self.head
            self.head.prev = self.head
            return
        newelm = LinkedListElement(x)
        former_tail = self.head.prev
        former_head = self.head

        former_tail.next = newelm
        former_head.prev = newelm
        
        newelm.next = former_head
        newelm.prev = former_tail
        self.head = newelm

    def deleteLast(self):
        if self.head is None:
            return
        if self.head is self.head.next:
            self.head = None
            return
        
        former_last = self.head.prev
        former_second_last = self.head.prev.prev
        self.head.prev = former_second_last
        former_second_last.next = self.head
    
    def deleteFirst(self):
        if self.head is None:
            return
        if self.head is self.head.next:
            self.head = None
            return

        tail = self.head.prev
        former_second = self.head.next
        tail.next = former_second
        former_second.prev = tail
        self.head = former_second
    
    def delete(self, x):
        if self.head is None:
            return
        if self.head.value == x:
            self.deleteFirst()
            return
        if self.head is self.head.next:
            return
        
        ptr = self.head
        while True:
            if ptr.value == x:
                ptr_prev = ptr.prev
                ptr_next = ptr.next
                ptr_prev.next = ptr_next
                ptr_next.prev = ptr_prev
                break
            ptr = ptr.next
            if ptr is self.head:
                break
    def puts(self):
        if self.head is None:
            print("")
            return
        ptr = self.head
        while True:
            print(ptr.value, end="")
            ptr = ptr.next
            if ptr is self.head:
                break
            else:
                print(" ", end="")



class LinkedListElement():

    def __init__(self, value):
        self.value = value
        self.next = None
        self.prev = None


if __name__ == "__main__":
    n = int(input())
    li = LinkedList()
    for i in range(n):
        cmd = input().split()
        if cmd[0] == "insert":
            li.insert(cmd[1])
        elif cmd[0] == "delete":
            li.delete(cmd[1])
        elif cmd[0] == "deleteFirst":
            li.deleteFirst()
        elif cmd[0] == "deleteLast":
            li.deleteLast()
    
    li.puts()