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:
#! -*-coding:utf-8-*-

import time
def main():
    n = input()
    dll = []
    for _ in xrange(n):
        tmp = raw_input().split()
        if len(tmp) == 1:
            # print dll
            # print tmp[0]
            if tmp[0] == "deleteFirst":
                # print "deleteFirst..."
                dll.pop(0)
            elif tmp[0] == "deleteLast":
                # print "deleteLast..."
                dll.pop(-1)
            else:
                print "This command is invalid."
                break
        elif len(tmp)==2:
            command = tmp[0]
            o = tmp[1]
            # print dll
            # print command, operand
            if command == "insert":
                # print "insert..."
                dll.insert(0,o)
            elif command == "delete":
                # print "delete..."
                if o in set(dll):
                    dll.remove(o)
            else:
                print "This command is invalid."
                break
    print " ".join(map(str,dll))

if __name__ == '__main__':
    f = time.clock()
    main()
    t = time.clock()
    print t-f

Submission status: Wrong Answer

Solution code:
n = input()
lis = []
for i in xrange(n):
    com = raw_input()
    try:
        com, x = com.split()
        if   com == 'insert':
            lis.append(int(x))
        elif com == 'delete':
            lis.remove(int(x))
    except:
        if com == 'deleteFirst':
            lis.pop(0)
        if com == 'deleteLast':
            lis.pop()

print " ".join( map(str, reversed(lis)) )

Submission status: Wrong Answer

Solution code:
n = input()
lis = []
for i in xrange(n):
    com = raw_input()
    try:
        com, x = com.split()
        if   com == 'insert':
            lis.append(x)
        elif com == 'delete':
            l = len(lis) - 1
            while (lis[l] != x) and l >= 0:
                l -= 1
            lis.pop(l)
    except:
        if com == 'deleteFirst':
            lis.pop()
        if com == 'deleteLast':
            lis.pop(0)

print " ".join( map(str, reversed(lis)) )

Submission status: Wrong Answer

Solution code:
from collections import deque
n = int(input())
dl = deque()
for _ in range(n):
    cmd = input()
    print('[DEBUG] cmd:',cmd)
    if ' ' in cmd:
        op,v = cmd.split()
    else:
        op = cmd
    if   op == 'insert'     : dl.appendleft(v) 
    elif op == 'delete'     :
        try: dl.remove(v)
        except ValueError: pass
    elif op == 'deleteFirst': dl.popleft() 
    elif op == 'deleteLast' : dl.pop() 
print(*dl)

Submission status: Wrong Answer

Solution code:
# coding:utf-8
# Doubly Linked List

class DLL:

    def __init__(self):
        self.array = []

    def insert(self, x):
        self.array = [x] + self.array
    
    def delete(self, x):
        del self.array[self.array.index(x)]

    def deleteFirst(self):
        del self.array[0]

    def deleteLast(self):
        del self.array[len(self.array)-1]


def main():

    dll = DLL()
    n = int(input())

    for _ in range(n):
        operation = input().split()
        command = operation[0]
        if command in ["insert", "delete"]:
            key = operation[1]
            eval("dll." + command + '(' + key + ')')

        else:
            eval("dll." + command + "()")

    print(dll.array)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import deque

n = int(input())
q = deque()

for i in range(n):
    command = input()
    if command[0] == 'i':
        q.appendleft(command[7])
    elif command[6] == ' ':
        try:
            q.remove(command[7])
        except Exception as e:
            pass
    elif command[6] == 'F':
        q.popleft()
    else:
        q.pop()

print(' '.join(q))

Submission status: Wrong Answer

Solution code:
# coding: utf-8

import sys
from collections import deque

n = int(input())

task_name = (
    "insert",
    "delete",
    "deleteFirst",
    "deleteLast"
)

tasks = deque(map(lambda x: x if x in task_name else x.split(), sys.stdin.readlines()))

a = deque()

for task in tasks:
    #deleteFirst,deleteLast
    if len(task) == 1:
        if task == "deleteFirst":
            a.popleft()
        else:
            a.pop()
    #insert,delete
    else:
        if task[0] == "insert":
            a.appendleft(task[1])
        elif task[1] in a:
            a.remove(task[1])

print(*a)

Submission status: Wrong Answer

Solution code:
# coding:utf-8
# Doubly Linked List

