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:
#include<stdio.h>
#include<stdlib.h>

struct node{
	int key;
	struct node *next;
	struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

void init()
{
	nil = NULL;
}

void insert(int key)
{
	struct node *newcell;

	newcell = (struct node*)malloc(sizeof(struct node));
	if (newcell == NULL) {
		puts( "malloc failed." );
		return;
	}

	if (nil == NULL) {
		nil = newcell;
		nil->next = nil;
		nil->prev = nil;
		nil->key = key;
		return;
	} else if (nil->next == nil) {
		nil->prev = newcell;
	} else if (nil->next->next == nil) {
		nil->prev->prev = newcell;
	}
	newcell->key = nil->key; 
	newcell->prev = nil;
	newcell->next = nil->next;
	nil->next->prev = newcell;
	nil->next = newcell;
	nil->key = key;
	return;
}

void deleteLast()
{
	struct node *last;
	if (nil->next == nil) {
		free(nil);
		nil = NULL;
		return;
	} else {
		last = nil->prev;
		nil->prev->prev->next = nil;
		nil->prev = last->prev;
		free(last);
	}
}

void deleteFirst()
{
	struct node *first;
	if (nil->prev == nil) {
		free(nil);
		nil = NULL;
		return;
	} else {
		first = nil;
		nil = nil->next;
		nil->prev = first->prev;
		first->prev->next = nil;
		free(first);
	}
}

void delete(int key)
{
	struct node *p;
	if (nil->key == key) {
		deleteFirst();
		return;
	}
	for (p = nil->next; p != nil; p = p->next) {
		if (p->key == key) {
			p->prev->next = p->next;
			p->next->prev = p->prev;
			free(p);
			return;
		}
	}
}

void printList()
{
	struct node *p;
	printf("%d", nil->key);
	for (p = nil->next; p != nil; p = p->next) {
		printf(" %d", p->key);
	}
	printf("\n");
	return;
}

int main(){
	int i, n, key;
	char com[12];
	struct node *p;

	scanf("%d", &n);
	init();

	for ( i = 0; i < n; i++ ){
		scanf("%s", com);

		if ( com[0] == 'i' ) {
			scanf("%d", &key);
			insert(key);
		} else if ( com[0] == 'd' ) {
			if (strlen(com) > 6){
				if ( com[6] == 'F' ) {
					deleteFirst();
				} else if ( com[6] == 'L' ) {
					deleteLast();
				}
			} else {
				scanf("%d", &key);
				delete(key);
			}
		}
	}
	printList();
	return 0;
}

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

for i in range(num):

    order = line[i].split()

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

print(' '.join(dq))

Submission status: Runtime Error

Solution code:
from collections import deque

queue = deque([])

n = int(input())

for i in range(n):
    commands = input().split(" ")
    command = commands[0]
    if command == "insert":
        queue.appendleft(commands[1])
    elif command == "delete":
        queue.remove(commands[1])
    elif command == "deleteFirst":
        queue.popleft()
    elif command == "deleteLast":
        queue.pop()

last = queue.pop()
for i in queue:
    print(i, end=" ")

print(last)

Submission status: Runtime Error

Solution code:
from collections import deque

queue = deque()

for _ in range(int(input())):
    commands = input().split(" ")
    if command[0] == "insert":
        queue.appendleft(commands[1])
    elif command[0] == "delete":
        try:
            queue.remove(commands[1])
        except ValueError:
            pass
    elif command[0] == "deleteFirst":
        queue.popleft()
    elif command[0] == "deleteLast":
        queue.pop()

print(" ".join(queue))

Submission status: Runtime Error

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

d = deque()

for _ in range(n):
    com = input()
    if ( len(com) == 8):
        com , i = com.split()

    if (com[0] == 'i'):
        d.appendleft(int(i))
    elif (com[0] == 'd'):
        if (len(com) == 6):
            d.remove(int(i))
        elif (com[6] == 'F'):
            d.popleft()
        elif (com[6] == 'L'):
            d.pop()
ans = map(str, d)
ans = " ".join(ans)
print(ans)

Submission status: Runtime Error

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

d = deque()

for _ in range(n):
    com = input()

