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:
n=int(raw_input())
l = []
for x in xrange(n):
    msg = raw_input().split()
    cmd = msg[0]
    if cmd == "insert":
        l.insert(0, msg[1])
    elif cmd == "delete":
        l.remove(msg[1])
    elif cmd == "deleteFirst":
        l.pop(0)
    elif cmd == "deleteLast":
        l.pop()

for x in l:
    print x,

Submission status: Runtime Error

Solution code:
n=int(raw_input())
l = []
for x in xrange(n):
    m = raw_input().split()
    cmd = m[0]
    if cmd == "insert":
        l.insert(0, m[1])
    elif cmd == "delete":
        if msg[1] in l:
            l.remove(m[1])
    elif cmd[7] == "F":
        l.pop(0)
    else:
        l.pop()

for x in l:
    print x,

Submission status: Runtime Error

Solution code:
n=int(raw_input())
l = []
for x in xrange(n):
    m = raw_input().split()
    cmd = m[0][-4]
    if c == "s":
        l.insert(0, m[1])
    elif c == "i":
        l.pop(0)
    elif c == "L":
        l.pop()
    else:
        try:
            l.remove(m[1])            
        except Exception, e:
            pass
            
print " ".join(l)

Submission status: Runtime Error

Solution code:
from collections import deque
n=int(raw_input())
que = deque()
for i in xrange(n):
    o = raw_input()
    if o == 'deleteFirst':
        del que[0]
    elif o == 'deleteLast':
        del que[-1]
    else:
        c,p = o.split()
        p = int(p)
        if c == 'insert':
            que.appendleft(p)
        elif c == 'delete':
            que.remove(p)
print ' '.join(map(str,que))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
from collections import deque
n=int(raw_input())
que = deque()
for i in xrange(n):
    o = raw_input()
    if o == 'deleteFirst':
        del que[0]
    elif o == 'deleteLast':
        del que[-1]
    else:
        c,p = o.split()
        p = int(p)
        if c == 'insert':
            que.appendleft(p)
        elif c == 'delete':
            que.remove(p)
print ' '.join(map(str,que))

Submission status: Runtime Error

Solution code:
from collections import deque
que = deque()
for i in range(int(input())):
    command = input()
    if command == 'deleteFirst':
        que.popleft()
    elif command == 'deleteLast':
        que.pop()
    else:
        c, n = command.split()
        if c == 'insert':
            que.appendleft(int(n))
        elif c == 'delete':
            que.remove(int(n))
print(' '.join([str(x) for x in que]))

Submission status: Runtime Error

Solution code:
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_C
# Doubly Linked List
# Result:
import sys

class DoublyLikedList(object):
    def __init__(self):
        self.head = None
        self.tail = None

    def __str__(self):
        vals = []
        pointer = self.head
        while pointer != None:
            vals.append(str(pointer.val))
            pointer = pointer.next

        if len(vals) == 0:
            return ''
        else:
            return ' '.join(vals)

    def insert(self, x):
        itm = ListItem(x)
        if self.head == None:
            self.head = itm
            self.tail = itm
        else:
            itm.next = self.head
            self.head.prev = itm
            self.head = itm

    def delete(self, x):
        pointer = self.head
        while pointer != None:
            if pointer.val == x:
                if pointer == self.head:
                    self.delete_first()
                elif pointer == self.tail:
                    self.delete_last()
                else:
                    if pointer.prev != None:
                        pointer.prev.next = pointer.next
                    if pointer.next != None:
                        pointer.next.prev = pointer.prev
                break
            pointer = pointer.next

    def delete_first(self):
        if self.head == None:
            return
        if self.head == self.tail:
            self.tail = None
        self.head = self.head.next
        if self.head == None:
            return
        else:
            self.head.prev = None

    def delete_last(self):
        if self.head == None:
            return
        if self.head == self.tail:
            self.tail = None
        self.tail = self.tail.prev
        if self.tail == None:
            return
        else:
            self.tail.next = None

class ListItem(object):
    def __init__(self, x):
        self.val = x
        self.prev = None
        self.next = None

### main
lst = DoublyLikedList()
n = int(sys.stdin.readline().rstrip())
for e in range(0, n):
    strs = sys.stdin.readline().rstrip().split(' ')
    if strs[0] == 'insert':
        lst.insert(int(strs[1]))
    elif strs[0] == 'delete':
        lst.delete(int(strs[1]))
    elif strs[0] == 'deleteFirst':
        lst.delete_first()
    elif strs[0] == 'deleteLast':
        lst.delete_last()

