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: Runtime Error

Solution code:
MAX_N = 800000


class DoublyLinkedList(object):

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

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

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

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

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

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

    def delete(self, x):
        i = self._search_node(x)
        if i is not None:
            self._delete_node(i)

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

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

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

        while cur != self.nil_node.p:
            ans += "{} ".format(self.list[cur].val)
            cur = self.list[cur].next

        print ans.strip()


class Node(object):

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

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


def node_generator():
    p = [-1]

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

    return _node_generator

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

    d = DoublyLinkedList()

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

    d.show()

Submission status: Runtime Error

Solution code:
MAX_N = 1000001


class DoublyLinkedList(object):

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

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

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

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

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

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

    def delete(self, x):
        i = self._search_node(x)
        if i is not None:
            self._delete_node(i)

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

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

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

        while cur != self.nil_node.p:
            ans += "{} ".format(self.list[cur].val)
            cur = self.list[cur].next

        print ans.strip()


class Node(object):

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

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


def node_generator():
    p = [-1]

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

    return _node_generator

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

    d = DoublyLinkedList()

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

    d.show()

Submission status: Runtime Error

Solution code:
def insert(o,dll):
    dll.append(o)
def delete(o,dll):
    dll.remove(o)
def deleteFirst(dll):
    dll.pop(0)
def deleteLast(dll):
    dll.pop(-1)

def main():
    n = input()
    dll = []
    for _ in xrange(n):
        tmp = raw_input().split()
        if len(tmp) == 1:
            if tmp[0] == "deleteFirst":
                deleteFirst(dll)
            elif tmp[0] == "deleteLast":
                deleteLast(dll)
            else:
                print "This command is invalid."
                break
        elif len(tmp)==2:
            command = tmp[0]
            operand = tmp[1]
            if command == "insert":
                insert(operand,dll)
            elif command == "delete":
                delete(operand,dll)
            else:
                print "This command is invalid."
                break
    print " ".join(map(str,sorted(dll,reverse=True)))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def insert(o,dll):
    dll.insert(0,o)
def delete(o,dll):
    dll.remove(o)
def deleteFirst(dll):
    dll.pop(0)
def deleteLast(dll):
    dll.pop(-1)

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":
                deleteFirst(dll)
            elif tmp[0] == "deleteLast":
                deleteLast(dll)
            else:
                print "This command is invalid."
                break
        elif len(tmp)==2:
            command = tmp[0]
            operand = tmp[1]
            # print dll
            # print command, operand
            if command == "insert":
                insert(operand,dll)
            elif command == "delete":
                delete(operand,dll)
            else:
                print "This command is invalid."
                break
    print " ".join(map(str,dll))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = input()
lis = []
ans = 0
for i in xrange(n):
    com = raw_input()
    if   com[0] == 'i':
        lis.append(com[7:])
    elif com[6] == ' ':
        try:
            lis.pop(~lis[::-1].index(com[7:]))
        except:
            pass
    elif com[6] == 'F':
        lis.pop()
    else:
        bot += 1
 
print ' '.join( map(str, reversed(lis[ans:])) )

Submission status: Runtime Error

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

commands = {"insert": lambda x, l: insert(x, l),
            "delete": lambda x, l: delete(x, l),
            "deleteFirst": lambda l: deleteFirst(l),
            "deleteLast": lambda l: deleteLast(l)}


# ??£??????????????????????????????x?????????????´?????¶?????¶????
def insert(x, l):
    l = [x] + l
    return l


# ??????x??????????????????????´??????£??????????????????????????????
def delete(x, l):
    for i in xrange(len(l)):
        if l[i] == x:
            l.pop(i)
            break
    return l


# ?????????????????????????´????????????????
def deleteFirst(l):
    l.pop(0)
    return l


# ????????????????°????????´????????????????
def deleteLast(l):
    l.pop()
    return l