class DLL:

    def __init__(self):
        self.array = []

    def insert(self, x):
        self.array = [x] + self.array
    
    def delete(self, x):
        del self.array[self.array.index(x)]

    def deleteFirst(self):
        del self.array[0]

    def deleteLast(self):
        del self.array[len(self.array)-1]


def main():

    dll = DLL()
    n = int(input())

    for _ in range(n):
        operation = input().split()
        command = operation[0]
        if command in ["insert", "delete"]:
            key = operation[1]
            eval("dll." + command + '(' + key + ')')

        else:
            eval("dll." + command + "()")

    print(str(dll.array)[1:len(str(dll.array))-1])

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input().strip())

l = []
for _ in range(n):
    cmd = input()
    if cmd == "deleteFirst":
        l = l[1:]
    elif cmd == "deleteLast":
        l.pop()
    elif cmd.startswith("insert "):
        _, e = cmd.split(" ")
        l = [e] + l
    elif cmd.startswith("delete "):
        try:
            l.remove(e)
        except ValueError:
            pass

print(" ".join(l))

Submission status: Wrong Answer

Solution code:
import sys

LIST_SIZE = 10 ** 6

class E(object):
    def __init__(self, p = None, v = None, n = None):
        self.p = p
        self.v = v
        self.n = n

    def rem(self):
        if self.p is not None:
            self.p.n = self.n
        if self.n is not None:
            self.n.p = self.p
        return self.p, self.n

    def ins(self, ne):
        self.p = ne
        ne.n = self
        return ne

    def prt(self):
        sys.stdout.write(self.v)
        if self.n is not None:
            sys.stdout.write(" ")
            self.n.prt()

fe = le = None

n = int(input().strip())

for _ in range(n):
    cmd = input()
    if cmd == "deleteFirst":
        if fe is not None:
            _, fe = fe.rem()
    elif cmd == "deleteLast":
        if le is not None:
            le, _ = le.rem()
    elif cmd.startswith("insert "):
        _, v = cmd.split(" ")
        e = E(None, v, None)
        if fe is not None:
            fe.ins(e)
        fe = e
    elif cmd.startswith("delete "):
        _, v = cmd.split(" ")
        e = fe
        while e is not None:
            if e.v == v:
                e.rem()
                break
            e = e.n

if fe is not None:
    fe.prt()
print("")

Submission status: Wrong Answer

Solution code:
import sys

LIST_SIZE = 10 ** 6

class E(object):
    def __init__(self, p = None, v = None, n = None):
        self.p = p
        self.v = v
        self.n = n

    def rem(self):
        if self.p is not None:
            self.p.n = self.n
        if self.n is not None:
            self.n.p = self.p
        return self.p, self.n

    def ins(self, ne):
        self.p = ne
        ne.n = self
        return ne

    def prt(self):
        sys.stdout.write(self.v)
        if self.n is not None:
            sys.stdout.write(" ")
            self.n.prt()

fe = le = None

n = int(input().strip())

for _ in range(n):
    cmd = input()
    if cmd == "deleteFirst":
        if fe is not None:
            _, fe = fe.rem()
    elif cmd == "deleteLast":
        if le is not None:
            le, _ = le.rem()
    elif cmd.startswith("insert "):
        _, v = cmd.split(" ")
        e = E(None, v, None)
        if fe is not None:
            fe.ins(e)
        fe = e
        if le is None:
            le = e
    elif cmd.startswith("delete "):
        _, v = cmd.split(" ")
        e = fe
        while e is not None:
            if e.v == v:
                pe, ne = e.rem()
                if pe is None and ne is None:
                    fe = le = None
                elif pe is None:
                    fe = ne
                elif ne is None:
                    le = pe
                break
            e = e.n

    if fe is not None:
        fe.prt()
    print("")

Submission status: Wrong Answer

Solution code:
import sys

class E(object):
    def __init__(self, p = None, v = None, n = None):
        self.p = p
        self.v = v
        self.n = n

    def rem(self):
        if self.p is not None:
            self.p.n = self.n
        if self.n is not None:
            self.n.p = self.p
        return self.p, self.n

    def ins(self, ne):
        self.p = ne
        ne.n = self
        return ne

    def prt(self):
        sys.stdout.write(self.v)
        if self.n is not None:
            sys.stdout.write(" ")
            self.n.prt()

fe = le = None

n = int(input().strip())

