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: WA: Presentation Error

Solution code:
MAX_N = 2000000


class DoublyLinkedList(object):

    def __init__(self):
        self.list = [Node(0, 0, 0, 0)] * MAX_N
        self.gen_node = node_generator()

        nil = 0
        self.nil_node = self.gen_node(0, nil, nil)
        self.list[nil] = self.nil_node

    def insert(self, x):
        inserted = self.gen_node(x, self.nil_node.p, self.nil_node.next)
        self.list[inserted.p] = inserted

        self.list[self.nil_node.next].prev = inserted.p
        self.nil_node.next = inserted.p

    def _delete_node(self, i):
        self.list[self.list[i].prev].next, self.list[self.list[i].next].prev = self.list[i].next, self.list[i].prev

    def _search_node(self, val):
        cur = self.nil_node.next
        while self.list[cur].p != self.nil_node.p:
            if self.list[cur].val == val:
                return cur
            cur = self.list[self.list[cur].next].p

    def delete(self, x):
        i = self._search_node(x)
        self._delete_node(i)

    def delete_first(self):
        self._delete_node(self.nil_node.next)

    def delete_last(self):
        self._delete_node(self.nil_node.prev)

    def show(self):
        cur = self.nil_node.next

        while cur != self.nil_node.p:
            print self.list[cur].val, " ",
            cur = self.list[cur].next


class Node(object):

    def __init__(self, p, val, prev, _next):
        self.p = p
        self.val = val
        self.prev = prev
        self.next = _next

    def __repr__(self):
        return "p: {}, val: {}, prev: {}, next: {}\n".format(self.p, self.val, self.prev, self.next)


def node_generator():
    p = [-1]

    def _node_generator(val, prev, _next):
        p[0] += 1
        return Node(p[0], val, prev, _next)

    return _node_generator

if __name__ == '__main__':
    n = int(raw_input())
    commands = [raw_input().split() for _ in range(n)]

    d = DoublyLinkedList()

    for command in commands:
        if command[0] == "insert":
            d.insert(int(command[1]))
        elif command[0] == "delete":
            d.delete(int(command[1]))
        elif command[0] == "deleteFirst":
            d.delete_first()
        elif command[0] == "deleteLast":
            d.delete_last()

    d.show()

Submission status: WA: Presentation Error

Solution code:
MAX_N = 200


class DoublyLinkedList(object):

    def __init__(self):
        self.list = [Node(0, 0, 0, 0)] * MAX_N
        self.gen_node = node_generator()

        nil = 0
        self.nil_node = self.gen_node(0, nil, nil)
        self.list[nil] = self.nil_node

    def insert(self, x):
        inserted = self.gen_node(x, self.nil_node.p, self.nil_node.next)
        self.list[inserted.p] = inserted

        self.list[self.nil_node.next].prev = inserted.p
        self.nil_node.next = inserted.p

    def _delete_node(self, i):
        self.list[self.list[i].prev].next, self.list[self.list[i].next].prev = self.list[i].next, self.list[i].prev

    def _search_node(self, val):
        cur = self.nil_node.next
        while self.list[cur].p != self.nil_node.p:
            if self.list[cur].val == val:
                return cur
            cur = self.list[self.list[cur].next].p

    def delete(self, x):
        i = self._search_node(x)
        self._delete_node(i)

    def delete_first(self):
        self._delete_node(self.nil_node.next)

    def delete_last(self):
        self._delete_node(self.nil_node.prev)

    def show(self):
        cur = self.nil_node.next

        while cur != self.nil_node.p:
            print self.list[cur].val, " ",
            cur = self.list[cur].next


class Node(object):

    def __init__(self, p, val, prev, _next):
        self.p = p
        self.val = val
        self.prev = prev
        self.next = _next

    def __repr__(self):
        return "p: {}, val: {}, prev: {}, next: {}\n".format(self.p, self.val, self.prev, self.next)