if __name__ == '__main__':
    N = input()
    functions, args = [], []
    for i in xrange(N):
        command = raw_input().split()
        functions.append(command[0])
        args.append(command[1])

    result = []
    for i in xrange(len(functions)):
        result = commands[functions[i]](args[i], result)
    print ' '.join(result)

Submission status: Runtime Error

Solution code:
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_C&lang=jp
sample_input = list(range(3))
sample_input[0] = '''7
insert 5
insert 2
insert 3
insert 1
delete 3
insert 6
delete 5'''
sample_input[1] = '''9
insert 5
insert 2
insert 3
insert 1
delete 3
insert 6
delete 5
deleteFirst
deleteLast'''
sample_input[2] = ''''''
give_sample_input = None
if give_sample_input is not None:
    sample_input_list = sample_input[give_sample_input].split('\n')
    def input():
        return sample_input_list.pop(0)
        
# main
class DoublyLinkedList():
    
    def __init__(self, a_data = []):
        self.data = a_data
    
    def insert(self, x):
        self.data.insert(0, x)
    
    def delete(self, x):
        self.data.remove(x)
    
    def delete_first(self):
        self.data.pop(0)
    
    def delete_last(self):
        self.data.pop()

    def to_str(self):
        output = ''
        for x in self.data:
            output += str(x) + ' '
        output = output.rstrip()
        return output

num_of_command = int(input())
doublely_list = DoublyLinkedList()
for n in range(num_of_command):
    str_command = input()
    if str_command == 'deleteFirst':
        doublely_list.delete_first()
        continue
    elif str_command == 'deleteLast':
        doublely_list.delete_last()
        continue
    command_name = str_command.split()[0]
    command_obj = int(str_command.split()[1])
    if command_name == 'insert':
        doublely_list.insert(command_obj)
    elif command_name == 'delete':
        doublely_list.delete(command_obj)

print(doublely_list.to_str())

Submission status: Runtime Error

Solution code:
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_C&lang=jp
sample_input = list(range(3))
sample_input[0] = '''7
insert 5
insert 2
insert 3
insert 1
delete 3
insert 6
delete 5'''
sample_input[1] = '''9
insert 5
insert 2
insert 3
insert 1
delete 3
insert 6
delete 5
deleteFirst
deleteLast'''
sample_input[2] = '''8
insert 1000000000
insert 999999999
deleteLast
insert 1234566890
insert 5
deleteFirst
insert 7
delete 5'''
give_sample_input = None
if give_sample_input is not None:
    sample_input_list = sample_input[give_sample_input].split('\n')
    def input():
        return sample_input_list.pop(0)
        
# main
class Node:
    
    def __init__(self, value, prev=None, next=None):
        self.value = value
        self.prev = prev
        self.next = next

class DoublyLinkedList:
    
    def __init__(self):
        self.be_empty()
    
    def be_empty(self):
        self.first = None
        self.last = None
        
    def is_empty(self):
        if self.first is None:
            assert self.last is None
            return True
        else: 
            return False
    
    def insert_node(self, node):
        if self.is_empty():
            self.first = node
            self.last = node
        else:
            self.first.prev = node
            node.next = self.first
            node.prev = None
            self.first = node
        
    def insert(self, x):
        self.insert_node(Node(x))
    
    def delete(self, x):
        '''Note : if x is not found, this does nothing'''
        if self.is_empty():
            return
        else:
            item = self.first
            while item is not None:
                if item.value == x:
                    break
                else:
                    item = item.next
            if item is self.last:
                self.delete_last()
            elif item is self.first:
                self.delete_first()
            else:
                prev = item.prev
                next = item.next
                prev.next = next
                next.prev = prev
                
    
    def delete_first(self):
        if self.first is self.last:
            self.be_empty()
        else:
            second = self.first.next
            second.prev = None
            self.first = second
    
    def delete_last(self):
        if self.first is self.last:
            self.be_empty()
        else:
            second = self.last.prev
            second.next = None
            self.last = second

    def to_str(self):
        output = ''
        if self.is_empty():
            return output
        else:
            item = self.first
            while item is not None:
                output += str(item.value) + ' '
                item = item.next
            output = output.rstrip()
            return output