for _ in range(n):
    cmd = input()
    if cmd == "deleteFirst":
        if fe is not None:
            _, fe = fe.rem()
    elif cmd == "deleteLast":
        if le is not None:
            le, _ = le.rem()
    elif cmd.startswith("insert "):
        _, v = cmd.split(" ")
        e = E(None, v, None)
        if fe is not None:
            fe.ins(e)
        fe = e
        if le is None:
            le = e
    elif cmd.startswith("delete "):
        _, v = cmd.split(" ")
        e = fe
        while e is not None:
            if e.v == v:
                pe, ne = e.rem()
                if pe is None and ne is None:
                    fe = le = None
                elif pe is None:
                    fe = ne
                elif ne is None:
                    le = pe
                break
            e = e.n

if fe is not None:
    fe.prt()
print("")

Submission status: Wrong Answer

Solution code:
import sys

class E(object):
    def __init__(self, p = None, v = None, n = None):
        self.p = p
        self.v = v
        self.n = n

    def rem(self):
        if self.p is not None:
            self.p.n = self.n
        if self.n is not None:
            self.n.p = self.p

    def ins(self, ne):
        self.p = ne
        ne.n = self

    def prt(self):
        sys.stdout.write(self.v)
        if self.n is not None:
            sys.stdout.write(" ")
            self.n.prt()

fe = le = None

n = int(input().strip())

for _ in range(n):
    cmd = input()
    if cmd == "deleteFirst":
        if fe is not None:
            fe.rem()
            fe = fe.n
    elif cmd == "deleteLast":
        if le is not None:
            le.rem()
            le = le.p
    elif cmd.startswith("insert "):
        _, v = cmd.split(" ")
        e = E(None, v, None)
        if fe is not None:
            fe.ins(e)
        fe = e
        if le is None:
            le = e
    elif cmd.startswith("delete "):
        _, v = cmd.split(" ")
        e = fe
        while e is not None:
            if e.v == v:
                e.rem()
                if fe == e:
                    fe = e.n
                if le == e:
                    le = e.p
                break
            e = e.n

if fe is not None:
    fe.prt()
print("")

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
n = int(sys.stdin.readline())

ans = deque()
for i in range(n):
    c = sys.stdin.readline()[:-1]
    if c[0] == 'i':
        ans.appendleft(c[7:])
    elif c[6] == ' ':
        try:
            ans.remove(c[7:])
        except:
            pass
    elif c[6] == 'F':
        ans.popleft
    else:
        ans.pop()

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#coding:UTF-8
def DLL(n,C):
    ans=[]
    for i in range(n):
        if C[i]=="deleteFirst":
            ans.pop(len(ans)-1)
        elif C[i]=="deleteLast":
            ans.pop(0)
        else:
            command=C[i].split(" ")[0]
            num=C[i].split(" ")[1]
            if command=="delete":
                ans.remove(num)
            else:
                ans.append(num)
    ans.reverse()
    print(" ".join(ans))
        
  
if __name__=="__main__":
    n=int(input())
    Command=[]
    for i in range(n):
        Command.append(input())
    DLL(n,Command)

Submission status: Wrong Answer

Solution code:
#coding:UTF-8
def DLL(n,C):
    ans=[]
    for i in range(n):
        if C[i]=="deleteFirst":
            ans.pop(len(ans)-1)
        elif C[i]=="deleteLast":
            ans.pop(0)
        else:
            command=C[i].split(" ")[0]
            num=C[i].split(" ")[1]
            if command=="delete":
                for i in reversed(range(len(ans))):
                    if ans[i]==num:
                        ans.remove(num)
                        break
            else:
                ans.append(num)
    ans.reverse()
    print(" ".join(ans))
        
  
if __name__=="__main__":
    n=int(input())
    Command=[]
    for i in range(n):
        Command.append(input())
    DLL(n,Command)

Submission status: Wrong Answer

Solution code:
# encoding: utf-8

import sys
from collections import deque


class Solution:
    @staticmethod
    def doubly_linked_list():
        # write your code here
        array_length = int(input())
        _input = sys.stdin.readlines()
        task_list = list(map(lambda x: dict(action=x.split()[0], value=x.split()[-1]), _input))
        task_deque = deque()
        for task in task_list:
            action = task.get('action')
            value = task.get('value')
            if action == 'insert':
                task_deque.appendleft(value)
            elif action == 'deleteFirst':
                task_deque.popleft()
            elif action == 'deleteLast':
                task_deque.pop()
            elif action == 'delete' and value not in task_deque:
                task_deque.remove(value)

        print(" ".join(map(str, task_deque)))
        assert len(task_deque) <= array_length


