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:
def pr(data,next,head,tail):
    i = head
    while(1):
        print(data[i],end = "")
        i = next[i]
        if i == -1:
            print("")
            break
        else :
            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 = 0
        head = 0
    return head,tail

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


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

def dl_l(next,prev,tail):
    if tail == -1:
        return tail
    next[prev[tail]] = -1
    tail = prev[tail]
    return 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":
        dl(data,next,prev,x[1],head,tail)
    elif x[0] == "deleteFirst":
        head = dl_f(next,prev,head)
    elif x[0] == "deleteLast":
        tail = dl_l(next,prev,tail)
#    print(data)

pr(data,next,head,tail)

Submission status: Wrong Answer

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

Solution code:
def pr(data,next,head,tail):
    i = head
    while(1):
        print(data[i],end = "")
        i = next[i]
        if i == -1:
            print("")
            break
        else :
            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 = 0
        head = 0
    return head,tail

def dl(data,next,prev,x,head,tail):
    i = head
    while(1):
        if data[i] == x:
            if i == head:
                head = next[head]
            if i == tail:
                tail = prev[tail]
            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):
    if head == -1:
        return head
    prev[next[head]] = -1
    head = next[head]
    return head

def dl_l(next,prev,tail):
    if tail == -1:
        return tail
    next[prev[tail]] = -1
    tail = prev[tail]
    return 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":
        haed,tail = dl(data,next,prev,x[1],head,tail)
    elif x[0] == "deleteFirst":
        head = dl_f(next,prev,head)
    elif x[0] == "deleteLast":
        tail = dl_l(next,prev,tail)

pr(data,next,head,tail)

Submission status: Wrong Answer

Solution code:
def pr(data,next,head,tail):
    i = head
    while(1):
        print(data[i],end = "")
        i = next[i]
        if i == -1:
            print("")
            break
        else :
            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 = 0
        head = 0
    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):
    if head == -1:
        return head
    prev[next[head]] = -1
    head = next[head]
    return head

def dl_l(next,prev,tail):
    if tail == -1:
        return tail
    next[prev[tail]] = -1
    tail = prev[tail]
    return 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 = dl_f(next,prev,head)
    elif x[0] == "deleteLast":
        tail = dl_l(next,prev,tail)
pr(data,next,head,tail)

Submission status: Wrong Answer

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

Solution code:

n=int(input())
list=[]
ok=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]):
				ok=1
		if ok==1:
			list.remove(int(l[1]))
			
	elif l[0]=="deleteFirst":
		del list[0]
		
	elif l[0]=="deleteLast":
		del list[len(list)-1]
	ok=0


print(list)

Submission status: Wrong Answer

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

Solution code:
lst=[]

n=int(input())
for i in range(n):
    ts=[x for x in input().split()]
    t=ts[0]
    if t=='insert' or t=='delete':
        s=ts[1]   
    if t=='insert':
        lst.insert(0,s)
    elif t=='delete':
        lst.remove(s)      
    elif t=='deleteFirst':
        lst.pop(0)
    elif t=='deleteLast':
        lst.pop(-1)
            
for i in lst:
    print (i)

Submission status: Wrong Answer

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'):
        if(li[1] in output):
            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: Wrong Answer

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:
            key = int(command[1])
            if command[0][0] == 'i': list.append(key)
            else:
                if key in list: list.remove(key)
        else:
            if command[0][6] == 'F': del list[0]
            else: list.pop()
    show(list)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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:
            key = int(command[1])
            if command[0][0] == 'i': list.append(key)
            else:
                if key in list: list.remove(key)
        else:
            if command[0][6] == 'L': del list[0]
            else: list.pop()
    show(list)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#coding:utf-8

n = int(input())
doublyList = []
for i in range(n):
    order = list(input().split())
    if len(order) == 2:
        if order[0] == "insert":
            doublyList.insert(0, order[1])
        if order[0] == "delete":
            for j,data in enumerate(doublyList):
                if data == order[1]:
                    doublyList.pop(j)

                    
    else:
        if order[0] == "deleteFirst" :
            doublyList.pop(0)
        if order[0] == "deleteLast":
            doublyList.pop()