num_of_command = int(input())
doublely_list = DoublyLinkedList()
for n in range(num_of_command):
    str_command = input()
    if str_command == 'deleteFirst':
        doublely_list.delete_first()
        continue
    elif str_command == 'deleteLast':
        doublely_list.delete_last()
        continue
    command_name = str_command.split()[0]
    command_obj = int(str_command.split()[1])
    if command_name == 'insert':
        doublely_list.insert(command_obj)
    elif command_name == 'delete':
        doublely_list.delete(command_obj)

print(doublely_list.to_str())

Submission status: Runtime Error

Solution code:
class Node:
    def __init__(self, key, prevNode, nextNode):
        self.key = key
        self.prevNode = prevNode
        self.nextNode = nextNode

def deleteNode(node):
    if node == fNode:
        return
    node.prevNode.nextNode = node.nextNode
    node.nextNode.preNode = node.prevNode

def searchNode(key):
    global fNode
    node = fNode.nextNode
    while node != fNode and node.key != key:
        node = node.nextNode
    return node

# ????????????????????????
fNode = Node(None, None, None)
fNode.prevNode = fNode
fNode.nextNode = fNode

n = int(input())

for i in range(0, n):
    command, key = input().split(' ')
    if command == 'insert':
        insertNode = Node(key, fNode, fNode.nextNode)
        fNode.nextNode.prevNode = insertNode
        fNode.nextNode = insertNode
    if command == 'delete':
        deleteNode(searchNode(key))
    if command == 'deleteFirst':
        deleteNode(fNode.nextNode)
    if command == 'deleteLast':
        deleteNode(fNode.lastNode)

    #nodeList(fNode)

# node List
node = fNode.nextNode
keys = []
while node != fNode:
    keys.append(node.key)
    node = node.nextNode

print(" ".join(keys))

Submission status: Runtime Error

Solution code:
class Node:
    def __init__(self, key, prevNode, nextNode):
        self.key = key
        self.prevNode = prevNode
        self.nextNode = nextNode

def deleteNode(node):
    if node == fNode:
        return
    node.prevNode.nextNode = node.nextNode
    node.nextNode.prevNode = node.prevNode

def searchNode(key):
    global fNode
    node = fNode.nextNode
    while node != fNode and node.key != key:
        node = node.nextNode
    return node

'''
def searchLast():
    global fNode
    node = fNode.nextNode
    while node != fNode:
        prevNode = node
        node = node.nextNode
    return prevNode
'''

def nodeList():
    global fNode
    node = fNode.nextNode
    keys = []
    while node != fNode:
        keys.append(node.key)
        node = node.nextNode

    print(" ".join(keys))

# ????????????????????????
fNode = Node(None, None, None)
fNode.prevNode = fNode
fNode.nextNode = fNode

n = int(input())
for i in range(0, n):
    inputs = input().split(' ')
 
for i in inputs:
    inputs2 = inputs.split(' ')
    command = inputs2[0]

    if command == 'insert':
        insertNode = Node(inputs2[1], fNode, fNode.nextNode)
        fNode.nextNode.prevNode = insertNode
        fNode.nextNode = insertNode
    if command == 'delete':
        deleteNode(searchNode(inputs[1]))
    if command == 'deleteFirst':
        deleteNode(fNode.nextNode)
    if command == 'deleteLast':
        deleteNode(fNode.prevNode)
        #deleteNode(searchLast())
nodeList()

Submission status: Runtime Error