    if (com[0] == 'i'):
        com ,i = com.split()
        d.appendleft(int(i))
    elif (com[0] == 'd'):
        if (com[7].isdigit()):
            com, i = com.split()
            d.remove(int(i))
        elif (com[6] == 'F'):
            d.popleft()
        elif (com[6] == 'L'):
            d.pop()
ans = map(str, d)
ans = " ".join(ans)
print(ans)

Submission status: Runtime Error

Solution code:
from collections import deque

n = int(input())
cmd = [input().split() for i in range(n)]
stack = deque()

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def order_each(orders):
    from collections import deque
    linked = deque([])
    for i in orders:
        order = i[0]
        if order == "insert":
            linked.appendleft(i[1])
        elif order == "delete":
            linked.remove(i[1])
        elif order == "deleteFirst":
            linked.popleft()
        elif order == "deleteLast":
            linked.pop()

    print(' '.join(linked))



orders = []

n = int(input())

for i in range(n):
    orders.append(list(input().split()))

order_each(orders)

Submission status: Runtime Error

Solution code:
from collections import deque
def order_each(orders):
    linked = deque([])
    for i in orders:
        order = i[0]
        if order == "insert":
            linked.appendleft(i[1])
        elif order == "delete":
            linked.remove(i[1])
        elif order == "deleteFirst":
            linked.popleft()
        elif order == "deleteLast":
            linked.pop()

    print(' '.join(linked))



orders = []

n = int(input())

for i in range(n):
    orders.append(list(input().split()))

order_each(orders)

Submission status: Runtime Error

Solution code:
n = int(raw_input())

A = []
for i in range(n):
	com = raw_input().split()
	if com[0] == "insert":
		A.insert(0, int(com[1]))
	elif com[0] == "delete":
		index = A.index(int(com[1]))
		del A[index]
	elif com[0] == "deleteFirst":
		del A[0]
	else:
		del A[-1]

for i in range(len(A)):
	if i != len(A)-1:
		print(A[i]),
	else:
		print(A[i])

Submission status: Runtime Error

Solution code:
n = int(raw_input())

A = []
for i in range(n):
	com = raw_input().split()
	if com[0][0] == "i": #com[0] == "insert"
		A.insert(0, int(com[1]))
	elif com[0][6] == " ": #com[0] == "delete"
		if int(com[1]) in A:
			index = A.index(int(com[1]))
			del A[index]
	elif com[0][6] == "F": #com[0] == "deleteFirst"
		del A[0]
	else:
		del A[-1]

for i in range(len(A)):
	if i != len(A)-1:
		print(A[i]),
	else:
		print(A[i])

Submission status: Runtime Error

Solution code:
from collections import deque

def insert(linked, x):
    if x not in linked:
        linked.appendleft(x)
        return linked


def delete(linked, x):
    if x in linked:
        linked.remove(x)
        return linked


def deleteFirst(linked):
    del linked[0]
    return linked


def deleteLast(linked):
    del linked[-1]
    return linked



orders = deque([])
n = int(input())

for i in range(n):
    orders.append(list(input().split()))

linked = deque([])

for o in orders:
    order = o[0]
    if order == 'insert':
        insert(linked, o[1])
    elif order == 'delete':
        delete(linked, o[1])
    elif order == 'deleteFirst':
        deleteFirst(linked)
    elif order == 'deleteLast':
        deleteLast(linked)

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

Submission status: Runtime Error

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

print(" ".join(x))

Submission status: Runtime Error

Solution code:
n = int(input())
dlist = []
for i in range(n):
    code = input().split()
    if code[0] == "insert":
        dlist.insert(0,code[1])
    if code[0] == "delete":
        dlist.remove(code[1])
    if code[0] == "deleteFirst":
        dlist.pop(0)
    if code[0] == "deleteLast":
        dlist.pop()
print(*dlist,sep=" ")

Submission status: Runtime Error

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

class Node(object):
    def __init__(self, key, prev=None, nex=None):
        self.key = key
        self.prev = prev
        self.next = nex
    
class DoublyLinkedLiset(object):
    def __init__(self):
        self.nil = Node(None)
        self.nil.next = self.nil
        self.nil.prev = self.nil
    
    def insert(self, x):
        X = Node(x)
        X.next = self.nil.next
        self.nil.next.prev = X
        self.nil.next = X
        X.prev = self.nil

    def listSearch(self, x):
        cur = self.nil.next
        while (cur != self.nil and cur.key != key):
            cur = cur.next
        
        return cur

    def deleteNode(self, X):
        if X == self.nil:
            return
        X.prev.next = X.next
        X.next.prev = X.prev
        #del X

    def deleteFirst(self):
        self.deleteNode(self.nil.next)

    def deleteLast(self):
        self.deleteNode(self.nil.prev)