print lst

Submission status: Runtime Error

Solution code:
n = int( raw_input( ) )
eles = []
for i in range( n ):
	op = raw_input( ).split( " " )
	if "insert" == op[0]:
		eles.insert( 0, op[1] )
	elif "delete" == op[0]:
		eles.remove( op[1] )
	elif "deleteFirst" == op[0] :
		del eles[0]
	elif "deleteLast" == op[0]:
		eles.pop( )

print( " ".join( eles ) )

Submission status: Runtime Error

Solution code:
n = int( raw_input( ) )
eles = []
for i in range( n ):
	op = raw_input( ).split( " " )
	if "insert" == op[0]:
		eles.insert( 0, op[1] )
	elif "delete" == op[0]:
		for val in eles:
			if op[1] == val:
				eles.pop( i )
	elif "deleteFirst" == op[0] :
		del eles[0]
	elif "deleteLast" == op[0]:
		eles.pop( )

print( " ".join( eles ) )

Submission status: Runtime Error

Solution code:
import sys

n = int( raw_input( ) )
eles = []
lines = sys.stdin.readlines()
for line in lines:
	op = line.split( " " )
	op[1] = op[1].strip( )
	if "insert" == op[0]:
		eles.insert( 0, op[1] )
	elif "delete" == op[0]:
		if op[1].rstrip( ) in eles:
			eles.remove( op[1] )
	elif "deleteFirst" == op[0] :
		del eles[0]
	elif "deleteLast" == op[0]:
		eles.pop( )

print( " ".join( eles ) )

Submission status: Runtime Error

Solution code:
import sys

n = int( raw_input( ) )
eles = []
for line in sys.stdin:
	op = line.split( " " )
	op[1] = op[1].strip( )
	if "insert" == op[0]:
		eles.insert( 0, op[1] )
	elif "delete" == op[0]:
		if op[1].rstrip( ) in eles:
			eles.remove( op[1] )
	elif "deleteFirst" == op[0] :
		del eles[0]
	elif "deleteLast" == op[0]:
		eles.pop( )

print( " ".join( eles ) )

Submission status: Runtime Error

Solution code:
n=int(raw_input())
while n:
    n-=1
    s=map(str,raw_input().split())
    if s[0][0]=='i':
        ans.insert(0,s[1])
    elif s[0][-3]=='r':
        ans.pop(0)
    elif s[0][-3]=='a':
        ans.pop(0)
    else:
        ans.remove(s[1])
for i in ans:
    print i,

Submission status: Runtime Error

Solution code:
ans=[]
n=int(raw_input())
while n:
    n-=1
    s=map(str,raw_input().split())
    if s[0][0]=='i':
        ans.insert(0,s[1])
    elif s[0][-3]=='r':
        ans.pop(0)
    elif s[0][-3]=='a':
        ans.pop()
    else:
        for i,j in enumerate(ans):
            if j==s[1]:
                ans.pop(i)
                break
print ' '.join(i)

Submission status: Runtime Error

Solution code:
import sys
import collections
n=int(raw_input())
ans=collections.deque()
while n:
    n-=1
    s=sys.stdin.readline().rstrip().split(' ')
    if s[0][0]=='i':
        ans.appendleft(s[1])
    elif s[0][-3]=='r':
        ans.popleft()
    elif s[0][-3]=='a':
        ans.pop()
    else:
        ans.remove(s[1])
sys.stdout.write(' '.join(ans))
print

Submission status: Runtime Error

Solution code:
class LinkedList():
  def __init__(self):
    self.linked_list = []
  def insert(self,x):
    self.linked_list.insert(0,x)
  def delete(self,x):
    self.linked_list.remove(x)
  def deleteFirst(self):
    self.linked_list.pop(0)
  def deleteLast(self):
    self.linked_list.pop(-1)
  def get(self):
    return ' '.join(self.linked_list)

linkedlist = LinkedList()
for i in range(int(raw_input())):
  line = raw_input()
  if line.count(' '):
    c, x = line.split(' ')
  else:
    c = line
    x = ''
  if c == "insert":
    linkedlist.insert(x)
  elif c == "delete":
     linkedlist.delete(x)
  elif c == "deleteFirst":
     linkedlist.deleteFirst()
  else:
     linkedlist.deleteLast()