if __name__ == '__main__':
    solution = Solution()
    solution.doubly_linked_list()

Submission status: Wrong Answer

Solution code:
# encoding: utf-8

import sys
from collections import deque


class Solution:
    @staticmethod
    def doubly_linked_list():
        # write your code here
        array_length = int(input())
        _input = sys.stdin.readlines()
        task_deque = deque()

        for i in range(array_length):
            action = _input[:-1]
            value = _input[-1]
            if action == 'insert':
                task_deque.appendleft(value)
            elif action == 'deleteFirst':
                task_deque.popleft()
            elif action == 'deleteLast':
                task_deque.pop()
            elif action == 'delete':
                try:
                    task_deque.remove(value)
                except Exception as e:
                    pass
        print(" ".join(task_deque))


if __name__ == '__main__':
    solution = Solution()
    solution.doubly_linked_list()

Submission status: Wrong Answer

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("\b")

Submission status: Wrong Answer

Solution code:
def delete(l, num):
    for i, x in enumerate(l):
        if x == num:
            return l[0:i] + l[i+1:]
    return l


n = int(input())
l = []
for i in range(n):
    com = input().split()
    if com[0] == 'insert':
        l = [int(com[1])] + l
    elif com[0] == 'delete':
        l = delete(l, int(com[1]))
    elif com[0] == 'deleteFirst':
        l = l[1:]
    elif com[0] == 'deleteLast':
        l = l[:-1]
    print(*l)

Submission status: Wrong Answer

Solution code:
import collections
q = collections.deque(maxlen=1000000)

n = int(input())
for i in range(n):
    com = input().split()
    if com[0]=='insert':
        q.appendleft(int(com[1]))
    elif com[0]=='delete':
        try:
            q.remove(int(com[0]))
        except ValueError:
            pass
    elif com[0]=='deleteFirst':
        q.popleft()
    elif com[0]=='deleteLast':
        q.pop()
print(*q)

Submission status: Wrong Answer

Solution code:
from collections import deque

def process_command(dll, commands):
    for cmd in commands:
        if cmd.startswith('insert') or cmd.startswith('delete '):
            t = cmd.split(' ')
            cmd = t[0]
            num_str = t[1]
        if cmd == 'insert':
            dll.appendleft(int(num_str))
        elif cmd == 'delete':
            temp = []
            result = dll.popleft()
            while result != int(num_str):
                temp.append(result)
                result = dll.popleft()
            dll.extendleft(temp)
        elif cmd == 'deleteFirst':
            dll.popleft()
        elif cmd == 'deleteLast':
            dll.pop()


if __name__ == '__main__':
    # ??????????????\???
    commands = []
    num = int(input())
    for i in range(num):
        commands.append(input())
    #commands.append(('insert', '5'))
    #commands.append(('insert', '2'))
    #commands.append(('insert', '3'))
    #commands.append(('insert', '1'))
    #commands.append(('delete', '3'))
    #commands.append(('insert', '6'))
    #commands.append(('delete', '5'))

    # ??????
    dll = deque()
    process_command(dll, commands)

    # ???????????????
    dll.reverse()
    print('{0}'.format(' '.join(map(str, dll))))

Submission status: Wrong Answer

Solution code:
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_C&lang=jp
#???????????£????????????
#??¬?????????????????¬????????§????????¨???????????????????????????dummy????????????????????¨??§???????????????????????????????????§??????
def dll_processor(operations):
    
    front = None
    
    for o in operations:
        opcode = o[0]
        if opcode == "insert":
            front = insert(front, { "next":None, "prev":None, "data":o[1] })
        elif opcode == "delete":
            front = delete(front, o[1])
        elif opcode == "deleteFirst":
            front = delete_first(front)
        elif opcode == "deleteLast":
            front = delete_last(front)
        #print(front)
        #print(get_list(front))
        
    return get_list(front)

def get_list(front):
    if not front:
        return []
    
    l = []
    target = front
    while True:
        l.append(target["data"])
        if not target["next"]:
            break
        target = target["next"]
    return l

def insert(front, target):

    if front:
        front["prev"] = target
        target["next"] = front

    return target
    
