Buggy python submission (verdict: Runtime Error):
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 delete_leaf(p,x):
    if left(p,x):
        p['left'] = None
    else:
        p['right'] = None
    return p

def delete_half_leaf(p,x,y):
    if left(p,x):
        p['left'] = y
    else:
        p['right'] = y
    y['parent'] = p
    return p


def left(p,x):
    if p['left'] != None and p['left']['key'] == x['key']:
        return True
    else:
        return False

def delete_internal(p,x):
    y = x['right']
    while y['left'] != None:
        y = y['left']
    x['key'] = y['key']
    if y['right'] == None:
        tree = delete_leaf(tree,y['parent'],y)
    else:
        tree = delete_half_leaf(tree,y['parent'],y,y['left'])
    return p

def delete(tree,k):
    x = find(tree,k)
    if x == None: return
    p = x['parent']
    if p == None:
        pass
    else:
        if x['left'] == x['right'] == None:
            p = delete_leaf(p,x)
        elif x['right'] == None:
            p = delete_half_leaf(p,x,x['left'])
        elif x['left'] == None:
            p = delete_half_leaf(p,x,x['right'])
        else:
            p = delete_internal(p,x)
    return tree

def find(tree,k):
    x = tree
    while x != None:
        if x['key'] == k:
            return x
        elif x['key'] > k:
            x = x['left']
        else:
            x = x['right']
    return None

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] == 'f':
        x = find(tree, int(c[5:]))
        if x == None:
            print "no"
        else:
            print "yes"
    elif c[0] == 'd':
        tree = delete(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 get_successor(x):
    if x['right'] != None:
        return get_minimum(x['right'])
    else:
        y = x['parent']
        while y != None and x == y['left']:
            x = y
            y = y['parent']
        return y

def get_minimum(x):
    while x['left'] != None:
        x = x['left']
    return x

def delete_node(tree,z):
    if z['left'] == None or z['right'] == None:
        y = z
    else:
        y = get_successor(z)

    if y['left'] != None:
        x = y['left']
    else:
        x = y['right']

    if x != None:
        x['parent'] = y['parent']

    if y['parent'] == None:
        tree = x
    else:
        if y['parent']['left'] != None and y['parent']['left']['key'] == y['key']:
            y['parent']['left'] = x
        else:
            y['parent']['right'] = x

    z['key'] = y['key']

    return tree

def find(tree,k):
    x = tree
    while x != None:
        if x['key'] == k:
            return x
        elif x['key'] > k:
            x = x['left']
        else:
            x = x['right']
    return None

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] == 'f':
        x = find(tree, int(c[5:]))
        if x == None:
            print "no"
        else:
            print "yes"
    elif c[0] == 'd':
        z = find(tree, int(c[7:]))
        if not z == None: tree = delete_node(tree,z)
    elif c[0] == 'p':
        print '',
        middleorder(tree)
        print
        print '',
        preorder(tree)
        print

Buggy python submission (verdict: Runtime Error):
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 get_successor(x):
    if x['right'] != None:
        return get_minimum(x['right'])
    else:
        y = x['parent']
        while y != None and x == y['left']:
            x = y
            y = y['parent']
        return y

def get_minimum(x):
    while x['left'] != None:
        x = x['left']
    return x

def delete_node(tree,z):
    if z['left'] == None or z['right'] == None:
        y = z
    else:
        y = get_successor(z)

    if y['left'] != None:
        x = y['left']
    else:
        x = y['right']

    if x != None:
        x['parent'] = y['parent']

    if y['parent'] == None:
        tree = x
    else:
        if y['parent']['left']['key'] == y['key']:
            y['parent']['left'] = x
        else:
            y['parent']['right'] = x

    z['key'] = y['key']

    return tree

def find(tree,k):
    x = tree
    while x != None:
        if x['key'] == k:
            return x
        elif x['key'] > k:
            x = x['left']
        else:
            x = x['right']
    return None

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] == 'f':
        x = find(tree, int(c[5:]))
        if x == None:
            print "no"
        else:
            print "yes"
    elif c[0] == 'd':
        z = find(tree, int(c[7:]))
        if not z == None: tree = delete_node(tree,z)
    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 get_successor(x):
    if x['right'] != None:
        return get_minimum(x['right'])
    else:
        y = x['parent']
        while y != None and x == y['left']:
            x = y
            y = y['parent']
        return y

def get_minimum(x):
    while x['left'] != None:
        x = x['left']
    return x

def delete_node(tree,z):
    if z['left'] == None or z['right'] == None:
        y = z
    else:
        y = get_successor(z)

    if y['left'] != None:
        x = y['left']
    else:
        x = y['right']

    if x != None:
        x['parent'] = y['parent']

    if y['parent'] == None:
        tree = x
    else:
        if y['parent']['left'] != None and y['parent']['left']['key'] == y['key']:
            y['parent']['left'] = x
        else:
            y['parent']['right'] = x

    z['key'] = y['key']

    return tree

