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

insert x: ??£?????????????????????????????? x ?????????????´?????¶?????¶???????
delete x: ?????? x ??????????????????????´??????£????????????????????????????????????????????????????´?????????¨???????????´????????????????????????
deleteFirst?????????????????????????´???????????????????
deleteLast: ????????????????°????????´???????????????????
"""

class Dlist:
    MAX = 1000000
    
    def __init__(self):
        """ ????????????????????? """
        self.si = 0
        self.ei = 0
        self.cnt = 0
        self.data = [0 for r in range(Dlist.MAX)]

    def insert(self,x):
        """ ??£?????????????????????????????? x ?????????????´?????¶?????¶???? """
        self.si -= 1
        if self.si < 0:
            self.si = Dlist.MAX - 1
        self.data[self.si] = x
        self.cnt += 1

    def delete(self,x):
        """ ?????? x ??????????????????????´??????£????????????????????????????????????????????????????´?????????¨???????????´????????????????????????"""
        if self.cnt > 0:
            self.hit = False
            for i in range(self.cnt):
                pi = self.si + i
                if pi >= Dlist.MAX:
                    pi -= Dlist.MAX
                if self.data[pi] == x:
                    hit = True
                    break
            if self.hit == True:
                for j in range(i, self.cnt):
                    pi = self.si + j
                    if pi >= Dlist.MAX:
                        pi -= Dlist.MAX
                    ni = pi + 1
                    if ni >= Dlist.MAX:
                        ni -= Dlist.MAX
                    self.data[pi] = self.data[ni]
                self.ei -= 1
                if self.ei < 0 :
                    self.ei = Dlist.MAX - 1
                self.cnt -= 1
            
    def deleteFirst(self):
        """ ?????????????????????????´???????????????? """
        if self.cnt > 0:
            self.data[self.si] = 0
            self.si += 1
            if self.si >= Dlist.MAX:
                self.si = 0
            self.cnt -= 1

    def deleteLast(self):
        """ ????????????????°????????´???????????????????"""
        if self.cnt > 0:
            self.ei -= 1
            if self.ei < 0 :
                self.ei = Dlist.MAX - 1
            self.data[self.ei] = 0
            self.cnt -= 1

    def getList(self):
        return self.data[self.si:self.ei]

# ?????????
num = int(input().strip())
dl = Dlist()

for i in range(num):
    cmd = list(input().strip().split())
    if cmd[0] == "insert":
        dl.insert(cmd[1])
    elif cmd[0] == "delete":
        dl.delete(cmd[1])
    elif cmd[0] == "deleteFirst":
        dl.deleteFirst()
    elif cmd[0] == "deleteLast":
        dl.deleteLast()

#    print("cmd={} si={} ei={} cnt={}".format(cmd[0], dl.si, dl.ei, dl.cnt))
#    print(dl.data)

print(" ".join(map(str,dl.getList())))

Submission status: Wrong Answer

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

for i in range(n):
	command = input().split()
	if len(command) == 2:
		command,x = command
	if command == 'insert':
		data.insert(0,x)
	elif command == 'delete':
		if x in data:
			data.remove(x)
	elif command == 'deleteFirst':
		data.pop(0)
	elif command == 'deleteLast':
		data.pop()

print(*data)

Submission status: Wrong Answer

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

for i in range(n):
	command = input().split()
	if len(command) == 2:
		command,x = command
	else:
		command = command[0]
	if command == 'insert':
		data.insert(0,x)
	elif command == 'delete':
		if x in data:
			data.remove(x)
	elif command == 'deleteFirst':
		print('First')
		data.pop(0)
	elif command == 'deleteLast':
		print('Last')
		data.pop()

print(*data)

Submission status: Wrong Answer

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

for i in range(n):
	command = input().split()
	if len(command) == 2:
		command,x = command
	else:
		command = command[0]
	print(command)
	if command == 'insert':
		data.insert(0,x)
	elif command == 'delete':
		if x in data:
			data.remove(x)
	elif command == 'deleteFirst':
		print('First')
		data.pop(0)
	elif command == 'deleteLast':
		print('Last')
		data.pop()

print(*data)

Submission status: Wrong Answer

Solution code:
n=int(input())

dl_list=[]

for i in range(n):
    cmd=input().split()
    if cmd[0]=="insert":
        dl_list.insert(0,cmd[1])
    elif cmd[0]=="delete":
        try:
            dl_list.remove(cmd[1])
        except:
            print("Error")
    elif cmd[0]=="deleteFirst":
        del dl_list[0]
    elif cmd[0]=="deleteLast":
        del dl_list[-1]

print(*dl_list)

Submission status: Wrong Answer

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

for i in range(n):
    cmd=input().split()
    if cmd[0]=="insert":
        dq.appendleft(cmd[1])
    elif cmd[0]=="deleteFirst":
        dq.popleft()
    elif cmd[0]=="deleteLast":
        dq.pop()
    elif cmd[0]=="delete":
        try:
            dq.remove(cmd[1])
        except:
            print("Error")
print(*dq)

Submission status: Wrong Answer

Solution code:

class DoublyLinkedList:
    def insert(self, L, key):
        L.insert(0, key)
    
    def delete(self, L, key):
        idx = L.index(key)
        L.pop(idx)
    
    def deleteFirst(self, L):
        L.pop(0)
    
    def deleteLast(self, L):
        L.pop()

N = int(input())
C = []
for i in range(N):
    C.append(input().split())

DLL = DoublyLinkedList()
L = []
for i in C:
    if i[0] == "insert":
        DLL.insert(L, i[1])
    elif i[0] == "delete":
        DLL.delete(L, i[1])
    elif i[0] == "deleteFirst":
        DLL.deleteFirst(L)
    elif i[0] == "deleteLast":
        DLL.deleteLast(L)
    else:
        raise ValueError("Wrong Command")

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

Submission status: Wrong Answer

Solution code:

class DoublyLinkedList:
    def insert(self, L, key):
        L.insert(0, key)
    
    def delete(self, L, key):
        idx = L.index(key)
        L.pop(idx)
    
    def deleteFirst(self, L):
        L.pop(0)
    
    def deleteLast(self, L):
        L.pop()

N = int(input())
C = []
for i in range(N):
    C.append(input().split())

DLL = DoublyLinkedList()
L = []
for i in C:
    if i[0] == "insert":
        DLL.insert(L, int(i[1]))
    elif i[0] == "delete":
        DLL.delete(L, int(i[1]))
    elif i[0] == "deleteFirst":
        DLL.deleteFirst(L)
    elif i[0] == "deleteLast":
        DLL.deleteLast(L)
    else:
        raise ValueError("Wrong Command")

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

Submission status: Wrong Answer

Solution code:
from collections import deque
import sys
n = int(input())
deq = deque()
sub_deq = {}
n, *cmds = sys.stdin.readlines()
for cmd in cmds:
    if cmd == 'deleteFirst\n':
        while deq:
            data = deq.pop()
            if data[1]:
                data[1] = 0
                break
    elif cmd == 'deleteLast\n':
        while deq:
            data = deq.popleft()
            if data[1]:
                data[1] = 0
                break
    else:
        cmd, val = cmd.split()
        if cmd == 'insert':
            data = [val, 1]
            deq.append(data)
            if val not in sub_deq:
                sub_deq[val] = [data]
            else:
                sub_deq[val].append(data)
        elif cmd == 'delete':
            if val in sub_deq:
                deq_v = sub_deq[val]
                while deq_v:
                    data = deq_v.pop()
                    if data[1]:
                        data[1] = 0
                        break
sys.stdout.write(" ".join(data[0] for data in reversed(deq) if data[1]))
sys.stdout.write('\n')

Submission status: Wrong Answer

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()
        
if len(l) > 1:
    for i in range(len(l)):
        print(i,end=" ")

print(l[len(l)-1])

Submission status: Wrong Answer

Solution code:
from collections import deque

n = int(input())
dq = deque()

for _ in range(n):
    command = input().split()
    if command[0] == 'delete':
        dq.remove(int(command[1]))
    elif command[0] == 'insert':
        dq.appendleft(int(command[1]))
    elif command == 'deleteFirst':
        dq.popleft()
    else:
        dq.pop()

print(*list(dq))

Submission status: Wrong Answer

Solution code:
from collections import deque

n = int(input())
dq = deque()

for _ in range(n):
    command = input().split()
    if command[0] == 'delete':
        if command[1] in dq:
            dq.remove(command[1])
    elif command[0] == 'insert':
        dq.appendleft(command[1])
    elif command == 'deleteFirst':
        dq.popleft()
    else:
        dq.pop()

print(''.join(dq))

Submission status: Wrong Answer

Solution code:
n=int(input())
commands=[input().split() for i in range(n)]
print(commands)
    
List=[]
def command(list_command):
    if 'insert' in list_command:
        List.insert(0,list_command[1])
    elif 'delete' in list_command:
        try:
            t=List.index(list_command[1])
            del List[t]
        except:
            pass
    elif 'deleteFirst' in list_command:
        del List[0]
    elif 'deleteLast' in list_command:
        del List[-1]

    return True
    
for i in commands:
    command(i)
print(*List)

Submission status: Wrong Answer

Solution code:
n=int(input())
commands=[input().split() for i in range(n)]
print(commands)
    
List=[]
def command(list_command):
    global List
    if 'insert' in list_command:
        List.insert(0,list_command[1])
    elif 'delete' in list_command:
        try:
            t=List.index(list_command[1])
            del List[t]
        except:
            pass
    elif 'deleteFirst' in list_command:
        del List[0]
    elif 'deleteLast' in list_command:
        del List[-1]
    return True
    
for i in commands:
    command(i)
print(*List)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
input_lines = sys.stdin.readlines()

doublyLinkedList = deque()


for x in input_lines[1:]:
    oneLine = x.split()
    if 'insert' in oneLine[0]:
        doublyLinkedList.append((int)(oneLine[1]))
    elif 'delete' == oneLine[0]:
        remove_value = (int)(oneLine[1])
        if remove_value in doublyLinkedList:
            doublyLinkedList.remove((int)(oneLine[1]))
    elif 'deleteFirst'in oneLine[0]:
        doublyLinkedList.popleft()
    elif 'deleteLast' in oneLine[0]:
        doublyLinkedList.pop()

print(*doublyLinkedList)

Submission status: Wrong Answer

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

print(*l)

Submission status: Wrong Answer

Solution code:
n = int(input())
list = []
for _ in range(n):
    command = input().split()
    if command[0] == 'insert':
        num = int(command[1])
        list.insert(0, num)
    elif command[0] == 'delete':
        num = int(command[1])
        list.remove(num)
    elif command[0] == 'deleteFirst':
        list.pop()
    elif command[0] == 'deleteLast':
        list.pop(-1)

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

Submission status: Wrong Answer

Solution code:
n = int(input())
list = []
for _ in range(n):
    command = input().split()
    if command[0] == 'insert':
        num = int(command[1])
        list.insert(0, num)
    elif command[0] == 'delete':
        num = int(command[1])
        list.remove(num)
    elif command[0] == 'deleteFirst':
        list.pop(0)
    elif command[0] == 'deleteLast':
        list.pop()
    print(list)

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

Submission status: Wrong Answer

Solution code:
from collections import deque
import sys

dq = deque()
num = int(sys.stdin.readline())
line = sys.stdin.readlines()

for i in range(num):

    order = line[i].split()

    if order[0] == 'insert':
        dq.appendleft(order[1])
    elif order[0] == 'deleteFirst':
        dq.popleft()
    elif order[0] == 'deleteLast':
        dq.pop()
    else:
        if order[1] in dq:
            dq.remove(order[1])

Submission status: Wrong Answer

Solution code:
from collections import deque
query = int(input())
l = deque()
for _ in range(query):
    command = input()
    if command == "deleteFirst":
        try:
            l.popleft()
        except:
            pass
    elif command == "deleteLast":
        try:
            l.pop()
        except:
            pass
    else:
        command, value = command.split(" ")
        if command == "insert":
            l.append(int(value))
        elif command == "delete":
            try:
                l.remove(int(value))
            except:
                pass
print(*l)

Submission status: Wrong Answer

Solution code:
k = int(input())
l=[]
x=[]
for i in range(k):
    buff = input()
    if "deleteFirst" in buff:
        x.pop()
    elif "deleteLast" in buff:
        x.pop(len(x)-1)
    elif "insert" in buff:
        x.insert(0, list(buff).pop())
    elif "delete" in buff:
        x.remove(list(buff).pop())

print(" ".join(x))

Submission status: Wrong Answer

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
        isf = 0
        while cur != self.nil:
            if isf > 0:
                print(" ")
            print(cur.key)
            cur = cur.next
            isf += 1

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

Solution code:
from collections import deque
dq = deque()
for _ in range(int(input())):
    ss = input()
    if ss == "deleteFirst":
        del dq[0]
    elif ss == "deleteLast":
        del dq[-1]
    else:
        c, s = ss.split()
        s = int(s)
        if c == "insert":
            dq.append(s)
        elif c == "delete":
            if s in dq:
                dq.remove(s)
dq.reverse()
print(*dq)

Submission status: Wrong Answer

Solution code:
from collections import deque
dq = deque()
for _ in range(int(input())):
    ss = input()
    if ss == "deleteFirst":
        del dq[-1]
    elif ss == "deleteLast":
        del dq[0]
    else:
        c, s = ss.split()
        s = int(s)
        if c == "insert":
            dq.append(s)
        elif c == "delete":
            if s in dq:
                dq.remove(s)
dq.reverse()
print(*dq)

Submission status: Wrong Answer

Solution code:
s=[]
for _ in range(int(input())):
 e=input()
 if e[0]=='i':s=[e.split()[1]]+s
 else:
  n=len(s)
  if n==6:s.remove(e.split()[1])
  elif n%2:s=s[1:]
  else:s.pop()
 print(*s)

Submission status: Wrong Answer

Solution code:
s=[]
for _ in range(int(input())):
 e=input()
 if'i'==e[0]:s=[e.split()[1]]+s
 else:
  if' '==e[6]:
   m=e.split()[1]
   if m in s:s.remove(m)
  elif len(e)%2:s=s[1:]
  else:s.pop()
 print(*s)

Submission status: Wrong Answer

Solution code:
import collections,sys
d=collections.deque()
input()
for e in sys.stdin.readlines():
 if'i'==e[0]:d.appendleft(e.split()[1])
 else:
  if' '==e[6]:
   m=e.split()[1]
   if m in d:d.remove(m)
  elif len(e)%2:d.popleft()
  else:d.pop()
print(*d)

Submission status: Wrong Answer

Solution code:
import collections,sys
d=collections.deque()
input()
for e in sys.stdin.readlines():
 if'i'==e[0]:d.appendleft(e.split()[1])
 else:
  if' '==e[6]:
   m=e.split()[1]
   if m in d:d.remove(m)
  elif len(e)%2:d.pop()
  else:d.popleft()
 print(*d)

Submission status: Wrong Answer

Solution code:
import collections

#getting input
commands = []
while True:
    try:
        line = str(input())
    except EOFError:
        break
    commands.append(line)
commands.pop(0)

'''while True:
    line = input()
    if line == '': break
    commands.append(line)
commands.pop(0)'''


#executing commands
output = collections.deque()

Submission status: Wrong Answer

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

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))
        print(d)

Submission status: Wrong Answer

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

import sys

_list = list()

n = int(sys.stdin.readline())
for i in range(n):
    cmd = sys.stdin.readline().split()
    if cmd[0] == 'insert':
        # _list.insert(0, cmd[1])
        _list.append(cmd[1])
    elif cmd[0] == 'delete':
        try:
            tmp = _list[::-1]
            tmp.remove(cmd[1])
            _list = tmp[::-1]
        except ValueError:
            #print('skip deleting', cmd[1])
            pass
    elif cmd[0] == 'deleteFirst':
        _list.pop()
    elif cmd[0] == 'deleteLast':
        _list.pop(0)
    else:
        raise ValueError
    print(_list)

print(' '.join(_list[::-1]))

Submission status: Wrong Answer

Solution code:
from collections import deque

n = int(input())
q = deque([])
i = 0
while i < n:
    s = list(map(str, input().split(' ')))
    if s[0] == 'insert':
        q.append(int(s[1]))
    elif s[0] == 'delete':
        try:
            q.remove(int(s[1]))
        except ValueError:
            pass
    elif s[0] == 'deleteFirst':
        q.pop()
    elif s[0] == 'deleteLast':
        q.popleft()
    i += 1
ans = ''
while len(q) != 0:
    ans += str(q.pop()) + ' '
print(ans[:-1])

Submission status: Wrong Answer

Solution code:
class DoubleEndedList:
# クラス内クラスを作る(CellクラスはDoubleEndedListクラスからしか参照しないため)
    class Cell:
        def __init__(self, data, prv = None, nxt = None):
            self.data = data
            self.prv = prv
            self.nxt = nxt

    def __init__(self):
        head = DoubleEndedList.Cell(None)
        head.prv = head
        head.nxt = head
        self.head = head

    def insertFirst(self, data):
        x = DoubleEndedList.Cell(data, self.head, self.head.nxt)
        self.head.nxt = x
        x.nxt.prv = x

    def delete(self, index):
        x = self.head
        while x.data != index:
            x = x.nxt
        x.prv.nxt = x.nxt
        x.nxt.prv = x.prv

deque = DoubleEndedList()
for i in range(int(input())):
    cmd = input().split()
    if cmd[0] == "insert":
        deque.insertFirst(int(cmd[1]))
    elif cmd[0] == "delete":
        deque.delete(int(cmd[1]))
    elif cmd[0] == "deleteFirst":
        deque.delete(deque.head.nxt.data)
    elif cmd[0] == "deleteLast":
        x = deque.head
        while x.nxt is not deque.head:
            x = x.nxt
        deque.delete(x.data)
    else:
        print("Wrong Command")
n = deque.head.nxt
while n is not deque.head:
    print(n.data, end = "")
    if n.nxt is not deque.head:
        print(" ", end = "")
    else:
        print("")
    n = n.nxt

Submission status: Wrong Answer

Solution code:

import sys
#import numpy as np
import copy

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

for i in range(N):
    # insert, delete, deleteFirst, deleteLast
    line = input().rstrip().split(' ')
    if line[0]=='insert':
        list.append((int)(line[1]))
    elif line[0]=='delete':
        for j in range(len(list)):
            if list[j]==(int)(line[1]):
                list.pop(j)
                break
    elif line[0]=='deleteFirst':
        list.pop(0)
    elif line[0]=='deleteLast':
        list.pop(len(list)-1)

for i in range(len(list)):
    print( (str)(list[i]), end="")
    if i != len(list)-1:
        print(" ",end="")
print()

Submission status: Wrong Answer

Solution code:
from collections import deque

n = int(input())
q = deque()
for i in range(n):
    com = input().split()
    if com[0] == 'insert':
        q.append(int(com[1]))
    elif com[0] == 'delete':
        try:
            q.remove(int(com[1]))
        except:
            pass
    elif com[0] == 'deleteFirst':
        q.popleft()
    else:
        q.pop()
ans = []
while len(q):
    ans.append(q.pop())
print(*ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
d = deque()
for _ in range(int(input())):
  a = input()
  if "i" == a[0]: d.appendleft(int(a[7]))
  elif "F" == a[6]: d.popleft()
  elif "L" == a[6]: d.pop()
  else:
    try: d.remove(int(a[7]))
    except: pass
print(*d)

Submission status: Wrong Answer

Solution code:
n = int(input())
commands = []
for a in range(n):
    raw = input().split()
    try:
        commands.append([raw[0], int(raw[1])])
    except:
        commands.append([raw[0], 'none'])

result = []
for a in commands:
    command, x = a[0], a[1]
    if command == 'insert':
        result.append(x)
    elif command == 'delete':
        result.remove(x)
    elif command == 'deleteFirst':
        del result[-1]
    else:
        del result[0]

result.reverse()
print(*result)

Submission status: Wrong Answer

Solution code:

Submission status: Wrong Answer

Solution code:
import collections,sys
def s():
 d=collections.deque()
 input()
 for e in sys.stdin:
  if'i'==e[0]:d.appendleft(e[7:-1])
  else:
   if' '==e[6]:
    m=e[7:-1]
    if m in d:d.remove(m)
   elif'i'==e[7]:d.pop()
   else:d.popleft()
 print(*d)
if'__main__'==__name__:s()

Submission status: Wrong Answer

Solution code:
from collections import deque
n = int(input())
a = deque()
for i in range(n):
    c = input()
    if c == "deleteFirst":
        a.pop()
    elif c == "deleteLast":
        a.popleft()
    else:
        c, v = c.split()
        if c == "insert":
            a.extendleft(v)
        else:
            try:
                a.remove(v)
            except:
                pass
print(" ".join(a))

Submission status: Wrong Answer

Solution code:
from collections import deque
n = int(input())
a = deque()
for i in range(n):
    c = input()
    if c == "deleteFirst":
        a.popleft()
    elif c == "deleteLast":
        a.pop()
    else:
        c, v = c.split()
        if c == "insert":
            a.extendleft(v)
        else:
            try:
                a.remove(v)
            except:
                pass
print(" ".join(a))

Submission status: Wrong Answer

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

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

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

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

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

Submission status: Wrong Answer

Solution code:
#! python3
# doubly_linked_list.py

from collections import deque

keys = deque([])

n = int(input())

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

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

Submission status: Wrong Answer

Solution code:
n = int(input("n:"))
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])
    if c[i][0]=='delete':
        s.remove(c[i][1])
    if c[i][0]=='deleteFirst':
        del s[len(s)-1]
    if c[i][0]=='deleteLast':
        del s[0]


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

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])
    if c[i][0]=='delete':
        s.remove(c[i][1])
    if c[i][0]=='deleteFirst':
        del s[len(s)-1]
    if c[i][0]=='deleteLast':
        del s[0]


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

Submission status: Wrong Answer

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

for i in range(n):
    A=input().split()
    #for j in range(2):
        #x=[]
    if A[0]=="insert":
        x.append(A[1])
      
    elif A[0]=="delete":
        x.remove(A[1])
    
    elif A[0]=="deletefarst":
        x.pop(0)
   
    else:
        x.pop()

print(x)

Submission status: Wrong Answer

Solution code:
import sys


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


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

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

    def search(self, key):
        cur = self.nil.next

        while cur != self.nil and cur.key != key:
            cur = cur.next

        return cur

    def delete_node(self, node):
        if node == self.nil:
            return

        node.prev.next = node.next
        node.next.prev = node.prev

    def delete_first(self):
        self.delete_node(self.nil.next)

    def delete_last(self):
        self.delete_node(self.nil.prev)

    def delete_key(self, key):
        node = self.search(key)
        self.delete_node(node)


def main():
    n = int(input())
    ll = LinkedList()

    for i in range(n):
        order = sys.stdin.readline().split()

        if order[0] == "insert":
            ll.insert(int(order[1]))
        elif order[0] == "delete":
            ll.delete_key(int(order[1]))
        elif order[0] == "deleteFirst":
            ll.delete_first()
        else:
            ll.delete_last()

    cur = ll.nil
    while cur.next != ll.nil:
        if cur != ll.nil:
            print(" ", end="")
        cur = cur.next
        print(cur.key, end="")

    print()

Submission status: Wrong Answer

Solution code:
n = int(input("command number:"))
L = []

for i in range(n):
    com = input()
    if com == "deleteFirst":
        del L[0]
    elif com == "deleteLast":
        del L[len(L)-1]
    else:
        c = com.split()
        if c[0] == "insert":
            L.insert(0, int(c[1]))
        elif c[0] == "delete":
            for i in range(len(L)):
                if L[i] == int(c[1]):
                    del L[i]
                    break
    print(L)
        
for i in range(len(L)):
    if i == len(L)-1:
        print(L[i])
    else:
        print(L[i], end=' ')

Submission status: Wrong Answer

Solution code:
n = int(input("command number:"))
L = []

for i in range(n):
    com = input()
    if com == "deleteFirst":
        del L[0]
    elif com == "deleteLast":
        del L[len(L)-1]
    else:
        c = com.split()
        if c[0] == "insert":
            L.insert(0, int(c[1]))
        elif c[0] == "delete":
            for i in range(len(L)):
                if L[i] == int(c[1]):
                    del L[i]
                    break
    #print(L)
        
for i in range(len(L)):
    if i == len(L)-1:
        print(L[i])
    else:
        print(L[i], end=' ')

Submission status: Wrong Answer

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

for i in range(n):
    com = input()
    if com == "deleteFirst":
        del L[0]
    elif com == "deleteLast":
        del L[len(L)-1]
    else:
        c = com.split()
        if c[0] == "insert":
            L.insert(0, int(c[1]))
        elif c[0] == "delete":
            for i in range(len(L)):
                if L[i] == int(c[1]):
                    del L[i]
                    break
    print(L)
        
for i in range(len(L)):
    if i == len(L)-1:
        print(L[i])
    else:
        print(L[i], end=' ')