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: Wrong Answer

Solution code:
class Deque:
    class Node:  # ??????????????????
        def __init__(self, x, y=None, z=None):
            self.key = x
            self.next = y
            self.prev = z

        def search(self, x):  # listSearch??¨???????????????????????????????????????
            if(self.key == x or self.key is None):
                return self
            else:
                return self.next.search(x)

        def delete(self):
            self.prev.next = self.next
            self.next.prev = self.prev

    def __init__(self):
        self.size = 0
        self.head = Deque.Node(None)
        self.tail = Deque.Node(None, self.head, None)
        self.head.prev = self.tail

    # insert x:??£??????????????????????????????x?????????????´???????????¶????
    def insert(self, x):
        p = Deque.Node(x, self.head, self.head.prev)
        self.head.prev.next = p
        self.head.prev = p
        self.size += 1

    # deleteFirst:??£????????????????????????????´???????????????????
    def deleteFirst(self):
        if self.size == 0:
            raise IndexError
        self.head.prev.delete()
        self.size -= 1

    # deleteLast:??£???????????????????°????????´???????????????????
    def deleteLast(self):
        if self.size == 0:
            raise IndexError
        self.tail.next.delete()
        self.size -= 1

    # ???????????????????????¢?´¢
    def listSearch(self, x):
        return self.tail.next.search(x)

    # ??¢?´¢?????\????£?
    def listSearch2(self, x):
        node = self.tail.next
        while(node.key is not None):
            if(node.key == x):
                return node
            else:
                node = node.next

    # delete:x???????????????????´??????????????????°?????¢?´¢????????¨
    def delete(self, x):
        if self.size == 0:
            raise IndexError
        node = self.listSearch(x)
        if(node.key is not None):
            node.delete()
        self.size -= 1

    # ??????
    def printList(self):
        ret = []
        node = self.tail.next
        while node.key is not None:
            ret.append(str(node.key))
            node = node.next
        print(" ".join(ret))


n = int(input())
d = Deque()
for i in range(n):
    i = input().split()
    if i[0] == "insert":
        x = int(i[1])
        d.insert(x)
    if i[0] == "delete":
        x = int(i[1])
        d.delete(x)
    if i[0] == "deleteFirst":
        d.deleteFirst()
    if i[0] == "deleteLast":
        d.deleteLast()
d.printList()

Submission status: Wrong Answer

Solution code:
class Deque:
    class Node:  # ??????????????????
        def __init__(self, x, y=None, z=None):
            self.key = x
            self.next = y
            self.prev = z

        def search(self, x):  # listSearch??¨???????????????????????????????????????
            if(self.key == x or self.key is None):
                return self
            else:
                return self.next.search(x)

        def delete(self):
            self.prev.next = self.next
            self.next.prev = self.prev

    def __init__(self):
        self.size = 0
        self.head = Deque.Node(None)
        self.tail = Deque.Node(None, self.head, None)
        self.head.prev = self.tail

    # insert x:??£??????????????????????????????x?????????????´???????????¶????
    def insert(self, x):
        p = Deque.Node(x, self.head, self.head.prev)
        self.head.prev.next = p
        self.head.prev = p
        self.size += 1

    # deleteFirst:??£????????????????????????????´???????????????????
    def deleteFirst(self):
        if self.size == 0:
            raise IndexError
        self.head.prev.delete()
        self.size -= 1

    # deleteLast:??£???????????????????°????????´???????????????????
    def deleteLast(self):
        if self.size == 0:
            raise IndexError
        self.tail.next.delete()
        self.size -= 1

    # ???????????????????????¢?´¢
    def listSearch(self, x):
        return self.tail.next.search(x)

    # ??¢?´¢?????\????£?
    def listSearch2(self, x):
        node = self.tail.next
        while(node.key is not None):
            if(node.key == x):
                return node
            else:
                node = node.next

    # delete:x???????????????????´??????????????????°?????¢?´¢????????¨
    def delete(self, x):
        if self.size == 0:
            raise IndexError
        node = self.listSearch(x)
        if(node.key is not None):
            node.delete()
        self.size -= 1

    # ??????
    def printList(self):
        ret = []
        node = self.head.prev
        while node.key is not None:
            ret.append(str(node.key))
            node = node.prev
        print(" ".join(ret))