doublyList = " ".join(doublyList)
print(doublyList)

Submission status: Wrong Answer

Solution code:
def assign(linked_list, commmand, x):
    if command == 'insert':
        linked_list.insert(0, int(x))
    if command == 'delete':
        if x in linked_list:
            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(linked_list)
print(' '.join(map(str, linked_list)))

Submission status: Wrong Answer

Solution code:
def assign(linked_list, commmand, x):
    if command == 'insert':
        linked_list.insert(0, int(x))
    if command == 'delete':
        if x in linked_list:
            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: Wrong Answer

Solution code:
#coding:utf-8
n = int(input())

class LinkedList:
    class Cell:
        def __init__(self, x, y=None, z=None):
            # セルを構成（ｘが値、ｙが次のセルの値、ｚが前のセルの値）
            self.data = x
            self.nex = y
            self.pre = z

    def __init__(self, *args):
        head = LinkedList.Cell(None)# オブジェクトを作る準備
        head.nex = head #ヘッダーの右隣のセル
        head.pre = head #ヘッダーの左隣のセル
        self.size = 0
        self.head = head #ヘッダー

    def push_front(self, x):
        h = self.head###ヘッダーのオブジェクトを呼び出し
        q = h.nex   ###qはヘッダーの右隣のセルをｑとおく
        p = LinkedList.Cell(x, q, h) #ｘを値とするセルｐの作成
        h.nex = p #ヘッダーの右隣のセルをｐとする
        q.pre = p #ｑのセルをｐとする
        self.size += 1

    def push_back(self, x):
        h = self.head
        p = h.pre
        q = LinkedList.Cell(x, h, p)
        h.pre = q
        p.next = q
        self.size += 1

    def pop_front(self):
        h = self.head
        q = h.nex
        p = q.nex
        p.pre = h
        h.nex = p
        self.size -= 1

    def pop_back(self):
        h = self.head
        p = h.pre
        q = p.pre
        q.nex = h
        h.pre = q
        self.size -= 1

    def delete(self, x):
        cp = self.head
        i = 0
        while i < self.size:
            i += 1
            cp = cp.nex
            if cp.data == x:
                cp_pre = cp.pre
                cp_nex = cp.nex
                cp_pre.nex = cp_nex
                cp_nex.pre = cp_pre
        return None
            

l = LinkedList()
for i in range(n):
    order = list(input().split())
    if order[0] == "insert":
        l.push_front(order[1])
    elif order[0] == "delete":
        l.delete(order[1])
    elif order[0] == "deleteFirst":
        l.pop_front()
    else:
        l.pop_back()

head = l.head
numList = []
for i in range(l.size-2):
    head = head.nex
    numList.append(head.data)

numList = " ".join([str(num) for num in numList])
print(numList)

Submission status: Wrong Answer

Solution code:
#coding:utf-8
n = int(input())

class LinkedList:
    class Cell:
        def __init__(self, x, y=None, z=None):
            # セルを構成（ｘが値、ｙが次のセルの値、ｚが前のセルの値）
            self.data = x
            self.nex = y
            self.pre = z

    def __init__(self, *args):
        head = LinkedList.Cell(None)# オブジェクトを作る準備
        head.nex = head #ヘッダーの右隣のセル
        head.pre = head #ヘッダーの左隣のセル
        self.size = 0
        self.head = head #ヘッダー

    def push_front(self, x):
        h = self.head###ヘッダーのオブジェクトを呼び出し
        q = h.nex   ###qはヘッダーの右隣のセルをｑとおく
        p = LinkedList.Cell(x, q, h) #ｘを値とするセルｐの作成
        h.nex = p #ヘッダーの右隣のセルをｐとする
        q.pre = p #ｑのセルをｐとする
        self.size += 1

    def push_back(self, x):
        h = self.head
        p = h.pre
        q = LinkedList.Cell(x, h, p)
        h.pre = q
        p.next = q
        self.size += 1

    def pop_front(self):
        h = self.head
        q = h.nex
        p = q.nex
        p.pre = h
        h.nex = p
        self.size -= 1

    def pop_back(self):
        h = self.head
        p = h.pre
        q = p.pre
        q.nex = h
        h.pre = q
        self.size -= 1

    def delete(self, x):
        cp = self.head
        i = 0
        while i < self.size:
            i += 1
            cp = cp.nex
            if cp.data == x:
                cp_pre = cp.pre
                cp_nex = cp.nex
                cp_pre.nex = cp_nex
                cp_nex.pre = cp_pre
                self.size -= 1
        return None
            

