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

def insert(tree,k):
    y = None
    x = tree
    z = Node(k)
    while x != None:
        y = x
        if x.key > k:
            x = x.left
        else:
            x = x.right
    z.p = y
    if y == None:
        tree = z
    elif y.key > k:
        y.left = z
    else:
        y.right = z
    return tree

def middleorder(x):
    if x != None:
        middleorder(x.left)
        print x.key,
        middleorder(x.right)

def preorder(x):
    if x != None:
        print x.key,
        preorder(x.left)
        preorder(x.right)



tree = None
m = int(raw_input())
for i in range(m):
    c = raw_input().strip()
    if c[0] == 'i':
        tree = insert(tree, int(c[7:]))
    elif c[0] == 'p':
        print '',
        middleorder(tree)
        print
        print '',
        preorder(tree)
        print

Fixed submission:
def insert(tree,k):
    y = None
    x = tree
    z = {'key':k, 'parent':None, 'left':None, 'right':None}
    while x != None:
        y = x
        if x['key'] > k:
            x = x['left']
        else:
            x = x['right']
    z['parent'] = y
    if y == None:
        tree = z
    elif y['key'] > k:
        y['left'] = z
    else:
        y['right'] = z
    return tree

def middleorder(x):
    if x != None:
        middleorder(x['left'])
        print x['key'],
        middleorder(x['right'])

def preorder(x):
    if x != None:
        print x['key'],
        preorder(x['left'])
        preorder(x['right'])



tree = None
m = int(raw_input())
for i in range(m):
    c = raw_input().strip()
    if c[0] == 'i':
        tree = insert(tree, int(c[7:]))
    elif c[0] == 'p':
        print '',
        middleorder(tree)
        print
        print '',
        preorder(tree)
        print

Buggy python submission (verdict: Time Limit Exceeded):
class Node:
    def __init__(self,v):
        self.v = v
        self.left = None
        self.right = None

def inorder(n):
    if n != None:
        inorder(n.left)
        print n.v,
        inorder(n.right)

def preorder(n):
    if n != None:
        print n.v,
        preorder(n.left)
        preorder(n.right)

class BST:
    def __init__(self):
        self.root = None

    def insert(self,v):
        n = Node(v)
        x = self.root
        y = None
        while x != None:
            y = x
            if x.v > v:
                x = x.left
            else:
                x = x.right
        if y == None:
            self.root = n
        else:
            if y.v > v:
                y.left = n
            else:
                y.right = n
    def print_tree(self):
        print '',
        inorder(self.root)
        print
        print '',
        preorder(self.root)
        print


n = int(raw_input())
ops = []
for _ in range(n):
    ops.append(raw_input())

tree = BST()
for op in ops:
    if op[0] == 'i':
        num = op.split(' ')[1]
        num = int(num)
        tree.insert(num)
    else:
        tree.print_tree()

Fixed submission:
def insert(tree,k):
    y = None
    x = tree
    z = {'key':k, 'parent':None, 'left':None, 'right':None}
    while x != None:
        y = x
        if x['key'] > k:
            x = x['left']
        else:
            x = x['right']
    z['parent'] = y
    if y == None:
        tree = z
    elif y['key'] > k:
        y['left'] = z
    else:
        y['right'] = z
    return tree

def middleorder(x):
    if x != None:
        middleorder(x['left'])
        print x['key'],
        middleorder(x['right'])

def preorder(x):
    if x != None:
        print x['key'],
        preorder(x['left'])
        preorder(x['right'])



tree = None
m = int(raw_input())
for i in range(m):
    c = raw_input().strip()
    if c[0] == 'i':
        tree = insert(tree, int(c[7:]))
    elif c[0] == 'p':
        print '',
        middleorder(tree)
        print
        print '',
        preorder(tree)
        print

Buggy python submission (verdict: Time Limit Exceeded):
class Node:
    def __init__(self, value):
        self.value = value
        self.left = None
        self.right = None

class BST:
    def __init__(self):
        self.root = None

    def insert(self,x):
        if self.root == None:
            self.root = Node(x)
        cur = self.root
        while True:
            if cur.value > x:
                if cur.left == None:
                    cur.left = Node(x)
                    break
                cur = cur.left
            elif cur.value < x:
                if cur.right == None:
                    cur.right = Node(x)
                    break
                cur = cur.right
            else:
                break

    def mprint(self):
        print '',
        print ' '.join(map(str, self.inorder(self.root)))
        print '',
        print ' '.join(map(str, self.preorder(self.root)))

    def inorder(self, cur):
        ret = []
        if cur.left != None:
            ret += self.inorder(cur.left)
        ret.append(cur.value)
        if cur.right != None:
            ret += self.inorder(cur.right)
        return ret

    def preorder(self, cur):
        ret = []
        ret.append(cur.value)
        if cur.left != None:
            ret += self.preorder(cur.left)
        if cur.right != None:
            ret += self.preorder(cur.right)
        return ret



m = int(raw_input())
tree = BST()
for _ in range(m):
    line = raw_input()
    if line[0] == 'i':
        num = int(line.split(' ')[1])
        tree.insert(num)
    elif line[0] == 'p':
        tree.mprint()
    else:
        raise Exception("Unknown command")

Fixed submission:
def insert(tree,k):
    y = None
    x = tree
    z = {'key':k, 'parent':None, 'left':None, 'right':None}
    while x != None:
        y = x
        if x['key'] > k:
            x = x['left']
        else:
            x = x['right']
    z['parent'] = y
    if y == None:
        tree = z
    elif y['key'] > k:
        y['left'] = z
    else:
        y['right'] = z
    return tree

def middleorder(x):
    if x != None:
        middleorder(x['left'])
        print x['key'],
        middleorder(x['right'])

def preorder(x):
    if x != None:
        print x['key'],
        preorder(x['left'])
        preorder(x['right'])



tree = None
m = int(raw_input())
for i in range(m):
    c = raw_input().strip()
    if c[0] == 'i':
        tree = insert(tree, int(c[7:]))
    elif c[0] == 'p':
        print '',
        middleorder(tree)
        print
        print '',
        preorder(tree)
        print