def node_generator():
    p = [-1]

    def _node_generator(val, prev, _next):
        p[0] += 1
        return Node(p[0], val, prev, _next)

    return _node_generator

if __name__ == '__main__':
    n = int(raw_input())
    commands = [raw_input().split() for _ in range(n)]

    d = DoublyLinkedList()

    for command in commands:
        if command[0] == "insert":
            d.insert(int(command[1]))
        elif command[0] == "delete":
            d.delete(int(command[1]))
        elif command[0] == "deleteFirst":
            d.delete_first()
        elif command[0] == "deleteLast":
            d.delete_last()

    d.show()

Submission status: WA: Presentation Error

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

if __name__ == '__main__':
	num = int(input())
	output = ''
	link = []
	for i in range(num):
		order = input()
		if order[:7] == 'insert ':
				link.insert(0, order[7:])
		elif order[:7] == 'delete ':
				if order[7:] in link:
					link.remove(order[7:])
		elif order == 'deleteFirst':
				link.pop(0)
		elif order == 'deleteLast':
				link.pop()
	for j in link:
		output = output + j + ' '
	print(output)

Submission status: WA: Presentation Error

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

while(n):
	s=input().split()
	com=s[0]
	if com=="insert":
		l.insert(0,s[1])
	elif com=="delete":
		for i in range(len(l)):
			if l[i]==s[1]:
				l.pop(i)
				break
	elif com=="deleteFirst":
		l.pop(0)
	else:
		l.pop()
	n-=1

for i in l:
	print(i,end=" ")
print("")

Submission status: WA: Presentation Error

Solution code:
list = []

n = int(input())

for i in range(n):
    line = input().split()
    if line[0] == 'insert':
        list.insert(0, int(line[1]))
    if line[0] == 'delete':
        list.remove(int(line[1]))
    if line[0] == 'deleteFirst':
        list.remove(list[0])
    if line[0] == 'deleteLast':
        list.pop()

for i in list:
    print(i, end=" ")
print()

Submission status: WA: Presentation Error

Solution code:
import sys
from collections import deque
n = int(sys.stdin.readline())
q = deque()
for i in range(n):
    c = sys.stdin.readline()
    if c[0] == 'i':
        q.appendleft(c[7:])
    elif c[6] == ' ':
        q.remove(c[7:])
    elif c[6] == 'F':
        q.popleft()
    else:
        q.pop()
print(*q)

Submission status: WA: Presentation Error

Solution code:
import sys
from collections import deque
n = int(input())
q = deque()
for i in range(n):
    c = sys.stdin.readline()
    if c[0] == 'i':
        q.appendleft(c[7:])
    elif c[6] == ' ':
        try:
            q.remove(c[7:])
        except:
            pass
    elif c[6] == 'F':
        q.popleft()
    else:
        q.pop()
print(*q)

Submission status: WA: Presentation Error

Solution code:
def operation(command, arrey):
    if command[0] == 'insert':
        arrey.insert(0,command[1])
        return arrey
    elif command[0] == 'delete':
        if command[1] in arrey:
            arrey.remove(command[1])
    elif command[0] == 'deleteFirst':
        arrey.pop(0)
    elif command[0] == 'deleteLast':
        arrey.pop(-1)


n = int(input())
list = []

for i in range(n):
    command = input().split()
    operation(command,list)

for i in range(len(list)):
    print(list[i]+' ',end='')

Submission status: WA: Presentation Error

Solution code:
def operation(command, arrey):
    if command[0] == 'insert':
        arrey.insert(0,command[1])
        return arrey
    elif command[0] == 'delete':
        if command[1] in arrey:
            arrey.remove(command[1])
    elif command[0] == 'deleteFirst':
        arrey.pop(0)
    elif command[0] == 'deleteLast':
        arrey.pop(-1)


n = int(input())
list = []

for i in range(n):
    command = input().split()
    operation(command,list)

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