print linkedlist.get()

Submission status: Runtime Error

Solution code:
import collections
n = int(input())
que = collections.deque()
for _ in range(n):
    command = input()
    if 'insert' in command:
        command, num = command.split()
        que.appendleft(int(num))
    elif 'deleteFirst' in command:
        que.popleft()
    elif 'deleteLast' in command:
        que.pop()
    elif 'delete' in command:
        command, num = command.split()
        que.remove(int(num))
print(' '.join(map(str, que)))

Submission status: Runtime Error

Solution code:
import sys
import collections
n = int(input())
que = collections.deque()

for _ in range(n):
    command = sys.stdin.readline().strip()
    if 'i' == command[0]:
        command, num = command
        que.appendleft(num)
    elif 'deleteFirst\n' == command:
        que.popleft()
    elif 'deleteLast\n' == command:
        que.pop()
    else:
        command, num = command.split()
        try:
            que.remove(num)
        except ValueError:
            pass
print(' '.join(map(str, que)))

Submission status: Runtime Error

Solution code:
from collections import deque

n = int(input())
que = deque()

for i in range(n):
    command = input()
    if command == "deleteFirst":
        que.popleft()
    elif command == "deleteLast":
        que.pop()
    else:
        a, b = command.split()
        if a == "insert":
            que.appendleft(b)
        else:
            que.remove(b)

print(*que)

Submission status: Runtime Error

Solution code:
n = int(raw_input())
R = []
for i in xrange(n):
    L = raw_input().split()
    order = L[0]
    value = int(L[1])
    if order == 'insert':
        R.insert(0, value)
    if order == 'delete':
        R.remove(value)
    if order == 'deleteFirst':
        R.pop()
    if order == 'deleteLast':
        R.pop(len(R)-1)
print ' '.join(map(str, R))

Submission status: Runtime Error

Solution code:
n = int(raw_input())
R = []
for i in xrange(n):
    L = raw_input().split()
    order = L[0]
    value = 0
    if len(L) > 1:
        value = int(L[1])
    if order == 'insert':
        R.insert(0, value)
    if order == 'delete':
        R.remove(value)
    if order == 'deleteFirst':
        R.pop(0)
    if order == 'deleteLast':
        R.pop()
print ' '.join(map(str, R))

Submission status: Runtime Error

Solution code:
list=[]
n=int(raw_input())
for i in range(n):
	inst,value=raw_input().split()
	if inst=='insert':
		list.insert(0,int(value))
	elif inst=='delete':
		list.remove(int(value))
	elif inst=='deleteFirst':
		del list[0]
	else :list.pop()
print list

Submission status: Runtime Error

Solution code:
list=[]
n=int(raw_input())
for i in range(n):
	inst,value=raw_input().split()
	if inst=='insert':
		list.insert(0,int(value))
	elif inst=='delete':
		list.remove(int(value))
	elif inst=='deleteFirst':
		del list[0]
	else :list.pop()
print list

Submission status: Runtime Error

Solution code:
list=[]
n=int(raw_input())
for i in range(n):
	inst=raw_input().split()
	
	if inst[0]=='insert':
		list.insert(0,int(inst[1]))
	elif inst[0]=='delete':
		list.remove(int(inst[1]))
	elif inst[0]=='deleteFirst':
		del list[0]
	else :list.pop()

for i in list:
	print i,

Submission status: Runtime Error

Solution code:
A = []
n = int(raw_input())
stack = []
for i in range(n):
	A.append(raw_input())

for i in A:
	if "insert" in i:
		stack.insert(0, i[7:])
	elif "delete " in i:
		stack.remove(i[7:])
	elif "deleteFirst" in i:
		stack.pop(0)
	elif "deleteLast" in i:
		stack.pop()
print " ".join(stack)

Submission status: Runtime Error

Solution code:
A = []
n = int(raw_input())
stack = []
for i in range(n):
	A.append(raw_input())

for i in A:
	if "insert" in i:
		stack.insert(0, i[7:])
	elif "delete " in i and len(stack) > 0:
		stack.remove(i[7:])
	elif "deleteFirst" in i and len(stack) > 0:
		stack.pop(0)
	elif "deleteLast" in i and len(stack) > 0:
		stack.pop()
