Buggy python submission (verdict: Time Limit Exceeded):
class Node():
    def __init__(self, key, prev=None, next=None):
        self.key = key
        self.prev = prev
        self.next = next

class link():
    def __init__(self):
        self.node = Node(None)
        self.node.prev = self.node.next = self.node

    def insert(self, key):
        elem = Node(key, self.node, self.node.next)
        self.node.next.prev = elem
        self.node.next = elem

    def search(self, key):
        elem = self.node.next
        while (elem != self.node) and (elem.key != key):
            elem = elem.next
        return elem

    def delete(self, node):
        if node == self.node:
            return None
        node.prev.next = node.next
        node.next.prev = node.prev

    def deleteFirst(self):
        self.delete(self.node.next)

    def deleteLast(self):
        self.delete(self.node.prev)

    def show_keys(self):
        keys = []
        elem = self.node.next
        while elem != self.node:
            keys.append(str(elem.key))
            elem = elem.next
        print(' '.join(keys))

n = int(input())
linkedlist = link()
for i in range(n):
    com = input().split()
    if com[0] == 'insert':
        linkedlist.insert(int(com[1]))
    elif com[0] == 'delete':
        linkedlist.delete(linkedlist.search(int(com[1])))
    elif com[0] == 'deleteFirst':
        linkedlist.deleteFirst()
    else:
        linkedlist.deleteLast()
linkedlist.show_keys()


Fixed submission:
from collections import deque

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

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

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


Fixed submission:
from collections import deque

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

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

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


Fixed submission:
from collections import deque

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