Submission status: WA: Presentation Error

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

    def __init__(self, elm=None, prev=None, nxt=None):
        self.elm = elm
        self.prev = prev
        self.nxt = nxt


class MyDLList:
    size = 0
    head = tail = None

    def insert(self, elm):
        if self.is_empty():
            self.head = self.tail = Node(elm)
        else:
            x = Node(elm)
            x.nxt = self.head
            self.head.prev = x
            self.head = x
        self.size += 1

    def list_search(self, x):
        cur = self.head
        while cur != self.tail and cur.elm != x:
            cur = cur.nxt
        if cur.elm != x:
            cur = None
        return cur

    def delete(self, x):
        cur = self.list_search(x)
        if cur:
            if cur == self.head:
                self.delete_first()
            elif cur == self.tail:
                self.delete_last()
            else:
                cur.prev.nxt = cur.nxt
                cur.nxt.prev = cur.prev
            self.size -= 1
            return cur.elm
        else:
            pass

    def delete_first(self):
        cur = self.head
        if not self.is_empty():
            if self.head != self.tail:
                self.head.nxt.prev = None
                self.head = self.head.nxt
            else:
                self.head = self.tail = None
            self.size -= 1
        return cur.elm

    def delete_last(self):
        cur = self.tail
        if not self.is_empty():
            if self.head != self.tail:
                self.tail.prev.nxt = None
                self.tail = self.tail.prev
            else:
                self.tail = self.head = None
            self.size -= 1
        return cur.elm

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

    def __str__(self):
        cur = self.head
        output = ""
        while cur:
            output += str(cur.elm) + " "
            cur = cur.nxt
        return output


n = int(input())

V = [list(map(str, input().split())) for _ in range(n)]
dl = MyDLList()

for i in V:
    if i[0] == "insert":
        dl.insert(int(i[1]))
    elif i[0] == "delete":
        dl.delete(int(i[1]))
    elif i[0] == "deleteFirst":
        dl.delete_first()
    elif i[0] == "deleteLast":
        dl.delete_last()

print(dl)

Submission status: WA: Presentation Error

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

    def __init__(self, elm=None, prev=None, nxt=None):
        self.elm = elm
        self.prev = prev
        self.nxt = nxt


class MyDLList:
    size = 0
    head = tail = None

    def insert(self, elm):
        if self.is_empty():
            self.head = self.tail = Node(elm)
        else:
            x = Node(elm)
            x.nxt = self.head
            self.head.prev = x
            self.head = x
        self.size += 1

    def list_search(self, x):
        cur = self.head
        while cur != self.tail and cur.elm != x:
            cur = cur.nxt
        if cur.elm != x:
            cur = None
        return cur

    def delete(self, x):
        cur = self.list_search(x)
        if cur:
            if cur == self.head:
                self.delete_first()
            elif cur == self.tail:
                self.delete_last()
            else:
                cur.prev.nxt = cur.nxt
                cur.nxt.prev = cur.prev
            self.size -= 1
        else:
            pass

    def delete_first(self):
        cur = self.head
        if not self.is_empty():
            if self.head != self.tail:
                self.head.nxt.prev = None
                self.head = self.head.nxt
            else:
                self.head = self.tail = None
            self.size -= 1

    def delete_last(self):
        cur = self.tail
        if not self.is_empty():
            if self.head != self.tail:
                self.tail.prev.nxt = None
                self.tail = self.tail.prev
            else:
                self.tail = self.head = None
            self.size -= 1

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

    def __str__(self):
        cur = self.head
        output = ""
        while cur:
            output += str(cur.elm) + " "
            cur = cur.nxt
        return output


n = int(input())

V = [list(map(str, input().split())) for _ in range(n)]
dl = MyDLList()

for i in V:
    if i[0] == "insert":
        dl.insert(int(i[1]))
    elif i[0] == "delete":
        dl.delete(int(i[1]))
    elif i[0] == "deleteFirst":
        dl.delete_first()
    elif i[0] == "deleteLast":
        dl.delete_last()