print " ".join(stack)

Submission status: Runtime Error

Solution code:
A = []
n = int(raw_input())
stack = []
for i in range(n):
	A.append(raw_input())

for i in A:
	if "insert" in i:
		stack.insert(0, i[7:])
	elif "delete " in i and len(stack) > 0:
		stack.remove(i[7:])
	elif "deleteFirst" in i and len(stack) > 0:
		stack.pop(0)
	elif "deleteLast" in i and len(stack) > 0:
		stack.pop()
if len(stack) > 0:
    print " ".join(stack)

Submission status: Runtime Error

Solution code:
A = []
n = int(raw_input())
stack = []
for i in range(n):
	A.append(raw_input())

for i in A:
	if "insert" in i:
		stack.insert(0, int(i[7:]))
	elif "delete " in i and len(stack) > 0:
		stack.remove(int(i[7:]))
	elif "deleteFirst" in i and len(stack) > 0:
		stack.pop(0)
	elif "deleteLast" in i and len(stack) > 0:
		stack.pop()
if len(stack) > 0:
    print " ".join(map(str, stack))

Submission status: Runtime Error

Solution code:
from collections import deque
n = int(raw_input())
stack = deque()
for i in range(n):
	i = raw_input()
	if "insert" in i:
		stack.insert(0, int(i[7:]))
	elif "delete " in i:
		if int(i[7:]) in stack:
		    stack.remove(int(i[7:]))
	elif "deleteFirst" in i:
		stack.pop(0)
	elif "deleteLast" in i:
		stack.pop()
print " ".join(map(str, stack))

Submission status: Runtime Error

Solution code:
from collections import deque
n = int(raw_input())
stack = []
for i in range(n):
	i = raw_input()
	if "insert" in i:
		stack.appendleft(int(i[7:]))
	elif "delete " in i:
		if int(i[7:]) in stack:
		    stack.remove(int(i[7:]))
	elif "deleteFirst" in i:
		stack.popleft()
	elif "deleteLast" in i:
		stack.pop()
print " ".join(map(str, stack))

Submission status: Runtime Error

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

class Node(object):
    def __init__(self, data, prev_node, next_node):
        self.data = data
        self.prev_node = prev_node
        self.next_node = next_node

class DoubleList(object):
    head = None
    tail = None

    def insert(self, data):
        new_node = Node(data, None, None)
        if self.head is None:
            self.head = self.tail = new_node
        else:
            new_node.next_node = self.head
            new_node.prev_node = None
            self.head.prev_node = new_node
            self.head = new_node

    def delete(self, data_value):
        current_node = self.head
        while current_node is not None:
            if current_node.data == data_value:
                if current_node.prev_node is not None and current_node.next_node is not None:
                    current_node.prev_node.next_node = current_node.next_node
                    current_node.next_node.prev_node = current_node.prev_node
                elif current_node.prev_node is None:
                    self.head = current_node.next_node
                    current_node.next_node.prev_node = None
                elif current_node.next_node is None:
                    self.tail = current_node.prev_node
                    current_node.prev_node.next_node = None
            current_node = current_node.next_node

    def deleteFirst(self):
        if self.head.next_node is not None:
            self.head.next_node.prev_node = None
            self.head = self.head.next_node
        else:
            self.head = self.tail = None

    def deleteLast(self):
        if self.tail.prev_node is not None:
            self.tail.prev_node.next_node = None
            self.tail = self.tail.prev_node
        else:
            self.head = self.tail = None

    def show(self):
        current_node = self.head
        data = ""
        while current_node is not None:
            data += current_node.data+" "
            current_node = current_node.next_node
        print data[:-1]

if __name__ == "__main__":
    DL = DoubleList()
    num = int(raw_input())
    for i in range(num):
        line = raw_input()
        if " " in line:
            operation = line.strip().split()[0]
            value = line.strip().split()[1]
        else:
            operation = line.strip()

        if operation == "insert":
            DL.insert(value)
        elif operation == "delete":
            DL.delete(value)
        elif operation == "deleteFirst":
            DL.deleteFirst()
        else:
            DL.deleteLast()

    DL.show()

Submission status: Runtime Error

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

class Node(object):
    def __init__(self, data, prev_node, next_node):
        self.data = data
        self.prev_node = prev_node
        self.next_node = next_node