    def deleteKey(self, x):
        self.deleteNode(self.listSearch(x))

    def printList(self):
        cur = self.nil.next
        ret = []
        
        while cur.key is not None:
            ret.append(cur.key)
            cur = cur.next
  
        print(' '.join(ret))

if __name__ == '__main__':

    n = int(input())
    dll = DoublyLinkedLiset()

    for i in range(n):
        command = input().split(" ")
        if command[0] == "insert":
            dll.insert(command[1])
        elif command[0] == "delete":
            dll.deleteKey(command[1])
        elif command[0] == "deleteFirst":
            dll.deleteFirst()
        elif command[0] == "deleteLast":
            dll.deleteLast()

    dll.printList()

Submission status: Runtime Error

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

from collections import deque

if __name__ == '__main__':
    n = int(input())
    L = deque()

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

    print(" ".join(L))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
class Node(object):
    def __init__(self, num, prev = None, nxt = None):
        self.num = num;
        self.prev = prev;
        self.nxt = nxt;

class Double_Linked_List(object):
    def __init__(self):
        self.first = self.last = None;

    def insert(self, num):
        node = Node(num);
        first = self.first;
        if first is not None:
            first.prev = node;
            node.nxt = first;
            self.first = node;
        else:
            self.first = node;
            self.last = node;

    def delete(self, num):
        current = self.first;
        while current is not None:
            if current.num == num:
                prev = current.prev;
                nxt = current.nxt;
                if prev is not None:
                    current.prev = None;
                    prev.nxt = nxt;
                if nxt is not None:
                    current.nxt = None;
                    nxt.prev = prev;
                if nxt is None:
                    self.last = prev;
                if prev is None:
                    self.first = nxt;
                break;
            else:
                current = current.nxt;

    def delete_first(self):
        first = self.first;
        if first is not None:
            nxt = first.nxt;
            if nxt is not None:
                self.first = nxt;
                nxt.prev = None;
                first.nxt = None;
            else:
                self.first = None;
                self.last = None;

    def delete_last(self):
        last = self.last;
        if last is not None:
            prev = last.prev;
            if prev is not None:
                prev.nxt = None;
                last.prev = None;
                self.last = prev;
            else:
                self.first = None;
                self.last = None;

    def get_content(self):
        ret = [];
        append = ret.append;
        current = self.first;
        while current is not None:
            append(current.num);
            current = current.nxt;
        return " ".join(ret);

def main():
    double_linked_list = Double_Linked_List();
    count = int(input());
    delete_first = double_linked_list.delete_first;
    delete_last = double_linked_list.delete_last;
    delete = double_linked_list.delete;
    insert = double_linked_list.insert;
    for i in xrange(count):
        command = input().split();
        command_name = command[0];

        if command_name == "insert":
            num = command[1];
            insert(num);
        if command_name == "delete":
            num = command[1];
            delete(num);
        elif command_name == "deleteFirst":
            delete_first();
        elif command_name == "deleteLast":
            delete_last();
    print(double_linked_list.get_content());

main();

Submission status: Runtime Error

Solution code:
from collections import deque

n=int(input())
command=[0 for i in range(n)]
k=[0 for i in range(n)]
k_queue= deque([])

for i in range(n):
    s=input()
    if s=="deleteFirst" or s=="deleteLast":
        command[i],k[i]=s,0
    else:
        command[i],k[i]=s.split()
    
    if command[i]=="insert":
        k_queue.appendleft(k[i])
    elif command[i]=="deleteFirst":
        k_queue.popleft()
    elif command[i]=="deleteLast":
        k_queue.pop()
    else:
        k_queue.remove(k[i])

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

Submission status: Runtime Error

Solution code:
import collections

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

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


#executing commands
output = collections.deque()
for command in commands:
    pair = command.split()
    if len(pair) < 2:
        if pair[0] == "deleteFirst":
            output.pop(0)
        else:
            output.pop()
        continue

    command = pair[0]
    num = pair[1]