Solution code:
from collections import deque
n = int(input())
d = deque()
for i in range(n):
    line = input().split()
    if len(line) == 2:
        command, ele = line
    else:
        command = line[0]
    if command == 'insert':
        d.appendleft(ele)
    elif command == 'delete':
        d.remove(ele)
    elif command == 'deleteFirst':
        d.popleft()
    elif command == 'deleteLast':
        d.pop()
print(' '.join(list(d)))

Submission status: Runtime Error

Solution code:
from collections import deque
n = int(input())
d = deque()
for i in range(n):
    line = input().split()
    if len(line) == 2:
        command, ele = line
    else:
        command = line[0]

    if command == 'insert':
        d.appendleft(ele)
    elif command == 'delete':
        d.remove(ele)
    elif command == 'deleteFirst':
        d.popleft()
    elif command == 'deleteLast':
        d.pop()
print(' '.join(list(d)))

Submission status: Runtime Error

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):
        key = ''
        try:
            command, key = map(str, input().split())

        except ValueError:
            command = input()

        print(command, key)
        eval("dll." + command + '(' + key + ')')

    print(dll.array)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

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())
    ans = ""

    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 + "()")

    for value in dll.array:
        ans += str(value) + " "

    print(ans.rstrip())

if __name__ == "__main__":
    main()

Submission status: Runtime Error

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):
        if x in dll.array:
            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())
    ans = ""

    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)
    for value in dll.array:
        ans += str(value) + " "

    print(ans.rstrip())

if __name__ == "__main__":
    main()

Submission status: Runtime Error

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


def main():

    n = int(input())
    ans = ""
    dll = []
    for _ in range(n):
        operation = input().split()
        command = operation[0]
        if len(command) == 6:
            key = str(operation[1])
            if command == "insert":
                dll.insert(0, key)
            else:
                dll.remove(key)

        else:
            if command[6] == 'F':
                dll.pop(0)
            else:
                dll.pop(-1)

    print(' '.join(dll))

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
from collections import deque

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

for i in range(n):
    command, num = input().split()
    if command == 'insert':
        q.appendleft(n)
    elif command == 'delete':
        try:
            q.remove(num)
        except Exception as e:
            pass
    elif command == 'deleteFirst':
        q.popleft()
    else:
        q.pop()

print(' '.join(q))

Submission status: Runtime Error

Solution code:
rom collections import deque
import sys

n = int(sys.stdin.readline())
q = deque()

for i in range(n):
    command = sys.stdin.readline()[:-1]
    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: Runtime Error

Solution code:
# coding: utf-8

import sys
from collections import deque

#n, q = map(int, input().split())
n = int(input())
tasks = {
    "insert": "appendleft",
    "delete": "remove",
    "deleteFirst": "pop",
    "deleteLast": "popleft"
}

a = deque()

for i in range(n):
    input_line = input()
    if input_line in tasks:
        #deleteFirst,deleteLast
        task = input_line
        eval("a.{}()".format(tasks[task]))
    else:
        #insert,delete
        task, item = input_line.split()
        eval("a.{}({})".format(tasks[task], item))

print(*a)

Submission status: Runtime Error

Solution code:
# coding: utf-8

import sys
from collections import deque

#n, q = map(int, input().split())
n = int(input())
tasks = {
    "insert": "appendleft",
    "delete": "remove",
    "deleteFirst": "popleft",
    "deleteLast": "pop"
}

a = deque()

for i in range(n):
    input_line = input()
    if input_line in tasks:
        #deleteFirst,deleteLast
        task = input_line
        eval("a.{}()".format(tasks[task]))
    else:
        #insert,delete
        task, item = input_line.split()
        eval("a.{}({})".format(tasks[task], item))

print(*a)

Submission status: Runtime Error

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:
        t, item = task.split()
        if t == "insert":
            a.appendleft(item)
        elif item in a:
            a.remove(item)

print(*a)

Submission status: Runtime Error

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(a))-1])

if __name__ == "__main__":
    main()