class DoubleList(object):
    head = None
    tail = None

    def insert(self, data):
        new_node = Node(data, None, None)
        if self.head is None:
            self.head = self.tail = new_node
        else:
            new_node.next_node = self.head
            new_node.prev_node = None
            self.head.prev_node = new_node
            self.head = new_node

    def delete(self, data_value):
        current_node = self.head
        while current_node is not None:
            if current_node.data == data_value:
                if current_node.prev_node is not None and current_node.next_node is not None:
                    current_node.prev_node.next_node = current_node.next_node
                    current_node.next_node.prev_node = current_node.prev_node
                    break
                elif current_node.prev_node is None:
                    self.head = current_node.next_node
                    current_node.next_node.prev_node = None
                elif current_node.next_node is None:
                    self.tail = current_node.prev_node
                    current_node.prev_node.next_node = None
            current_node = current_node.next_node

    def deleteFirst(self):
        if self.head.next_node is not None:
            self.head.next_node.prev_node = None
            self.head = self.head.next_node
        else:
            self.head = self.tail = None

    def deleteLast(self):
        if self.tail.prev_node is not None:
            self.tail.prev_node.next_node = None
            self.tail = self.tail.prev_node
        else:
            self.head = self.tail = None

    def show(self):
        current_node = self.head
        data = ""
        while current_node is not None:
            data += current_node.data+" "
            current_node = current_node.next_node
        print data[:-1]

if __name__ == "__main__":
    DL = DoubleList()
    num = int(raw_input())
    for i in range(num):
        line = raw_input()
        if " " in line:
            operation = line.strip().split()[0]
            value = line.strip().split()[1]
        else:
            operation = line.strip()

        if operation == "insert":
            DL.insert(value)
        elif operation == "delete":
            DL.delete(value)
        elif operation == "deleteFirst":
            DL.deleteFirst()
        else:
            DL.deleteLast()

    DL.show()

Submission status: Runtime Error

Solution code:
n = int(raw_input())
L = list()

for i in range(n):
    S = raw_input().split(" ")
    if S[0] ==  "insert":
        L.insert(0, S[1])

    elif S[0] == "delete":
        L.remove(S[1])

    elif S[0] == "deleteFirst":
        L.pop(0)

    elif S[0] == "deleteLast":
        L.pop()

print " ".join(L)

Submission status: Runtime Error

Solution code:
import sys


DLL = []

def insert(x):
    DLL.insert(0, x)

def delete(x):
    DLL.remove(x)

def deleteFirst():
    DLL.pop(0)

def deleteLast():
    DLL.pop(-1)


def main(commands):
    for command in commands:
        vals = command.strip().split(" ")
        com = vals[0]
        if len(vals) == 2:
            num = vals[1]
            if com == "insert":
                insert(num)
            elif com == "delete":
                delete(num)
        elif com == "deleteFirst":
            deleteFirst()
        else:
            deleteLast()
    return DLL


if __name__ == "__main__":
    lines = sys.stdin.readlines()
    n = lines[0]
    commands = lines[1:]
    DLL = main(commands)
    print " ".join(DLL)

Submission status: Runtime Error

Solution code:
n = int(raw_input())
L = list()

for i in range(n):
    S = raw_input().split(" ")
    if S[0] ==  "insert":
        L.insert(0, S[1])

    elif S[0] == "delete":
        L.remove(S[1])

    elif S[0] == "deleteFirst":
        L.pop(0)

    elif S[0] == "deleteLast":
        L.pop(-1)

print " ".join(L)

Submission status: Runtime Error

Solution code:
import sys


DLL = []

def insert(x):
    DLL.insert(0, x)

def delete(x):
    if len(DLL) > 0:
        DLL.remove(x)

def deleteFirst():
    if len(DLL) > 0:
        DLL.pop(0)

def deleteLast():
    if len(DLL) > 0:
        DLL.pop(-1)


def main(commands):
    for command in commands:
        vals = command.strip().split(" ")
        com = vals[0]
        if len(vals) == 2:
            num = vals[1]
            if com == "insert":
                insert(num)
            elif com == "delete":
                delete(num)
        elif com == "deleteFirst":
            deleteFirst()
        else:
            deleteLast()
    return DLL


if __name__ == "__main__":
    lines = sys.stdin.readlines()
    n = lines[0]
    commands = lines[1:]
    DLL = main(commands)
    print " ".join(DLL)