    if command == "insert":
        output.appendleft(num)
    else: #delete
        try:
            output.remove(num)
        except:
            pass

Submission status: Runtime Error

Solution code:
# coding: UTF-8
from collections import deque

dll = deque()

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

print(" ".join(dll))

Submission status: Runtime Error

Solution code:
n = int(input())
L = []
i = 0
while i < n:
    s = list(map(str, input().split(' ')))
    if s[0] == 'insert':
        L.insert(0, int(s[1]))
    elif s[0] == 'delete':
        L.remove(int(s[1]))
    elif s[0] == 'deleteFirst':
        del L[0]
    elif s[0] == 'deleteLast':
        del L[-1]
    i += 1
print(' '.join(map(str, L)))

Submission status: Runtime Error

Solution code:

import sys
#import numpy as np
import copy

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

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

for i in range(len(list)):
    print( (str)(list[i]) + " ", end="")
print()

Submission status: Runtime Error

Solution code:

import sys
#import numpy as np
import copy

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

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

for i in range(len(list)):
    print( (str)(list[i]) + " ", end="")
print()

Submission status: Runtime Error

Solution code:

import sys
#import numpy as np
from collections import deque
#import collections

N = int(input())


list = deque()

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

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


u"""
list = []

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

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

Submission status: Runtime Error

Solution code:

import sys
#import numpy as np
from collections import deque
#import collections

N = int(input())


list = deque()

for i in range(N):
    # insert, delete, deleteFirst, deleteLast
    line = input().rstrip().split(' ')
    if line[0][0]=='i':
        #list.append((int)(line[1]))
        list.appendleft((int)(line[1]))
    else
        if len(line[0])<7:
            try:
                list.remove((int)(line[1]))
            except ValueError:
                pass
        elif line[0][6]=='F':
            list.popleft()
        elif line[0][6]=='L':
            list.pop()

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


u"""
list = []

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

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

Submission status: Runtime Error

Solution code:
import sys

class ListElement:
    def __init__(self,num):
        self.num = num
        self.next = self.prev = None

class doubleLinkedList:
    def __init__(self):
        self.list = None
    def insert(self,num):
        temp = ListElement(num)
        temp.next = self.list
        self.list = temp
    def delFirst(self):
        if self.list is None:
            return
        temp = self.list
        self.list = temp.next
        del(temp)
    def recDel(self,List):
        if List.next.next is None:
            temp = List.next
            List.next = None
            temp.prev = None
            del(temp)
            return
        self.recDel(List.next)
    def delLast(self):
        if self.list is None:
            return
        elif self.list.next is None:
            self.delFirst()
            return
        self.recDel(self.list)
    def recList(self,List,num):
        if List is None:
            return
        elif List.next is not None and List.next.num == num:
            temp = List.next
            List.next = temp.next
            temp.prev = temp.next = None
            del(temp)
            return
        self.recList(List.next,num)
    def delete(self,num):
        if self.list is None:
            return
        elif self.list.num == num:
            self.delFirst()
            return
        self.recList(self.list,num)
    def recPrint(self,List):
        if List is None:
            print()
            return
        print(List.num,end='')
        if List.next is not None:
            print(" ",end='')
        self.recPrint(List.next)
    def printList(self):
        self.recPrint(self.list)

l = []
for i in sys.stdin:
    l.append(i.split())

res = doubleLinkedList()
for i in range(1,len(l)):
    if l[i][0] == 'insert':
        res.insert(l[i][1])
    elif l[i][0] == 'delete':
        res.delete(l[i][1])
    elif l[i][0] == 'deleteFirst':
        res.delFirst()
    elif l[i][0] == 'deleteLast':
        res.delLast()
res.printList()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from collections import deque

n = int(input())
result = deque()
func = {'insert':result.appendleft,\
        'delete':result.remove,\
        'deleteFirst':result.popleft,\
        'deleteLast':result.pop}

for i in range(n):
    c = input().split()
    if len(c) > 1:
        func[c[0]](int(c[1]))
    else:
        func[c[0]]()

print(*result)

Submission status: Runtime Error

Solution code:
n, q = map(int, input().split())
l = []
for i in range(n):
  t = []
  for j in input().split():
    t += [j]
  t[1] = int(t[1])
  l += [t]
 
c = 0
while len(l) > 0:
  if l[0][1] > q:
    l[0][1] -= q
    l += [l[0]]
    l.pop(0)
    c += q
  else:
    c += l[0][1]
    print(l[0][0], c)
    l.pop(0)

Submission status: Runtime Error

Solution code:
n = int(input())
a = []
for i in range(n):
    c = input()
    if c == "deleteFirst":
        a.pop(0)
    elif c == "deleteLast":
        a.pop()
    else:
        c, v = c.split()
        v = int(v)
        if c == "insert":
            a.insert(0, v)
        else:
            a.remove(v)
print(" ".join(map(str, a)))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 29 18:31:35 2018
ALDS1-3c simple implementation owing to the feature of python.
@author: maezawa
"""

a = []
n = int(input())
for i in range(n):
    com, key = input().split()
    if com == 'insert':
        a.insert(0, key)
    elif com == 'delete':
        a.remove(key)
    elif com == 'deleteFirst':
        a.pop(0)
    elif com == 'deleteLast':
        a.pop(-1)

print(a)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 29 18:31:35 2018
ALDS1-3c simple implementation owing to the feature of python.
@author: maezawa
"""
def print_array(g):
    ans = str(g[0])
    if len(g) > 1:
        for i in range(1,len(g)):
            ans += ' '+str(g[i]) 
    print(ans)

a = []
n = int(input())
for i in range(n):
    s = input().split()
    if len(s) == 2:
        key = s[1]
    com = s[0]
         