print(dl)

Submission status: WA: Presentation Error

Solution code:
print(1, "")

Submission status: WA: Presentation Error

Solution code:
import sys


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

    def __init__(self):
        head = mydeque.cell(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 = mydeque.cell(x,q,h)
        h.next = p
        q.prev = p
        self.size += 1

    def push_back(self,x):
        h = self.head
        p = h.prev
        q = mydeque.cell(x,h,p)
        h.prev = q
        p.next = q
        self.size += 1

    def delete_top(self):
        h = self.head
        top = h.next
        nexttop = top.next
        h.next = nexttop
        nexttop.prev = h
        self.size -= 1

    def delete_last(self):
        h = self.head
        last = h.prev
        prevlast = last.prev
        h.prev = prevlast
        prevlast.next = h
        self.size -= 1

    def delete_find(self,target):
        h = self.head
        now_data = h.next
        while now_data != self.head:
            if now_data.data == target:
                next_now = now_data.next
                prev_now = now_data.prev
                next_now.prev = prev_now
                prev_now.next = next_now
                self.size -= 1
                break
            now_data = now_data.next

    def allprint(self):
        h = self.head.next
        for i in range(self.size):
            if i == self.size:
                sys.stdout.write(h.data)
            else:
                print(h.data, end=" ")
                h = h.next

# with open("input.txt","r") as f:
queue = int(input())
length = 0
myd = mydeque()
for q in range(queue):
    command = [n for n in input().strip("\n").split(' ')]
    if command[0] == "insert":
        myd.push_front(command[1])
    elif command[0] == "delete":
        myd.delete_find(command[1])
    elif command[0] == "deleteFirst":
        myd.delete_top()
    else:
        myd.delete_last()
myd.allprint()

Submission status: WA: Presentation Error

Solution code:
import sys


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

    def __init__(self):
        head = mydeque.cell(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 = mydeque.cell(x,q,h)
        h.next = p
        q.prev = p
        self.size += 1

    def push_back(self,x):
        h = self.head
        p = h.prev
        q = mydeque.cell(x,h,p)
        h.prev = q
        p.next = q
        self.size += 1

    def delete_top(self):
        h = self.head
        top = h.next
        nexttop = top.next
        h.next = nexttop
        nexttop.prev = h
        self.size -= 1

    def delete_last(self):
        h = self.head
        last = h.prev
        prevlast = last.prev
        h.prev = prevlast
        prevlast.next = h
        self.size -= 1

    def delete_find(self,target):
        h = self.head
        now_data = h.next
        while now_data != self.head:
            if now_data.data == target:
                next_now = now_data.next
                prev_now = now_data.prev
                next_now.prev = prev_now
                prev_now.next = next_now
                self.size -= 1
                break
            now_data = now_data.next

    def allprint(self):
        h = self.head.next
        for i in range(self.size):
            if i == self.size - 1:
                sys.stdout.write(h.data)
            else:
                print(h.data, end=" ")
                h = h.next

# with open("input.txt","r") as f:
queue = int(input())
length = 0
myd = mydeque()
for q in range(queue):
    command = [n for n in input().strip("\n").split(' ')]
    if command[0] == "insert":
        myd.push_front(command[1])
    elif command[0] == "delete":
        myd.delete_find(command[1])
    elif command[0] == "deleteFirst":
        myd.delete_top()
    else:
        myd.delete_last()
myd.allprint()

Submission status: WA: Presentation Error

Solution code:
import sys


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

    def __init__(self):
        head = mydeque.cell(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 = mydeque.cell(x,q,h)
        h.next = p
        q.prev = p
        self.size += 1

    def push_back(self,x):
        h = self.head
        p = h.prev
        q = mydeque.cell(x,h,p)
        h.prev = q
        p.next = q
        self.size += 1

    def delete_top(self):
        h = self.head
        top = h.next
        nexttop = top.next
        h.next = nexttop
        nexttop.prev = h
        self.size -= 1

    def delete_last(self):
        h = self.head
        last = h.prev
        prevlast = last.prev
        h.prev = prevlast
        prevlast.next = h
        self.size -= 1

    def delete_find(self,target):
        h = self.head
        now_data = h.next
        while now_data != self.head:
            if now_data.data == target:
                next_now = now_data.next
                prev_now = now_data.prev
                next_now.prev = prev_now
                prev_now.next = next_now
                self.size -= 1
                break
            now_data = now_data.next

    def allprint(self):
        h = self.head.next
        for i in range(self.size):
            if i == self.size - 1:
                print(h.data, end="")
            else:
                print(h.data, end=" ")
                h = h.next

# with open("input.txt","r") as f:
queue = int(input())
length = 0
myd = mydeque()
for q in range(queue):
    command = [n for n in input().strip("\n").split(' ')]
    if command[0] == "insert":
        myd.push_front(command[1])
    elif command[0] == "delete":
        myd.delete_find(command[1])
    elif command[0] == "deleteFirst":
        myd.delete_top()
    else:
        myd.delete_last()
myd.allprint()

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

for i in range(len(lin)):
    print (lin[0], end = "")

Submission status: WA: Presentation Error

Solution code:
import sys

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

Submission status: WA: Presentation Error

Solution code:
import sys

class Node:
    def __init__(self, num):
        self.prev = None
        self.next_node = None
        self.num = num
    def delete(self):
        if self.prev is not None:
            self.prev.next_node = self.next_node
        if self.next_node is not None:
            self.next_node.prev = self.prev

'''
class LinkedList:
    def __init__(self):
        self.node_list = []
    def add(self, num):
        node = Node(num)
        if len(self.node_list) != 0:
            node.prev = self.node_list[-1]
            self.node_list[-1].next_node = node
        self.node_list.append(node)
    def delete(self, num):
        for (i, node) in enumerate(reversed(self.node_list)):
            if node.num == num:
                node.delete()
                self.node_list.pop(len(self.node_list) - i - 1)
                break
    def delete_last(self):
        self.node_list[0].delete()
        self.node_list.pop(0)
    def delete_first(self):
        self.node_list[-1].delete()
        self.node_list.pop()
    def __str__(self):
        s = ""
        for n in reversed(self.node_list):
            s += str(n.num) + " "
        s = s.strip()
        return s
'''

class LinkedList:
    def __init__(self):
        self.start_node = None
        self.last_node = None
    def add(self, num):
        node = Node(num)
        if self.start_node is None:
            self.start_node = node
        elif self.last_node is None:
            self.last_node = self.start_node
            node.next_node = self.last_node
            self.last_node.prev = node
            self.start_node = node
        else:   
            self.start_node.prev = node
            node.next_node = self.start_node
            self.start_node = node
    def delete(self, num):
        node = self.start_node
        while node is not None:
            if node.num == num:
                if node == self.start_node:
                    self.delete_first()
                elif node == self.last_node:
                    self.delete_last()
                else:
                    node.delete()
                break
            node = node.next_node
    def delete_last(self):
        node = self.last_node
        self.last_node = self.last_node.prev
        node.delete()
    def delete_first(self):
        node = self.start_node
        self.start_node = self.start_node.next_node
        node.delete()
    def __str__(self):
        s = ""
        node = self.start_node
        while node is not None:
            s += str(node.num) + " "
            node = node.next_node
        return s

def main():
    linked_list = LinkedList()
    c_num = int(sys.stdin.readline().strip())
    for i in range(0, c_num):
        line = sys.stdin.readline().strip().split(" ")
        op = line[0]
        if op == "insert":
            linked_list.add(int(line[1]))
        if op == "delete":
            linked_list.delete(int(line[1]))
        if op == "deleteFirst":
            linked_list.delete_first()
        if op == "deleteLast":
            linked_list.delete_last()
    print str(linked_list)
    
if __name__ == "__main__":
    main()

Submission status: WA: Presentation Error

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

Submission status: WA: Presentation Error

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

Submission status: WA: Presentation Error

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

    for i in linked:
        print(i, end=" ")
    print("")


orders = []

n = int(input())

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

order_each(orders)

Submission status: WA: Presentation Error

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

    for i in linked:
        print(i, end=" ")


orders = []

n = int(input())

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

order_each(orders)

Submission status: WA: Presentation Error

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

    print(''.join(linked))


orders = []

n = int(input())

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

order_each(orders)

Submission status: WA: Presentation Error

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

d = deque()

for _ in range(n):
    com = input()
    if ( len(com) == 8):
        com , i = com.split()

    if (com[0] == 'i'):
        d.appendleft(int(i))
    elif (com[0] == 'd'):
        if (len(com) == 6):
            d.remove(int(i))
        elif (com[6] == 'F'):
            d.popleft()
        elif (com[6] == 'L'):
            d.pop()

for i in d:
    print(i, end=' ')

Submission status: WA: Presentation Error

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

class Node():
    def __init__(self, key, prev=None, nex=None):
        self.key = key
        self.prev = prev
        self.next = nex
    
class DoublyLinkedLiset():
    def __init__(self):
        self.nil = Node(None)
        self.nil.next = self.nil
        self.nil.prev = self.nil
    
    def insert(self, x):
        X = Node(x)
        X.next = self.nil.next
        self.nil.next.prev = X
        self.nil.next = X
        X.prev = self.nil

    def listSearch(self, x):
        cur = self.nil.next
        while (cur != self.nil and cur.key != key):
            cur = cur.next
        
        return cur

    def deleteNode(self, X):
        if X == self.nil:
            return
        X.prev.next = X.next
        X.next.prev = X.prev
        del X

    def deleteFirst(self):
        self.deleteNode(self.nil.next)

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

    def deleteKey(self, x):
        self.deleteNode(self.listSearch(x))

    def printList(self):
        cur = self.nil.next
        while cur != self.nil:
            print(cur.key, end=" ")
            cur = cur.next
        print()

if __name__ == '__main__':

    n = int(input())
    dll = DoublyLinkedLiset()

    for i in range(n):
        line = input().split(" ")
        if len(line) == 2:
            command, key = line
            if command == "insert":
                dll.insert(key)
            elif command == "delete":
                dll.deleteKey(key)

        else:
            command = line[0]
            if command == "deleteFirst":
                dll.deleteFirst()
            elif command == "deleteLast":
                dll.deleteLast()

    dll.printList()

Submission status: WA: Presentation Error

Solution code:
k = int(input())
d = dict()
total = ""

def get_first_key():
    for key2 in d.keys():
        return key2
        
def get_nth_key(dictionary, n):
    if n < 0:
        n += len(dictionary)
    for i, key in enumerate(dictionary.keys()):
        if i == n:
            return key

for i in range(k):
        move = input()
        key = move[7:]
        if move[0:7] == "insert ":
            d[key] = 1
        elif move[0:7] == "delete ":
            d.pop(key, None)
        elif move[0:7] == "deleteF":
            d.pop(get_first_key())
        elif move[0:7] == "deleteL":
            d.pop(get_nth_key(d, -1))

for value in d.keys():
  total += value + " "
  
print(total)

Submission status: WA: Presentation Error

Solution code:
x = int(input())
alist = []
b = []
for i in range(x):
    a = input().split( )

    if a[0] == "insert":
        alist.append(a[1])

    elif a[0] == "delete":
        alist.remove(a[1])

    elif a[0] == "deleteFirst":
        alist.pop(0)

    elif a[0] == "deleteLast":
        alist.pop(len(alist)-1)

for i in range(len(alist)):
    if(i == len(alist)):
        print(alist.pop())
    else:
        print(alist.pop(),end=' ')