Submission status: Runtime Error

Solution code:
N = int(raw_input())
A = []
B = []

def insert(B, x):
    B.insert(0, x)
    return B
def delete(B, x):
    i = 0
    for num in B:
        if num == x:
            B.pop(i)
            break
        i += 1
    return B
def deleteFirst(B):
    B.pop(0)
    return B
def deleteLast(B):
    B.pop()
    return B
operation = {'insert':insert, 'delete':delete, 'deleteFirst':deleteFirst, 'deleteLast':deleteLast}

for i in range(N):
    a = raw_input().split()
    if len(a) == 2:
        A.append([a[0], int(a[1])])
    else:
        A.append([a[0]])


for item in A:
    if len(item) == 2:
        command, num = item
        B = operation[command](B, int(num))
    else:
        command = item[0]
        B = operation[command](B)

print ' '.join(B)

Submission status: Runtime Error

Solution code:
import sys

def isEmpty(S):
  if len(S) == 0:
    return True

def isFull(S):
  if len(S) >= 100000:
    return True



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

a = 0
S = []

for i in range(n):
  text = raw_input()
  x_list = text.split()
  if x_list[0] == 'insert':
    S.insert(0, x_list[1])
    a += 1
  elif x_list[0] == 'delete':
    S.remove(x_list[1])
    a -= 1
  elif x_list[0] == 'deleteFirst':
    S.pop(0)
    a -= 1
  else:
    a -= 1
    S.pop()

for i in range(a):
  print S[i],

Submission status: Runtime Error

Solution code:
import sys

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

a = 0
S = []

for i in range(n):
  text = raw_input()
  x_list = text.split()
  if x_list[0] == 'insert':
    S.insert(0, x_list[1])
    a += 1
  elif x_list[0] == 'delete':
    S.remove(x_list[1])
    a -= 1
  elif x_list[0] == 'deleteFirst':
    S.pop(0)
    a -= 1
  else:
    a -= 1
    S.pop()

print " ".join(S)
"""
for i in range(a):
  print S[i],
 """

Submission status: Runtime Error

Solution code:
N = int(raw_input())
A = []
B = []

def insert(B, x):
    B.insert(0, x)
    return B
def delete(B, x):
    B.remove(x)
    return B
def deleteFirst(B):
    B.pop(0)
    return B
def deleteLast(B):
    B.pop()
    return B
operation = {'insert':insert, 'delete':delete, 'deleteFirst':deleteFirst, 'deleteLast':deleteLast}

for i in range(N):
    a = raw_input().split()
    if len(a) == 2:
        A.append([a[0], int(a[1])])
    else:
        A.append([a[0]])


for item in A:
    if len(item) == 2:
        command, num = item
        B = operation[command](B, int(num))
    else:
        command = item[0]
        B = operation[command](B)

B_str = map(str, B)
print ' '.join(B_str)

Submission status: Runtime Error

Solution code:
#coding:utf-8
#1_3_C
from collections import deque
n = int(input())
ary = deque()
for i in range(n):
    cmd = input().split()
    if cmd[0] == "insert":
        ary.appendleft(cmd[1])
    elif cmd[0] == "delete":
        ary.remove(cmd[1])
    elif cmd[0] == "deleteFirst":
        ary.popleft()
    elif cmd[0] == "deleteLast":
        ary.pop()

print(" ".join(ary))

Submission status: Runtime Error

Solution code:
n=input()
List=[]
for i in range(n):
	command=raw_input().split()
	if command[0]=="insert":
		ll=[]
		ll.append(command[1])
		List=ll+List
	elif command[0]=="delete":
		List.remove(command[1])
	elif command[0]=="deleteFirst":
		List=List[1:]
	else :
		List=List[:-1]
print(" ".join(List))

Submission status: Runtime Error

Solution code:
n=input()
List=[]
for i in range(n):
	command=raw_input().split()
	if command[0]=="insert":
		ll=[]
		ll.append(int(command[1]))
		List=ll+List
	elif command[0]=="delete":
		List.remove(int(command[1]))
	elif command[0]=="deleteFirst":
		List=List[1:]
	else :
		List=List[:-1]
print(" ".join(map(str,List)))

Submission status: Runtime Error

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

import collections