def delete(front, target):

    delete_node = front
    while not delete_node["data"] == target:
        delete_node = delete_node["next"]
        if delete_node == None:
            return front

    if delete_node["prev"] == None:
        delete_node["next"]["prev"] = None
        return delete_node["next"]
    elif delete_node["next"] == None:
        delete_node["prev"]["next"] = None
        return front
    else:
        delete_node["next"]["prev"] = delete_node["prev"]
        delete_node["prev"]["next"] = delete_node["next"]
        return front
    
def delete_last(front):
    last = front
    while last["next"]:
        last = last["next"]

    if last == front:
        return None
    else:
        last["prev"]["next"] = None
        return None
    
def delete_first(front):
    front["next"]["prev"] = None
    return front["next"]

def main():
    n_list = int(input())
    target_list = [input().split() for i in range(n_list)]
    print(*dll_processor(target_list))
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_C&lang=jp
#???????????£????????????
#??¬?????????????????¬????????§????????¨???????????????????????????dummy????????????????????¨??§???????????????????????????????????§??????
import gc
def dll_processor(operations):
    
    front = None
    end = None
    
    for o in operations:
        if o[0] == "insert":
            front, end = insert(front, end,{ "next":None, "prev":None, "data":o[1] })
        elif o[0] == "delete":
            front, end = delete(front, end, o[1])
        elif o[0] == "deleteFirst":
            front = delete_first(front)
        elif o[0] == "deleteLast":
            end = delete_last(end)
        gc.collect()
        #print(get_list(front))
        
    return get_list(front)

def get_list(front):
    if not front:
        return []
    
    l = []
    target = front
    while True:
        l.append(target["data"])
        if not target["next"]:
            break
        target = target["next"]
    return l

def insert(front, end, target):

    if front:
        front["prev"] = target
        target["next"] = front
        return target, end
    else:
        return target, target
    
def delete(front, end,target):

    delete_node = front
    while not delete_node["data"] == target:
        delete_node = delete_node["next"]
        if delete_node == None:
            return front

    if delete_node["prev"] == None:
        delete_node["next"]["prev"] = None
        return delete_node["next"], end
    elif delete_node["next"] == None:
        delete_node["prev"]["next"] = None
        return front, delete_node["prev"]
    else:
        delete_node["next"]["prev"] = delete_node["prev"]
        delete_node["prev"]["next"] = delete_node["next"]
        return front, end
    
def delete_last(end):
    
    if not end["prev"]:
        return None
    else:
        end["prev"]["next"] = None
        return end
    
def delete_first(front):
    
    if not front["next"]:
        return None
    else:
        front["next"]["prev"] = None
        return front["next"]

def main():
    n_list = int(input())
    target_list = [input().split() for i in range(n_list)]
    print(*dll_processor(target_list))
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_C&lang=jp
#???????????£????????????
#??¬?????????????????¬????????§????????¨???????????????????????????dummy????????????????????¨??§???????????????????????????????????§??????
import gc
def dll_processor(operations):
    
    front = None
    end = None
    
    for o in operations:
        if o[0] == "insert":
            front, end = insert(front, end,{ "next":None, "prev":None, "data":o[1] })
        elif o[0] == "delete":
            front, end = delete(front, end, o[1])
        elif o[0] == "deleteFirst":
            front = delete_first(front)
        elif o[0] == "deleteLast":
            end = delete_last(end)
        gc.collect()
        #print(get_list(front))
        
    return get_list(front)

def get_list(front):
    if not front:
        return []
    
    l = []
    target = front
    while True:
        l.append(target["data"])
        if not target["next"]:
            break
        target = target["next"]
    return l

def insert(front, end, target):

    if front:
        front["prev"] = target
        target["next"] = front
        return target, end
    else:
        return target, target
    
def delete(front, end,target):

    delete_node = front
    while not delete_node["data"] == target:
        delete_node = delete_node["next"]
        if delete_node == None:
            return front, end

    if delete_node["prev"] == None:
        delete_node["next"]["prev"] = None
        return delete_node["next"], end
    elif delete_node["next"] == None:
        delete_node["prev"]["next"] = None
        return front, delete_node["prev"]
    else:
        delete_node["next"]["prev"] = delete_node["prev"]
        delete_node["prev"]["next"] = delete_node["next"]
        return front, end
    
def delete_last(end):
    
    if not end["prev"]:
        return None
    else:
        end["prev"]["next"] = None
        return end["prev"]
    
def delete_first(front):
    
    if not front["next"]:
        return None
    else:
        front["next"]["prev"] = None
        return front["next"]