l = LinkedList()
for i in range(n):
    order = list(input().split())
    if order[0] == "insert":
        l.push_front(order[1])
    elif order[0] == "delete":
        l.delete(order[1])
    elif order[0] == "deleteFirst":
        l.pop_front()
    else:
        l.pop_back()

head = l.head
numList = []
for i in range(l.size):
    head = head.nex
    numList.append(head.data)

numList = " ".join([str(num) for num in numList])
print(numList)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque

class LinkedList(object):
    class Node(object):
        def __init__(self, value, next=None, prev=None):
            self.value = value
            self.next = next
            self.prev = prev

    def __init__(self, dtype):
        self.dtype = dtype
        self.dummy = LinkedList.Node(dtype())
        self.dummy.next = self.dummy
        self.dummy.prev = self.dummy

        self.dict = defaultdict(deque)

    def insert(self, x):
        node = LinkedList.Node(x, self.dummy.next, self.dummy)

        self.dummy.next.prev = node
        self.dummy.next = node

        self.dict[x].append(node)
    
    def delete(self, x):
        if x in self.dict:
            queue = self.dict[x]
            if len(queue) > 0:
                node = queue.popleft()
                self.__remove_node(node)
    
    def deleteLast(self):
        node = self.dummy.prev
        if node != self.dummy:
            self.__remove_node(node)
            self.dict[node.value].pop()
    
    def deleteFirst(self):
        node = self.dummy.next
        if node != self.dummy:
            self.__remove_node(node)
            self.dict[node.value].popleft()

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

    def items(self):
        node = self.dummy.next
        while node != self.dummy:
            yield node.value
            node = node.next


store = LinkedList(str)
for i in range(int(input())):
    parts = input().split()
    cmd = parts[0]
    if cmd == 'insert':
        store.insert(parts[1])
    elif cmd == 'delete':
        store.delete(parts[1])
    elif cmd == 'deleteFirst':
        store.deleteFirst()
    elif cmd =='deleteLast':
        store.deleteLast()

print(' '.join(store.items()))

Submission status: Wrong Answer

Solution code:
import sys

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

class DoublyLinkedList:
	def __init__(self):
		self.head = None
		self.tail = None
		self.size = 0
	
	def get_size(self):
		return self.size
	
	def is_empty(self):
		return self.size == 0
	
	def appendToHead(self, value):
		node = Node(value)
		if self.head == None and self.tail == None:
			self.head = self.tail = node
		else:
			node.next = self.head
			self.head.prev = node
			self.head = node
		self.size += 1
	
	def removeFirst(self):
		if self.is_empty(): return
		if self.size == 1:
			self.head = self.head = None
		else:			
			self.head = self.head.next
			self.head.prev = None
		self.size -= 1
		
	def removeLast(self):
		if self.is_empty(): return 
		if self.size == 1:
			self.head = self.tail = None
		else:
			self.tail = self.tail.prev
			self.tail.next = None
		self.size -= 1

	def remove(self, value):
		if self.is_empty(): return
		if self.head.value == value:
			self.removeFirst()
		else:
			node = self.head.next
			while node != None:
				if node.value == value:
					node.prev.next = node.next
					if node.next != None:
						node.next.prev = node.prev
					self.size -= 1
					break
				else:
					node = node.next
		
	def print(self):
			node = self.head
			while node != None:
				sys.stdout.write(str(node.value))
				node = node.next
				if node != None:
					sys.stdout.write(' ')
	