n = int(input())
d = Deque()
for i in range(n):
    i = input().split()
    if i[0] == "insert":
        x = int(i[1])
        d.insert(x)
    if i[0] == "delete":
        x = int(i[1])
        d.delete(x)
    if i[0] == "deleteFirst":
        d.deleteFirst()
    if i[0] == "deleteLast":
        d.deleteLast()
d.printList()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys


class Deque:
    class Node:  # ??????????????????
        def __init__(self, x, y=None, z=None):
            self.key = x
            self.next = y
            self.prev = z

        def search(self, x):  # listSearch??¨???????????????????????????????????????
            if(self.key == x or self.key is None):
                return self
            else:
                return self.next.search(x)

        def delete(self):
            self.prev.next = self.next
            self.next.prev = self.prev

    def __init__(self):
        self.size = 0
        self.head = Deque.Node(None)
        self.tail = Deque.Node(None, self.head, None)
        self.head.prev = self.tail

    # insert x:??£??????????????????????????????x?????????????´???????????¶????
    def insert(self, x):
        p = Deque.Node(x, self.head, self.head.prev)
        self.head.prev.next = p
        self.head.prev = p
        self.size += 1

    # deleteFirst:??£????????????????????????????´???????????????????
    def deleteFirst(self):
        if self.size == 0:
            raise IndexError
        self.head.prev.delete()
        self.size -= 1

    # deleteLast:??£???????????????????°????????´???????????????????
    def deleteLast(self):
        if self.size == 0:
            raise IndexError
        self.tail.next.delete()
        self.size -= 1

    # ???????????????????????¢?´¢
    def listSearch(self, x):
        return self.tail.next.search(x)

    # ??¢?´¢?????\????£?
    def listSearch2(self, x):
        node = self.tail.next
        while(node.key is not None):
            if(node.key == x):
                return node
            else:
                node = node.next

    # delete:x???????????????????´??????????????????°?????¢?´¢????????¨
    def delete(self, x):
        if self.size == 0:
            raise IndexError
        node = self.listSearch(x)
        if(node.key is not None):
            node.delete()
        self.size -= 1

    # ??????
    def printList(self):
        ret = []
        node = self.tail.next
        while node.key is not None:
            ret.append(str(node.key))
            node = node.next
        print(" ".join(ret))


n = int(input())
d = Deque()
for inpt in sys.stdin.read().splitlines():
    i = inpt.split()
    print(i)
    if i[0] == "insert":
        x = int(i[1])
        d.insert(x)
    if i[0] == "delete":
        x = int(i[1])
        d.delete(x)
    if i[0] == "deleteFirst":
        d.deleteFirst()
    if i[0] == "deleteLast":
        d.deleteLast()
d.printList()

Submission status: Wrong Answer

Solution code:
import sys
res = dict()
dll = [None] * 2000000
left = 0
right = 0
n = int(input())
for inpt in sys.stdin.read().splitlines():
    i = inpt.split()
    if i[0] == "insert":
        x = int(i[1])
        dll[left] = x
        if(x in res):
            res[x].append(left)
        else:
            res[x] = [left]
        left += 1
    if i[0] == "delete":
        x = int(i[1])
        if(x in res):
            ind = max(res[x])
            dll[ind] = None
            res[x].remove(ind)
            if(len(res[x]) == 0):
                del res[x]
            if(ind == (left - 1)):
                left = ind
    if i[0] == "deleteFirst":
        left -= 1
        dll[left] = None
    if i[0] == "deleteLast":
        right += 1
ret = []
for i in range(right, left):
    ind = left - 1 - i
    if(dll[ind] is not None):
        ret.append(str(dll[ind]))
print(" ".join(ret))

Submission status: Wrong Answer

Solution code:
import sys
res = dict()
dll = [None] * 2000000
left = 0
right = 0
n = int(input())
for inpt in sys.stdin.read().splitlines():
    i = inpt.split()
    if i[0] == "insert":
        x = int(i[1])
        dll[left] = x
        if(x in res):
            res[x].append(left)
        else:
            res[x] = [left]
        left += 1
    if i[0] == "delete":
        x = int(i[1])
        if(x in res):
            ind = max(res[x])
            dll[ind] = None
            res[x].remove(ind)
            if(len(res[x]) == 0):
                del res[x]
            if(ind == (left - 1)):
                left = ind
            if(ind == right):
                right += 1
    if i[0] == "deleteFirst":
        left -= 1
        dll[left] = None
    if i[0] == "deleteLast":
        right += 1
    # print(dll[right:left])