def main():
    n_list = int(input())
    target_list = [input().split() for i in range(n_list)]
    print(*dll_processor(target_list))
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_C&lang=jp
#???????????£????????????
#??¬?????????????????¬????????§????????¨???????????????????????????dummy????????????????????¨??§???????????????????????????????????§??????
def dll_processor(operations):
    
    front = None
    end = None
    
    for o in operations:
        if o[0] == "insert":
            front, end = insert(front, end,{ "next":None, "prev":None, "data":int(o[1]) })
        elif o[0] == "delete":
            front, end = delete(front, end, o[1])
        elif o[0] == "deleteFirst":
            front, end = delete_first(front, end)
        elif o[0] == "deleteLast":
            front, end = delete_last(front, end)
        #print(get_list(front))
        
    return get_list(front)

def get_list(front):
    if not front:
        return []
    
    l = []
    target = front
    while True:
        l.append(target["data"])
        if not target["next"]:
            break
        target = target["next"]
    return l

def insert(front, end, target):

    if front:
        front["prev"] = target
        target["next"] = front
        return target, end
    else:
        return target, target
    
def delete(front, end,target):

    delete_node = front
    while not delete_node["data"] == target:
        delete_node = delete_node["next"]
        if delete_node == None:
            return front, end

    if delete_node["prev"] == None:
        delete_node["next"]["prev"] = None
        return delete_node["next"], end
    elif delete_node["next"] == None:
        delete_node["prev"]["next"] = None
        return front, delete_node["prev"]
    else:
        delete_node["next"]["prev"] = delete_node["prev"]
        delete_node["prev"]["next"] = delete_node["next"]
        return front, end
    
def delete_last(front, end):
    
    if not end["prev"]:
        return None, None
    else:
        end["prev"]["next"] = None
        return front, end["prev"]
    
def delete_first(front, end):
    
    if not front["next"]:
        return None, None
    else:
        front["next"]["prev"] = None
        return front["next"], end

def main():
    n_list = int(input())
    target_list = [input().split() for i in range(n_list)]
    print(*dll_processor(target_list))
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:

import sys
from collections import deque

n = int(sys.stdin.readline())
inputs = sys.stdin.readlines()

linked_list = deque([])

for line in inputs:
    cmd = line[0]

    if len(line) == 2:
        value = line[1]

    if cmd == "insert":
        linked_list.appendleft(value)
    elif cmd == "delete":
        if value in linked_list:
            linked_list.remove(value)
    elif cmd == "deleteFirst":
        linked_list.popleft()
    elif cmd == "deleteLast":
        linked_list.pop()

print(*linked_list)

Submission status: Wrong Answer

Solution code:

import sys
from collections import deque

n = int(sys.stdin.readline())
inputs = sys.stdin.readlines()

linked_list = deque([])

for line in inputs[:-1]:
    cmd = line[0]

    if len(line) == 2:
        value = line[1]

    if cmd == "insert":
        linked_list.appendleft(value)
    elif cmd == "delete":
        if value in linked_list:
            linked_list.remove(value)
    elif cmd == "deleteFirst":
        linked_list.popleft()
    elif cmd == "deleteLast":
        linked_list.pop()

print(*linked_list)

Submission status: Wrong Answer

Solution code:
# f = open('input.txt')

n = int(input())
# n = int(f.readline())
doubly_linked_list = []

for i in range(n):
    cmd = input()
    # cmd = f.readline().strip()
    if cmd == 'deleteFirst':
        doubly_linked_list.pop(-1)
    elif cmd == 'deleteLast':
        doubly_linked_list.pop(0)
    else:
        cmd, x = cmd.split()
        if cmd == 'insert':
            doubly_linked_list.append(x)
        elif cmd == 'delete':
            doubly_linked_list.remove(x)

print(' '.join(doubly_linked_list))

Submission status: Wrong Answer

Solution code:
# f = open('input.txt')

n = int(input())
# n = int(f.readline())
doubly_linked_list = []

for i in range(n):
    cmd = input()
    # cmd = f.readline().strip()
    if cmd == 'deleteFirst':
        doubly_linked_list.pop(-1)
    elif cmd == 'deleteLast':
        doubly_linked_list.pop(0)
    else:
        cmd, x = cmd.split()
        if cmd == 'insert':
            doubly_linked_list.append(x)
        elif cmd == 'delete':
            doubly_linked_list.remove(x)

print(' '.join(reversed(doubly_linked_list)))