    if com == 'insert':
        a.insert(0, key)
    elif com == 'delete':
        a.remove(key)
    elif com == 'deleteFirst':
        a.pop(0)
    elif com == 'deleteLast':
        a.pop(-1)

print_array(a)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 29 18:31:35 2018
ALDS1-3c simple implementation owing to the feature of python.
@author: maezawa
"""
from sys import stdin

def print_array(g):
    ans = str(g[0])
    if len(g) > 1:
        for i in range(1,len(g)):
            ans += ' '+str(g[i]) 
    print(ans)

a = []
n = int(input())
sin = stdin.readlines()
for i in range(n):
    s = sin[i].plit()
    #s = input().split()
    if len(s) == 2:
        key = int(s[1])
    com = s[0]
         
    if com == 'insert':
        a.insert(0, key)
    elif com == 'deleteFirst':
        a.pop(0)
    elif com == 'deleteLast':
        a.pop(-1)
    elif com == 'delete':
        try:
            a.remove(key)
        except ValueError:
            pass

print_array(a)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 29 18:31:35 2018
ALDS1-3c simple implementation owing to the feature of python.
@author: maezawa
"""
from sys

def print_array(g):
    ans = str(g[0])
    if len(g) > 1:
        for i in range(1,len(g)):
            ans += ' '+str(g[i]) 
    sys.stdout.write(ans)

a = []
n = int(input())
s_in = sys.stdin.readlines()
for i in range(n):
    s = s_in[i].split()
    #s = input().split()
    #if len(s) == 2:
    #    key = int(s[1])
    com = s[0]
         
    if com == 'insert':
        key = int(s[1])
        a.insert(0, key)
    elif com == 'deleteFirst':
        a.pop(0)
    elif com == 'deleteLast':
        a.pop(-1)
    elif com == 'delete':
        key = int(s[1])
        try:
            a.remove(key)
        except ValueError:
            pass

print_array(a)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 29 18:31:35 2018
ALDS1-3c simple implementation owing to the feature of python.
@author: maezawa
"""
import sys

def print_array(g):
    sys.stdout.write(g[0])
    if len(g) > 1:
        for i in range(1,len(g)):
            sys.stdout.write(' '+str(g[i])) 
    sys.stdout.write(\n)

a = []
n = int(input())
s_in = sys.stdin.readlines()
for i in range(n):
    s = s_in[i].split()
    #s = input().split()
    #if len(s) == 2:
    #    key = int(s[1])
    com = s[0]
         
    if com == 'insert':
        key = int(s[1])
        a.insert(0, key)
    elif com == 'deleteFirst':
        a.pop(0)
    elif com == 'deleteLast':
        a.pop(-1)
    elif com == 'delete':
        key = int(s[1])
        try:
            a.remove(key)
        except ValueError:
            pass

print_array(a)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 29 18:31:35 2018
ALDS1-3c simple implementation owing to the feature of python.
@author: maezawa
"""
import sys

def print_array(g):
    sys.stdout.write(g[0])
    if len(g) > 1:
        for i in range(1,len(g)):
            sys.stdout.write(' '+str(g[i])) 
    sys.stdout.write('\n')

a = []
n = int(input())
s_in = sys.stdin.readlines()
for i in range(n):
    s = s_in[i].split()
    #s = input().split()
    #if len(s) == 2:
    #    key = int(s[1])
    com = s[0]
         
    if com == 'insert':
        key = int(s[1])
        a.insert(0, key)
    elif com == 'deleteFirst':
        a.pop(0)
    elif com == 'deleteLast':
        a.pop(-1)
    elif com == 'delete':
        key = int(s[1])
        try:
            a.remove(key)
        except ValueError:
            pass

print_array(a)

Submission status: Runtime Error

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

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

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

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

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