n = int(input())
dll = DoublyLinkedList()
for i in range(n):
	cmd = str(input())
	if cmd == 'deleteFirst':
		dll.removeFirst()
	elif cmd == 'deleteLast':
		dll.removeLast()
	else:
		cmd, value = cmd.split()
		if cmd == 'insert':
			dll.appendToHead(int(value))
		elif cmd == 'delete':
			dll.remove(int(value))
		else:
			print('Unknown command:' + cmd)
	
dll.print()

Submission status: Wrong Answer

Solution code:
import sys

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

class DoublyLinkedList:
	def __init__(self):
		self.head = None
		self.tail = None
		self.size = 0
	
	def get_size(self):
		return self.size
	
	def is_empty(self):
		return self.size == 0
	
	def appendToHead(self, value):
		node = Node(value)
		if self.head == None and self.tail == None:
			self.head = self.tail = node
		else:
			node.next = self.head
			self.head.prev = node
			self.head = node
		self.size += 1
	
	def removeFirst(self):
		if self.is_empty(): return
		if self.size == 1:
			self.head = self.head = None
		else:			
			self.head = self.head.next
			self.head.prev = None
		self.size -= 1
		if self.size == 1:
			self.tail = self.head
		
		
	def removeLast(self):
		if self.is_empty(): return 
		if self.size == 1:
			self.head = self.tail = None
		else:
			self.tail = self.tail.prev
			self.tail.next = None
		self.size -= 1
		if self.size == 1:
			self.head = self.tail

	def remove(self, value):
		if self.is_empty(): return
		if self.head.value == value:
			self.removeFirst()
		else:
			node = self.head.next
			while node != None:
				if node.value == value:
					node.prev.next = node.next
					if node.next != None:
						node.next.prev = node.prev
					self.size -= 1
					break
				else:
					node = node.next
		
	def print(self):
			node = self.head
			while node != None:
				sys.stdout.write(str(node.value))
				node = node.next
				if node != None:
					sys.stdout.write(' ')
	
n = int(input())
dll = DoublyLinkedList()
for i in range(n):
	cmd = str(input())
	if cmd == 'deleteFirst':
		dll.removeFirst()
	elif cmd == 'deleteLast':
		dll.removeLast()
	else:
		cmd, value = cmd.split()
		if cmd == 'insert':
			dll.appendToHead(int(value))
		elif cmd == 'delete':
			dll.remove(int(value))
		else:
			print('Unknown command:' + cmd)
	
dll.print()

Submission status: Wrong Answer

Solution code:
class Node():
    key = 0
    def __init__( self,  key ):
        self.key = key
        self.next = -1
        self.pre = -1

    def insert( self, othernode ): # othernodeにはinsert前の先頭のノードを入れる
        self.next = othernode
        othernode.pre = self
        return self

    def delete( self, x ): #先頭ノードで実行
        if self.key == x and self.pre != -1:
            self.pre.next = self.next
            self.next.pre = self.pre
        elif self.pre != -1:
            self.next.delete( x )

    def printNodes( self ): #先頭ノードで実行
        if self.next.next != -1:
            print( str( self.key ), end=" " )
            self.next.printNodes()
        elif self.next != -1:
            print( str( self.key ), end="\n" )

    def deleteFirst( self ):
        self.next.pre = -1
        return self.next #新しい先頭ノードを返す

    def deleteLast( self ):
        if self.next != -1:
            self.next.deleteLast()
        else :
            self.pre.next = -1