ret = []
for x in dll[right:left]:
    if(x is not None):
        ret.append(str(x))
ret.reverse()
print(" ".join(ret))

Submission status: Wrong Answer

Solution code:
#ALDS1_3-C Elementary data structures - Doubly Linked List
import collections
import sys

def insert(x):
    q.append(x[1])

def delete(x):
    try:
        q.remove(x[1])
    except:
        pass

def deleteFirst(x):
    q.popleft()

def deleteLast(x):
    q.pop()

q = collections.deque()
n=int(input())
_input = sys.stdin.readlines()
cmds={"insert":insert,
      "delete":delete,
      "deleteFirst":deleteFirst,
      "deleteLast":deleteLast,
     }

for i in range(n):
    cmd=_input[i].split()
    cmds[cmd[0]](cmd)
print(*q)

Submission status: Wrong Answer

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

deque = deque()
n = int(sys.stdin.readline())
input_lines = sys.stdin.readlines()
print(input_lines)

for i in range(n):
    inp = input_lines[i].split()
    if inp[0] == 'insert':
        deque.appendleft(inp[1])
    elif inp[0] == 'deleteFirst':
        deque.popleft()
    elif inp[0] == 'deleteLast':
        deque.pop()
    else:
        if inp[1] in deque:
            deque.remove(inp[1])

print(*deque)

Submission status: Wrong Answer

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

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

class LinkedList:
    def __init__(self):
        self.head = None
        self.curr = None

    def insert(self, x):
        node = Node(x, self.head, None)
        self.head = node
        self.curr = node
        if self.curr.next is not None:
            self.curr.next.prev = node

    def delete(self, x):
        while True:
            if self.curr.data == x:
                if self.curr.next is None: # ??????node???delete???????????¨???
                    self.curr.prev.next = None
                else:
                    if self.curr.prev is not None:
                        self.curr.prev.next = self.curr.next # ????????????node???next?????§???curr???next
                    else:
                        self.head = self.curr.next
                    self.curr.next.prev = self.curr.prev # ????????????node???prev?????§???curr???prev
                break
            self.curr = self.curr.next
        self.curr = self.head

    def deleteFirst(self):
        self.curr = self.head
        if self.head is not None:
            if self.head.next is None:
                self.head = None
                self.curr = None
            else:
                self.head.next.prev = None
                self.head = self.head.next

    def deleteLast(self):
        self.curr = self.head
        while self.curr.next is not None:
            self.curr = self.curr.next
        if self.curr.prev is not None:
            self.curr.prev.next = None
        else:
            self.head = None
            self.curr = None

    def display(self):
        self.curr = self.head
        hoge = list()
        while self.curr is not None:
            hoge.append(str(self.curr.data))
            self.curr = self.curr.next
        print(" ".join(hoge))

linkedlist = LinkedList()
#linkedlist.insert(5)
#linkedlist.insert(2)
#linkedlist.insert(3)
#linkedlist.insert(1)
#linkedlist.delete(3)
#linkedlist.insert(6)
#linkedlist.delete(5)
#linkedlist.deleteFirst()
#linkedlist.deleteLast()
#linkedlist.display()

n = int(input())
for i in range(n):
    input_line = input()
    if input_line != "deleteFirst" and input_line != "deleteLast":
        command, key = input_line.split(" ")
        key = int(key)
    else:
        command = input_line
    if command == "insert":
        linkedlist.insert(key)
    elif command == "delete":
        linkedlist.delete(key)
    elif command == "deleteFirst":
        linkedlist.deleteFirst()
    elif command == "deleteLast":
        linkedlist.deleteLast()
linkedlist.display()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 21 08:50:28 2017