def process(commands):
    queue = collections.deque()
    for c in commands:
        if "insert" in c:
            queue.appendleft(int(c[7:]))
        elif "deleteFirst" in c:
            _ = queue.popleft()
        elif "deleteLast" in c:
            _ = queue.pop()
        elif "delete" in c:
            queue.remove(int(c[7:]))
    print(" ".join(list(map(str, queue))))


def main():
    n = int(input())
    process([input() for i in range(n)])


if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

n = input()
list = []
for i in xrange(n):
    command, key = raw_input().split()
    if command == "insert":
        list.insert(0, key)
    elif command == "delete":
        list.remove(key)
    elif command == "deleteFirst":
        list.pop(0)
    elif command == "deleteLast":
        list.pop()
        
print " ".join(list)

Submission status: Runtime Error

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

n = input()
list = []
for i in xrange(n):
    command = raw_input().split()
    if command[0] == "insert":
        list.insert(0, command[1])
    elif command[0] == "delete":
        list.remove(command[1])
    elif command[0] == "deleteFirst":
        list.pop(0)
    elif command[0] == "deleteLast":
        list.pop()
        
print " ".join(list)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import numpy as np

n = input()
list = np.array([], dtype=long)

for i in xrange(n):
    command = raw_input().split()
    if command[0] == "insert":
        list = np.append(int(command[1]), list)
    elif command[0] == "delete":
        key = int(command[1])
        for i in xrange(len(list)):
            if list[i] == key:
                list = np.delete(list, i)
    elif command[0] == "deleteFirst":
        list = np.delete(list, 0)
    elif command[0] == "deleteLast":
        list = np.delete(list, len(list)-1)
        
print " ".join(map(str,list))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
n = input()
l = []
tail = 0
for i in xrange(n):
    cmd = raw_input().split()
    if cmd[0] == "insert":
        l.append(cmd[1])
    elif cmd[0] == "delete":
        l.pop(l.lindex(cmd[1]))
    elif cmd[0] == "deleteFirst":
        l.pop()
    elif cmd[0] == "deleteLast":
        tail += 1

print " ".join(l[tail:][::-1])

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
n = input()
l = []
tail = 0
for i in xrange(n):
    cmd = raw_input().split()
    if cmd[0] == "insert":
        l.append(cmd[1])
    elif cmd[0] == "delete":
        l.pop(len(l) - l[::-1].index(cmd[1]) -1)
    elif cmd[0] == "deleteFirst":
        l.pop()
    elif cmd[0] == "deleteLast":
        tail += 1

print " ".join(l[tail:][::-1])

Submission status: Runtime Error

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

class DoublyLinkedList:
    def __init__(self):
        self.head = None
        self.tail = None

    def __str__(self):
        ret = ''
        n = self.head
        while True:
            if n == None:
                break
            else:
                ret += str(n.data) + ' '
                n = n.next
        return ret[:-1]


    def insert(self,v):
        n = Node(v)
        if self.head == None:
            self.head = n
            self.tail = n
        else:
            n.next = self.head
            n.next.prev = n
            self.head = n

    def delete(self,v):
        n = self.head
        while True:
            if n == None:
                break
            else:
                if n.data == v:
                    if n.next == None:
                        self.tail = n.prev
                    else:
                        n.next.prev = n.prev
                    if n.prev == None:
                        self.head = n.next
                    else:
                        n.prev.next = n.next
                    break
                n = n.next

    def deleteFirst(self):
        if self.head != None:
            self.head = self.head.next
            self.head.prev = None
        else:
            raise


    def deleteLast(self):
        if self.tail != None:
            self.tail = self.tail.prev
            self.tail.next = None
        else:
            raise

n = int(raw_input())
commends = []
for i in range(n):
    commends.append(raw_input())

l = DoublyLinkedList()
for c in commends:
    if c == "deleteFirst":
        l.deleteFirst()
    elif c == "deleteLast":
        l.deleteLast()
    else:
        op,val = c.split(' ')
        val = int(val)
        if op == "insert":
            l.insert(val)
        elif op == "delete":
            l.delete(val)

print l

Submission status: Runtime Error

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

n = int(input())
command = [input().split() for i in range(n)]
ans = []
for i in range(n):
    if command[i][0] == "insert":
        ans.insert(0, command[i][1])
    elif command[i][0] == "delete":
        ans.remove(command[i][1])
    elif command[i][0] == "deleteFirst":
        ans.pop(0)
    else:
        ans.pop()

print (' '.join(ans))