Submission status: Runtime Error

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 + "()")

    ans = ""
    for x in dll.array:
        ans += str(x) + ' '
    print(ans.strip())
        

if __name__ == "__main__":
    main()

Submission status: Runtime Error

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.insert(0, e)
    elif cmd.startswith("delete "):
        _, e = cmd.split(" ")
        l.remove(e)

print(" ".join(l))

Submission status: Runtime Error

Solution code:
from collections import deque

q = deque()

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

for _ in range(n):
    cmd = input()
    if cmd == "deleteFirst":
        q.popleft()
    elif cmd == "deleteLast":
        q.pop()
    elif cmd.startswith("insert "):
        v = cmd[7:]
        q.appendleft(v)
    elif cmd.startswith("delete "):
        v = cmd[7:]
        q.remove(v)
print(" ".join(q))

Submission status: Runtime Error

Solution code:
n = int(input())

ans = []
for i in range(n):
    c = input().split()
    cmd = c[0]
    x = 0
    if 1 < len(c):
        x = int(c[1])
    if cmd == 'insert':
        y = [x] + ans
        ans = y
    elif cmd == 'delete':
        index = ans.index(x)
        ans.pop(index)
    elif cmd == 'deleteFirst':
        ans.pop(0)
    elif cmd == 'deleteLast':
        ans.pop(len(ans) - 1)

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

Submission status: Runtime Error

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: Runtime Error

Solution code:
from collections import deque
    
n = int(input())
dll = deque()
    
for i in range(n):
    input_line = input().split()
    if input_line[0] == "insert":
        dll.appendleft(input_line[1])
    elif input_line[0] == "delete":
        try:
            dll.remove(input_line[1])
        except:
            pass
    elif input_line[0] == "deleteFirst":
        dll.popleft()
    else:
        dll.pop()
            
print(*dll

Submission status: Runtime Error

Solution code:
from collections import deque

n = int(input())
d = deque()
cmd = ['com', 0]
for i in range(n):
    cmd = input().split()
    if cmd[0] == 'insert':
        d.appendleft(int(cmd[1]))
    elif cmd[0] == 'delete':
        d.remove(int(cmd[1]))
    elif cmd[0] == 'deleteFirst':
        d.popleft()
    elif cmd[0] == 'deleteLast':
        d.pop()
print(*list(d))

Submission status: Runtime Error

Solution code:
class LinkedList(object):
    def __init__(self):
        self.data = []

    def insert(self, d):
        self.data.insert(0, d)

    def delete(self, d):
        self.data.remove(d)

    def delete_first(self):
        self.data.pop(0)

    def delete_last(self):
        self.data.pop(len(self.data)-1)

data = LinkedList()
for _ in range(int(input())):
    line_data = input().split()
    command = line_data[0]
    if len(line_data) == 2:
        d = int(line_data[1])

    if command == 'insert':
        data.insert(d)
    elif command == 'delete':
        data.delete(d)
    elif command == 'deleteFirst':
        data.delete_first()
    elif command == 'deleteLast':
        data.delete_last()

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

Submission status: Runtime Error

Solution code:
cnt=input()
lst=[]
for x in xrange(cnt):
    cmd = raw_input().split()
    if cmd[0] == "insert":
        lst = [int(cmd[1])] + lst
    elif cmd[0] == "delete":
        lst.remove(int(cmd[1]))
    elif cmd[0] == "deleteFirst":
        lst = lst[1:]
    elif cmd[0] == "deleteLast":
        lst = lst[:-1]
print " ".join([str(x) for x in lst])

Submission status: Runtime Error

Solution code:
#coding:UTF-8
def DLL(n,C):
    ans=[]
    for i in range(n):
        if C[i]=="deleteFirst":
            ans.pop(len(ans))
        elif C[i]=="delereLast":
            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: Runtime Error

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.reverse()
                ans.pop(ans.index(num))
                ans.reverse()
            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)