@author: syaga
"""

COMMAND = ["insert", "delete", "deleteFirst", "deleteLast"]

if __name__ == "__main__":
    n = int(input())
    com = []
    for i in range(n):
        com.append(input().split())
    print(com)
    ans = []
    for i in com:
        if i[0] == COMMAND[0]:
            ans.insert(0, i[1])
        elif i[0] == COMMAND[1]:
            ans.remove(i[1])
        elif i[0] == COMMAND[2]:
            ans.pop(0)
        elif i[0] == COMMAND[3]:
            ans.pop()
    print(" ".join(ans))

Submission status: Wrong Answer

Solution code:
n=int(raw_input())
lst = []
for _ in range(n):
    cmd = raw_input().split()
    if cmd[0] == "insert":
        lst.insert(0, int(cmd[1]))
    elif cmd[0] == "delete":
        if int(cmd[1]) in lst:
            lst.remove(int(cmd[1]))
    elif cmd[0] == "deleteFirst":
        if len(lst) > 0:
            lst.pop(0)
    elif cmd[0] == "deleteLast":
        if len(lst) > 0:
            lst.pop(-1)
    print lst

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

Submission status: Wrong Answer

Solution code:
from collections import deque

Submission status: Wrong Answer

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 = 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: Wrong Answer

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 = 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)
    print str(linked_list)
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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_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
            
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)
    print str(linked_list)
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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(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
            
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)
    print str(linked_list)
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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.strip()

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: Wrong Answer

Solution code:
import sys

l = []

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

def delete(lst,x):
	if x in lst:
		lst.remove(x)

def deleteFirst(lst):
	lst.pop(0)

def deleteLast(lst):
	lst.pop(len(lst)-1)


for i in range(n):
	c = sys.stdin.readline().strip().split(" ")
	if c[0]=="insert":
		l.append(int(c[1]))
	elif c[0]=="delete":
		delete(l,int(c[1]))
	elif c[0]=="deleteFirst":
		deleteFirst(l)
	elif c[0]=="deleteLast":
		deleteLast(l)
	print(l)

for a in l[::-1]:
	print(a),

Submission status: Wrong Answer

Solution code:
import sys

l = []

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

def delete(lst,x):
	if x in lst:
		lst.remove(x)

def deleteFirst(lst):
	lst.pop(0)

def deleteLast(lst):
	lst.pop(len(lst)-1)


for i in range(n):
	c = sys.stdin.readline().strip().split(" ")
	if c[0]=="insert":
		l.append(int(c[1]))
	elif c[0]=="delete":
		delete(l,int(c[1]))
	elif c[0]=="deleteFirst":
		deleteFirst(l)
	elif c[0]=="deleteLast":
		deleteLast(l)

for a in l[::-1]:
	print(a),

Submission status: Wrong Answer

Solution code:
import sys

l = []

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

def delete(lst,x):
	if x in lst:
		lst.remove(x)

def deleteFirst(lst):
	lst.pop(len(lst)-1)

def deleteLast(lst):
	lst.pop(0)


for i in range(n):
	c = sys.stdin.readline().strip().split(" ")
	if c[0]=="insert":
		l.append(int(c[1]))
	elif c[0]=="delete":
		delete(l,int(c[1]))
	elif c[0]=="deleteFirst":
		deleteFirst(l)
	elif c[0]=="deleteLast":
		deleteLast(l)

for a in l[::-1]:
	print(a),

Submission status: Wrong Answer

Solution code:
import sys

l = []

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

def delete(lst,x):
	if x in lst:
		lst=lst[::-1]
		lst.remove(x)
		lst=lst[::-1]

def deleteFirst(lst):
	lst.pop(len(lst)-1)

def deleteLast(lst):
	lst.pop(0)


for i in range(n):
	c = sys.stdin.readline().strip().split(" ")
	if c[0]=="insert":
		l.append(int(c[1]))
	elif c[0]=="delete":
		delete(l,int(c[1]))
	elif c[0]=="deleteFirst":
		deleteFirst(l)
	elif c[0]=="deleteLast":
		deleteLast(l)
	print(l[::-1])
for a in l[::-1]:
	print(a),

Submission status: Wrong Answer

Solution code:
import sys

l = []

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

def delete(lst,x):
	if x in lst:
		lst=lst[::-1]
		lst.remove(x)
		lst=lst[::-1]

def deleteFirst(lst):
	lst.pop(len(lst)-1)

def deleteLast(lst):
	lst.pop(0)


for i in range(n):
	c = sys.stdin.readline().strip().split(" ")
	if c[0]=="insert":
		l.append(int(c[1]))
	elif c[0]=="delete":
		delete(l,int(c[1]))
	elif c[0]=="deleteFirst":
		deleteFirst(l)
	elif c[0]=="deleteLast":
		deleteLast(l)

for a in l[::-1]:
	print(a),