def main():
    n = int( input() )
    commands = []
    vals = []
    for i in range(n):
        tmp = input().split()
        tmp.append( 0 )
        commands.append( tmp[0] )
        vals.append( int(tmp[1]) )

    FirstNode = Node( None )
    for i in range(n):
        if commands[i] == "insert":
            TmpNode = Node( vals[i] )
            FirstNode = TmpNode.insert( FirstNode )
        elif commands[i] == "delete":
            FirstNode.delete( vals[i] )
        elif commands[i] == "deleteFirst":
            FirstNode = FirstNode.deleteFirst()
        elif commands[i] == "deleteLast":
            FirstNode.deleteLast()
        else :
            print("command error!")

    FirstNode.printNodes()

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

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

    if command[0] == 'insert':
        key.append(command[1])
    elif command[0] == 'delete' and command[1] in key:
        key.remove(command[1])
    elif command[0] == 'deleteFirst':
        del key[0]
    elif command[0] == 'deleteLast':
        del key[-1]

for i in range(len(key)):
    if i == len(key) - 1:
        print('{0}'.format(key[i]))
    else:
        print('{0}'.format(key[i]), end=' ')

Submission status: Wrong Answer

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

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

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

    if command[0] == 'insert':
        key.append(command[1])
    elif command[0] == 'delete' and command[1] in key:
        key.remove(command[1])
    elif command[0] == 'deleteFirst':
        del key[0]
    elif command[0] == 'deleteLast':
        del key[-1]

for i in range(len(key)):
    if i == len(key) - 1:
        print('{0}'.format(key[i]))
    else:
        print('{0}'.format(key[i]), end=' ')

Submission status: Wrong Answer

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

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

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

    if command[0] == 'insert':
        key.insert(1, command[1])
    elif command[0] == 'delete' and command[1] in key:
        key.remove(command[1])
    elif command[0] == 'deleteFirst':
        del key[0]
    elif command[0] == 'deleteLast':
        del key[-1]

for i in range(len(key)):
    if i == len(key) - 1:
        print('{0}'.format(key[i]))
    else:
        print('{0}'.format(key[i]), end=' ')

Submission status: Wrong Answer

Solution code:
class Node:
    def __init__(self,e = None):
        self.prev= self
        self.next= self
        self.ele = e

class DoubleList:
    def __init__(self):
        nil = Node() 
        self.start = self.end =nil
    def insert(self,target):
        temp = Node(e =target)
        temp.next = self.start
        self.start.prev = temp
        self.start = temp
    def delete(self,target):
       if self.start.ele != None:
            temp = self.start
            while temp.ele is not None:
                if temp.ele == target:
                    temp.prev.next = temp.next
                    temp.next.prev = temp.prev
                    break
                else :
                    temp= temp.next
    def deleteFirst(self):
        if self.start.ele !=None:
            temp =self.start
            self.start = temp.next
            temp.next.prev = self.start
    def deleteLast(self):
        if self.end != self.start:
            temp = self.end.prev
            temp.prev.next = self.end
            self.end = temp.prev
    def printele(self):
        temp = self.start
        ans = []
        while temp.ele !=None:
            ans.append(temp.ele)
            temp=temp.next
        print(*ans)

n = int(input())
l = DoubleList()
for _ in range (n):
    cmd = input().split(' ')
    if cmd[0]=='insert':
        l.insert(int(cmd[1]))
    if cmd[0]=='delete':
            l.delete(int(cmd[1]))
    if cmd[0]=='deleteFirst':
        l.deleteFirst()
    if cmd[0]=='deleteLast':
        l.deleteLast()
l.printele()

Submission status: Wrong Answer

Solution code:
def run():
    n = int(input())
    nodes = []
    for _ in range(n):
        order = [o.strip() for o in input().split()]
        if order[0] == 'insert':
            nodes.append(int(order[1]))
        elif order[0] == 'delete':
            if int(order[1]) in nodes:
                nodes.remove(int(order[1]))
        elif order[0] == 'deleteFirst':
            nodes.pop(0)
        elif order[0] == 'deleteLast':
            nodes.pop(0)
    print(' '.join([str(n) for n in nodes]))
    
if __name__ == '__main__':
    run()

Submission status: Wrong Answer

