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: Memory Limit Exceeded

Solution code:
import time

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

class MyDLL:
    def __init__(self):
        self.linkedlist = []
        self.length = 0
    
    def isEmpty(self):
        if self.length==0:
            return True
        return False
    
    def insert(self, x):
        # 連結リストの先頭にキー x を持つ要素を継ぎ足す。
        if self.isEmpty():
            # 連結リストが空の時
            new = Node(x, None, None)
            self.linkedlist.insert(0, new)         
        else:
            # 連結リストが空ではない時
            old = self.linkedlist[0] # 今まで先頭にいたノード
            new = Node(x, None, old) # 新しく先頭になるノード
            old.prev = new           # 今まで先頭にいたノードの前に新しいノードを登録
            self.linkedlist.insert(0, new)
        self.length += 1 # 連結リストの長さを更新

    def delete(self, x):
        # キー x を持つ最初の要素を連結リストから削除する。そのような要素が存在しない場合は何もしない。
        for node in self.linkedlist:
            if node.key==x:# キー x を持つ最初の要素    
                if node.prev is None:# 先頭だった時
                    node.next.prev = None # 次の要素の前の要素をNoneにする
                elif node.next is None:# 最後尾だった時
                    node.prev.next = None
                else:# 途中だった時
                    prev_node = node.prev
                    next_node = node.next
                    prev_node.next = next_node
                    next_node.prev = prev_node
                self.linkedlist.remove(node)# listから削除 
                self.length -= 1     
                break # キーxを持つ最初だけで良いのでbreak
        
    def deleteFirst(self):
        # リストの先頭の要素を削除する。
        if not self.isEmpty():
            first = self.linkedlist.pop(0)
            if self.length>1:
                first.next.prev = None
            self.length -= 1 
        else:
            print("List is empty")
        
    def deleteLast(self):
        # リストの末尾の要素を削除する。        
        if not self.isEmpty():
            last = self.linkedlist.pop()
            if self.length>1:
                last.prev.next = None
            self.length -= 1 
        else:
            print("List is empty")
        


def main():
    n = int(input())
    commands = [input().split() for i in range(n)]
    commands = [{'order': c[0], 'value': c[1]} if len(c)==2 else {'order': c[0]} for c in commands]
    dll = MyDLL()
    for c in commands:        
        if c['order']=='insert':
            dll.insert(c['value'])
        elif c['order']=='delete':
            dll.delete(c['value'])
        elif c['order']=='deleteFirst':
            dll.deleteFirst()
        elif c['order']=='deleteLast':
            dll.deleteLast()
        else:
            print("the command dont't exist")
    print(' '.join([node.key for node in dll.linkedlist]))


if __name__=='__main__':
    # start = time.time()
    main()
    # elapsed_time = time.time() - start
    # print ("elapsed_time:{0}".format(elapsed_time) + "[sec]")

Submission status: Memory Limit Exceeded

Solution code:
class DoublyLinkedList:
    def __init__(self):
        self.nil = self.make_node(None)
        self.nil['next'] = self.nil
        self.nil['prev'] = self.nil

    def make_node(self,v):
        return {'key':v, 'next':None, 'prev':None}

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


    def insert(self,v):
        n = self.make_node(v)
        n['next'] = self.nil['next']
        self.nil['next']['prev'] = n
        n['prev'] = self.nil
        self.nil['next'] = n

    def delete(self,v):
        self.delete_node(self.list_search(v))

    def delete_node(self,n):
        n['next']['prev'] = n['prev']
        n['prev']['next'] = n['next']

    def list_search(self,v):
        cur = self.nil['next']
        while (cur['key'] != None) and (cur['key'] != v):
            cur = cur['next']
        return cur

    def deleteFirst(self):
        self.delete_node(self.nil['next'])

    def deleteLast(self):
        self.delete_node(self.nil['prev'])

n = int(raw_input())

l = DoublyLinkedList()
for i in range(n):
    c = raw_input()
    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: Memory Limit Exceeded

Solution code:
MAX_N = 2000000


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: Memory Limit Exceeded

Solution code:
MAX_N = 1000002


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: Memory Limit Exceeded

Solution code:
MAX_N = 1500001


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: Memory Limit Exceeded

Solution code:
MAX_N = 1250001


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: Memory Limit Exceeded

Solution code:
MAX_N = 11250001


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: Memory Limit Exceeded

Solution code:
MAX_N = 11000001


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: Memory Limit Exceeded

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[0] == "deleteFirst":
            a.popleft()
        else:
            a.pop()

    #insert,delete
    else:
        if task[0] == "insert":
            a.appendleft(task[1])
        elif task[1] in a:
            a.remove(task[1])

print(*a)

Submission status: Memory Limit Exceeded

Solution code:
# encoding: utf-8

import sys
from collections import deque


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

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


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

Submission status: Memory Limit Exceeded

Solution code:
# encoding: utf-8

import sys
from collections import deque


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

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


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

Submission status: Memory Limit Exceeded

Solution code:
# encoding: utf-8

import sys
from collections import deque


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

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


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

Submission status: Memory Limit Exceeded

Solution code:
# encoding: utf-8

import sys
from collections import deque


class Solution:
    @staticmethod
    def doubly_linked_list():
        # write your code here
        array_length = int(input())
        _input = sys.stdin.readlines()
        task_list = list(map(lambda x: dict(action=x.split()[0], value=x.split()[-1]), _input))
        assert len(task_list) == array_length
        task_deque = deque()

        for i in range(array_length):
            task = task_list[i]
            action = task.get('action')
            value = task.get('value')
            if action == 'insert':
                task_deque.appendleft(value)
            elif action == 'deleteFirst':
                task_deque.popleft()
            elif action == 'deleteLast':
                task_deque.pop()
            elif action == 'delete':
                try:
                    task_deque.remove(value)
                except Exception as e:
                    pass
        print(" ".join(map(str, task_deque)))
        assert len(task_deque) <= array_length


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

Submission status: Memory Limit Exceeded

Solution code:
# encoding: utf-8

import sys
from collections import deque


class Solution:
    @staticmethod
    def doubly_linked_list():
        # write your code here
        array_length = int(input())
        _input = sys.stdin.readlines()
        task_list = list(map(lambda x: dict(action=x.split()[0], value=x.split()[-1]), _input))
        task_deque = deque()

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


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

Submission status: Memory Limit Exceeded

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

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

def insert(front, target):

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

    return target
    
def delete(front, target):

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

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

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

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

Submission status: Memory Limit Exceeded

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

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

def insert(front, target):

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

    return target
    
def delete(front, target):

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

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

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

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