def find(tree,k):
    x = tree
    while x != None:
        if x['key'] == k:
            return x
        elif x['key'] > k:
            x = x['left']
        else:
            x = x['right']
    return None

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] == 'f':
        x = find(tree, int(c[5:]))
        if x == None:
            print "no"
        else:
            print "yes"
    elif c[0] == 'd':
        z = find(tree, int(c[7:]))
        if not z == None: tree = delete_node(tree,z)
    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 find(self,v):
        x = self.root
        while x != None:
            if x.v == v:
                return x
            elif x.v < v:
                x = x.right
            else:
                x = x.left
        return None

    def delete(self,v):
        x = self.root
        y = None
        while x != None:
            if x.v == v:
                break
            elif x.v < v:
                y = x
                x = x.right
            else:
                y = x
                x = x.left
        if x != None:
            if x.left != None and x.right != None:
                z = x.right
                w = x
                while z.left != None:
                    w = z
                    z = z.left
                x.v = z.v
                if w.left == z:
                    w.left = z.right
                else:
                    w.right = z.right
            else:
                z = x.left
                if z == None:
                    z = x.right
                if y.left == x:
                    y.left = z
                else:
                    y.right = z


    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)
    elif op[0] == 'f':
        num = op.split(' ')[1]
        num = int(num)
        if tree.find(num):
            print 'yes'
        else:
            print 'no'
    elif op[0] == 'd':
        num = op.split(' ')[1]
        num = int(num)
        tree.delete(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 get_successor(x):
    if x['right'] != None:
        return get_minimum(x['right'])
    else:
        y = x['parent']
        while y != None and x == y['left']:
            x = y
            y = y['parent']
        return y

def get_minimum(x):
    while x['left'] != None:
        x = x['left']
    return x

def delete_node(tree,z):
    if z['left'] == None or z['right'] == None:
        y = z
    else:
        y = get_successor(z)

    if y['left'] != None:
        x = y['left']
    else:
        x = y['right']

    if x != None:
        x['parent'] = y['parent']

    if y['parent'] == None:
        tree = x
    else:
        if y['parent']['left'] != None and y['parent']['left']['key'] == y['key']:
            y['parent']['left'] = x
        else:
            y['parent']['right'] = x

    z['key'] = y['key']

    return tree

def find(tree,k):
    x = tree
    while x != None:
        if x['key'] == k:
            return x
        elif x['key'] > k:
            x = x['left']
        else:
            x = x['right']
    return None

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] == 'f':
        x = find(tree, int(c[5:]))
        if x == None:
            print "no"
        else:
            print "yes"
    elif c[0] == 'd':
        z = find(tree, int(c[7:]))
        if not z == None: tree = delete_node(tree,z)
    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.parent = None
        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)
            return
        cur = self.root
        while True:
            if cur.value > x:
                if cur.left == None:
                    cur.left = Node(x)
                    cur.left.parent = cur
                    break
                cur = cur.left
            elif cur.value < x:
                if cur.right == None:
                    cur.right = Node(x)
                    cur.right.parent = cur
                    break
                cur = cur.right
            else:
                break

    def find(self,x):
        cur = self.root
        if cur == None:
            return None
        while True:
            if cur.value > x:
                if cur.left != None:
                    cur = cur.left
                else:
                    return None
            elif cur.value < x:
                if cur.right != None:
                    cur = cur.right
                else:
                    return None
            else:
                return cur

    def delete(self, x):
        n = self.find(x)
        if n == None:
            return
        else:
            self.delete_node(n)

    def delete_node(self, n):
        if n.left == None and n.right == None:
            if n.parent.left == n:
                n.parent.left = None
            elif n.parent.right == n:
                n.parent.right = None
        elif n.left == None:
            if n.parent.left == n:
                n.parent.left = n.right
                n.right.parent = n.parent
            elif n.parent.right == n:
                n.parent.right = n.right
                n.right.parent = n.parent
        elif n.right == None:
            if n.parent.left == n:
                n.parent.left = n.left
                n.left.parent = n.parent
            elif n.parent.right == n:
                n.parent.right = n.left
                n.left.parent = n.parent
        else:
            next_n = self.find_next(n)
            n.value = next_n.value
            self.delete_node(next_n)

    def find_next(self, n):
        x = n.right # always exists
        while x.left != None:
            x = x.left
        return x




    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()
commands = []
for _ in range(m):
    line = raw_input()
    if line[0] == 'i':
        num = int(line.split(' ')[1])
        commands.append(('insert', num))
    elif line[0] == 'p':
        commands.append(('print', '-1'))
    elif line[0] == 'f':
        num = int(line.split(' ')[1])
        commands.append(('find', num))
    elif line[0] == 'd':
        num = int(line.split(' ')[1])
        commands.append(('delete', num))
    else:
        raise Exception("Unknown command")

for cmd, num in commands:
    if cmd == 'insert':
        tree.insert(num)
    elif cmd == 'print':
        tree.mprint()
    elif cmd == 'find':
        if tree.find(num):
            print 'yes'
        else:
            print 'no'
    elif cmd == 'delete':
        tree.delete(num)

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 get_successor(x):
    if x['right'] != None:
        return get_minimum(x['right'])
    else:
        y = x['parent']
        while y != None and x == y['left']:
            x = y
            y = y['parent']
        return y

def get_minimum(x):
    while x['left'] != None:
        x = x['left']
    return x

def delete_node(tree,z):
    if z['left'] == None or z['right'] == None:
        y = z
    else:
        y = get_successor(z)

    if y['left'] != None:
        x = y['left']
    else:
        x = y['right']

    if x != None:
        x['parent'] = y['parent']

    if y['parent'] == None:
        tree = x
    else:
        if y['parent']['left'] != None and y['parent']['left']['key'] == y['key']:
            y['parent']['left'] = x
        else:
            y['parent']['right'] = x

    z['key'] = y['key']

    return tree

def find(tree,k):
    x = tree
    while x != None:
        if x['key'] == k:
            return x
        elif x['key'] > k:
            x = x['left']
        else:
            x = x['right']
    return None

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] == 'f':
        x = find(tree, int(c[5:]))
        if x == None:
            print "no"
        else:
            print "yes"
    elif c[0] == 'd':
        z = find(tree, int(c[7:]))
        if not z == None: tree = delete_node(tree,z)
    elif c[0] == 'p':
        print '',
        middleorder(tree)
        print
        print '',
        preorder(tree)
        print