Solution code:
def run():
    n = int(input())
    nodes = []
    for _ in range(n):
        order = [o.strip() for o in input().split()]
        if order[0] == 'insert':
            nodes.append(int(order[1]))
        elif order[0] == 'delete':
            if int(order[1]) in nodes:
                nodes.remove(int(order[1]))
        elif order[0] == 'deleteFirst':
            nodes.pop()
        elif order[0] == 'deleteLast':
            nodes.pop(0)
    nodes.reverse()
    print(' '.join([str(n) for n in nodes]))
    
if __name__ == '__main__':
    run()

Submission status: Wrong Answer

Solution code:
n = int(raw_input())

li = []
for i in range(n):
    cmd = raw_input().split()
    if cmd[0] == 'insert':
        li.insert(0,cmd[1])
    elif cmd[0] == 'delete':
        try:
            li.remove(cmd[1])
        except:
            pass
    elif cmd[0] == 'deleteFirst':
        li.pop(0)
    elif cmd[0] == 'deleteLast':
        li.pop()
    print li
for e in li:
    print e,

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
x = [0 for i in range(n)]
pf = 0
pb = 0

li = []
for i in range(n):
    s = (raw_input().split())
    if s[0] == 'insert':
        pf += 1
        x[pf]=int(s[1])
    elif s[0] == 'delete':
        try:
            p = x[pf::-1].index(int(s[1]))
            x[pf-p] = 0
        except:
            pass
    elif s[0] == 'deleteFirst':
        pf -= 1
    elif s[0] == 'deleteLast':
        pb += 1
for e in x[pb:pf+1][::-1]:
    if e != 0:
        print e,

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
x = [0 for i in range(n)]
pf = 0
pb = 0

li = []
for i in range(n):
    s = (raw_input().split())
    if s[0] == 'insert':
        pf += 1
        x[pf]=int(s[1])
    elif s[0] == 'delete':
        try:
            p = x[pf::-1].index(int(s[1]))
            x[pf-p] = 0
            while x[pf]==0:
                pb -= 1
            while x[pb]==0:
                pb += 1
        except:
            pass
    elif s[0] == 'deleteFirst':
        x[pf]=0
        pf -= 1
    elif s[0] == 'deleteLast':
        x[pb] = 0
        pb += 1
    print x
for e in x[pb:pf+1][::-1]:
    if e != 0:
        print e,

Submission status: Wrong Answer

Solution code:
import sys

A=[[0,0,0]]
size = 0

def insert(A,x):
    global size

    fp=A[0][1]
    try:
        i=[e[0] for e in A].index(-1)
        A[i]=[x,fp,0]
        A[fp][2]=i
        A[0][1]=i
    except:
        A.append([x,fp,0])
        A[fp][2]=len(A)-1
        A[0][1]=len(A)-1     
    size += 1    

def delete(A,x):
    global size
    p =A[0][1]
    while A[p][0]!=x:
        p=A[p][1]
        if p==0: return
    fp=A[p][1]
    bp=A[p][2]
    A[fp][2]=bp
    A[bp][1]=fp
    A[p]=[-1,-1,-1]
    size -= 1
    return

def deletefirst(A):
    global size
    if size == 0: return
    p=A[0][1]
    fp=A[p][1]
    A[0][1]=fp
    A[fp][2]=0
    A[p]=[-1,-1,-1]
    size -= 1
    return 0

def deletelast(A):
    global size
    if size == 0: return
    p=A[0][2]
    bp=A[p][2]
    A[0][2]=bp
    A[bp][1]=0
    A[p]=[-1,-1,-1]
    size -= 1
    return 0

n = int(raw_input())
for i in range(n):
    s = (raw_input().split())
    if s[0][0] == 'i':#'insert':
        insert(A,int(s[1]))
    elif len(s[0]) == 6:#'delete':
        delete(A,int(s[1]))
    elif s[0][7] == 'F':#'deleteFirst':
        deletefirst(A)
    elif s[0][7] == 'L':#'deleteLast':
        deletelast(A)

e = A[0][1]
while e!=0:
    print A[e][0],
    e = A[e][1]