Buggy python submission (verdict: Time Limit Exceeded):

from collections import deque
from enum import Enum, auto

class Color(Enum):
    WHITE = auto()
    GRAY = auto()
    BLACK = auto()

class BinaryTreeNode():
    def __init__(self, parent=None, left=None, right=None, val=None):
        self.parent = parent
        self.left = left
        self.right = right
        self.val = val
        self.color = Color.WHITE

class BinarySearchTree():
    def __init__(self, n):
        self.root = None
        self.nodes = deque([])
        self.num_nodes = n

    def set_root(self, val):
        node = BinaryTreeNode(val=val)
        self.root = len(self.nodes)
        self.nodes.append(node)

    def insert(self, val):
        y = None
        x = self.root
        while x != None:
            y = x
            if val < self.nodes[x].val:
                x = self.nodes[x].left
            else:
                x = self.nodes[x].right
        node = BinaryTreeNode(val=val, parent=y)

        if y == None:
            self.set_root(val)
        elif node.val < self.nodes[y].val:
            self.nodes[y].left = len(self.nodes)
            self.nodes.append(node)
        else:
            self.nodes[y].right = len(self.nodes)
            self.nodes.append(node)

    def init_color(self):
        for node in self.nodes:
            node.color = Color.WHITE

    def preorder(self):
        preordered = []
        self.init_color()
        def preorder_bfs(s):
            preordered.append(self.nodes[s].val)
            self.nodes[s].color = Color.GRAY
            if  self.nodes[s].left != None and self.nodes[self.nodes[s].left].color == Color.WHITE:
                preorder_bfs(self.nodes[s].left)
            if  self.nodes[s].right != None and self.nodes[self.nodes[s].right].color == Color.WHITE:
                preorder_bfs(self.nodes[s].right)
                self.nodes[s].color = Color.BLACK
        preorder_bfs(self.root)
        return preordered

    def inorder(self):
        inordered = []
        self.init_color()

        inorder_stack = deque([])
        def inorder_dfs_init(s):
            inorder_stack.append(s)
            inorder_dfs()

        def inorder_dfs():
            u = inorder_stack.pop()
            self.nodes[u].color = Color.GRAY
            if self.nodes[u].left != None and self.nodes[self.nodes[u].left].color == Color.WHITE:
                inorder_stack.append(u)
                inorder_stack.append(self.nodes[u].left)
                inorder_dfs()
            inordered.append(self.nodes[u].val)
            if self.nodes[u].right != None and self.nodes[self.nodes[u].right].color == Color.WHITE:
                inorder_stack.append(self.nodes[u].right)
                inorder_dfs()
            self.nodes[u].color = Color.BLACK

        inorder_dfs_init(self.root)
        return inordered

def print_elements(ordered):
    for ele in ordered:
        print(' {}'.format(ele), end='')
    print('')

m = int(input())
bst = BinarySearchTree(m)
for i in range(m):
    op = input()
    if op == 'print':
        print_elements(bst.inorder())
        print_elements(bst.preorder())
    else:
        num = int(op[7:])
        bst.insert(num)


Fixed submission:
class BinaryTreeNode():
    # __slots__ = ['left', 'right', 'val']
    def __init__(self, left=None, right=None, val=None):
        self.left = left
        self.right = right
        self.val = val

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

    def insert(self, val):
        y = None
        x = self.root
        while x != None:
            y = x
            if val < x.val:
                x = x.left
            else:
                x = x.right
        node = BinaryTreeNode(val=val)

        if y == None:
            self.root = node
        elif node.val < y.val:
            y.left = node
        else:
            y.right = node

    def preorder(self):
        self.preorder_list = []
        self.preorder_bfs(self.root)
        return self.preorder_list

    def preorder_bfs(self, u):
        if u == None: return
        self.preorder_list.append(u.val)
        self.preorder_bfs(u.left)
        self.preorder_bfs(u.right)

    def inorder(self):
        self.inorder_list = []
        self.inorder_dfs(self.root)
        return self.inorder_list

    def inorder_dfs(self, u):
        if u == None: return
        self.inorder_dfs(u.left)
        self.inorder_list.append(u.val)
        self.inorder_dfs(u.right)

def print_elements(arr):
    print(' ' + ' '.join([str(item) for item in arr]))

m = int(input())
bst = BinarySearchTree()
for i in range(m):
    op = input()
    if op == 'print':
        print_elements(bst.inorder())
        print_elements(bst.preorder())
    else:
        num = int(op[7:])
        bst.insert(num)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
from enum import Enum, auto

class Color(Enum):
    WHITE = auto()
    GRAY = auto()
    BLACK = auto()

class BinaryTreeNode():
    def __init__(self, parent=None, left=None, right=None, val=None):
        self.parent = parent
        self.left = left
        self.right = right
        self.val = val
        self.color = Color.WHITE

class BinarySearchTree():
    def __init__(self):
        self.root = None
        self.nodes = deque([])

    def set_root(self, val):
        node = BinaryTreeNode(val=val)
        self.root = len(self.nodes)
        self.nodes.append(node)

    def insert(self, val):
        y = None
        x = self.root
        while x != None:
            y = x
            if val < self.nodes[x].val:
                x = self.nodes[x].left
            else:
                x = self.nodes[x].right
        node = BinaryTreeNode(val=val, parent=y)

        if y == None:
            self.set_root(val)
        elif node.val < self.nodes[y].val:
            self.nodes[y].left = len(self.nodes)
            self.nodes.append(node)
        else:
            self.nodes[y].right = len(self.nodes)
            self.nodes.append(node)

    def find(self, val):
        x = self.root
        while x != None:
            if self.nodes[x].val == val:
                return True
            elif self.nodes[x].val < val:
                x = self.nodes[x].right
            else:
                x = self.nodes[x].left
        return False

    def init_color(self):
        for node in self.nodes:
            node.color = Color.WHITE

    def preorder(self):
        preordered = []
        self.init_color()
        def preorder_bfs(s):
            preordered.append(self.nodes[s].val)
            self.nodes[s].color = Color.GRAY
            if  self.nodes[s].left != None and self.nodes[self.nodes[s].left].color == Color.WHITE:
                preorder_bfs(self.nodes[s].left)
            if  self.nodes[s].right != None and self.nodes[self.nodes[s].right].color == Color.WHITE:
                preorder_bfs(self.nodes[s].right)
                self.nodes[s].color = Color.BLACK
        preorder_bfs(self.root)
        return preordered

    def inorder(self):
        inordered = []
        self.init_color()

        inorder_stack = deque([])
        def inorder_dfs_init(s):
            inorder_stack.append(s)
            inorder_dfs()

        def inorder_dfs():
            u = inorder_stack.pop()
            self.nodes[u].color = Color.GRAY
            if self.nodes[u].left != None and self.nodes[self.nodes[u].left].color == Color.WHITE:
                inorder_stack.append(u)
                inorder_stack.append(self.nodes[u].left)
                inorder_dfs()
            inordered.append(self.nodes[u].val)
            if self.nodes[u].right != None and self.nodes[self.nodes[u].right].color == Color.WHITE:
                inorder_stack.append(self.nodes[u].right)
                inorder_dfs()
            self.nodes[u].color = Color.BLACK

        inorder_dfs_init(self.root)
        return inordered

def print_elements(ordered):
    print(' ', end='')
    print(' '.join(list(map(str, ordered))))

m = int(input())
bst = BinarySearchTree()
for i in range(m):
    op = input()
    if op == 'print':
        print_elements(bst.inorder())
        print_elements(bst.preorder())
        continue
    ope, num = op.split(' ')
    num = int(num)
    if ope == 'insert':
        bst.insert(num)
    elif ope == 'find':
        if bst.find(num):
            print('yes')
        else:
            print('no')



Fixed submission:
class BinaryTreeNode():
    # __slots__ = ['left', 'right', 'val']
    def __init__(self, left=None, right=None, val=None):
        self.left = left
        self.right = right
        self.val = val

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

    def insert(self, val):
        y = None
        x = self.root
        while x != None:
            y = x
            if val < x.val:
                x = x.left
            else:
                x = x.right
        node = BinaryTreeNode(val=val)

        if y == None:
            self.root = node
        elif node.val < y.val:
            y.left = node
        else:
            y.right = node

    def preorder(self):
        self.preorder_list = []
        self.preorder_bfs(self.root)
        return self.preorder_list

    def preorder_bfs(self, u):
        if u == None: return
        self.preorder_list.append(u.val)
        self.preorder_bfs(u.left)
        self.preorder_bfs(u.right)

    def inorder(self):
        self.inorder_list = []
        self.inorder_dfs(self.root)
        return self.inorder_list

    def inorder_dfs(self, u):
        if u == None: return
        self.inorder_dfs(u.left)
        self.inorder_list.append(u.val)
        self.inorder_dfs(u.right)

def print_elements(arr):
    print(' ' + ' '.join([str(item) for item in arr]))

m = int(input())
bst = BinarySearchTree()
for i in range(m):
    op = input()
    if op == 'print':
        print_elements(bst.inorder())
        print_elements(bst.preorder())
    else:
        num = int(op[7:])
        bst.insert(num)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
from enum import Enum, auto

class Color(Enum):
    WHITE = auto()
    GRAY = auto()
    BLACK = auto()

class BinaryTreeNode():
    def __init__(self, parent=None, left=None, right=None, val=None):
        self.parent = parent
        self.left = left
        self.right = right
        self.val = val
        self.color = Color.WHITE

class BinarySearchTree():
    def __init__(self, n):
        self.root = None
        self.nodes = deque([])
        self.num_nodes = n

    def set_root(self, val):
        node = BinaryTreeNode(val=val)
        self.root = len(self.nodes)
        self.nodes.append(node)

    def insert(self, val):
        y = None
        x = self.root
        while x != None:
            y = x
            if val < self.nodes[x].val:
                x = self.nodes[x].left
            else:
                x = self.nodes[x].right
        node = BinaryTreeNode(val=val, parent=y)

        if y == None:
            self.set_root(val)
        elif node.val < self.nodes[y].val:
            self.nodes[y].left = len(self.nodes)
            self.nodes.append(node)
        else:
            self.nodes[y].right = len(self.nodes)
            self.nodes.append(node)

    def init_color(self):
        for node in self.nodes:
            node.color = Color.WHITE

    def preorder(self):
        preordered = []
        self.init_color()
        def preorder_bfs(s):
            preordered.append(self.nodes[s].val)
            self.nodes[s].color = Color.GRAY
            if  self.nodes[s].left != None and self.nodes[self.nodes[s].left].color == Color.WHITE:
                preorder_bfs(self.nodes[s].left)
            if  self.nodes[s].right != None and self.nodes[self.nodes[s].right].color == Color.WHITE:
                preorder_bfs(self.nodes[s].right)
                self.nodes[s].color = Color.BLACK
        preorder_bfs(self.root)
        return preordered

    def inorder(self):
        inordered = []
        self.init_color()

        inorder_stack = deque([])
        def inorder_dfs_init(s):
            inorder_stack.append(s)
            inorder_dfs()

        def inorder_dfs():
            u = inorder_stack.pop()
            self.nodes[u].color = Color.GRAY
            if self.nodes[u].left != None and self.nodes[self.nodes[u].left].color == Color.WHITE:
                inorder_stack.append(u)
                inorder_stack.append(self.nodes[u].left)
                inorder_dfs()
            inordered.append(self.nodes[u].val)
            if self.nodes[u].right != None and self.nodes[self.nodes[u].right].color == Color.WHITE:
                inorder_stack.append(self.nodes[u].right)
                inorder_dfs()
            self.nodes[u].color = Color.BLACK

        inorder_dfs_init(self.root)
        return inordered

def print_elements(ordered):
    for ele in ordered:
        print(' {}'.format(ele), end='')
    print('')

m = int(input())
bst = BinarySearchTree(m)
for i in range(m):
    op = input()
    if op == 'print':
        print_elements(bst.inorder())
        print_elements(bst.preorder())
    else:
        num = int(op[7:])
        bst.insert(num)



Fixed submission:
class BinaryTreeNode():
    # __slots__ = ['left', 'right', 'val']
    def __init__(self, left=None, right=None, val=None):
        self.left = left
        self.right = right
        self.val = val

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

    def insert(self, val):
        y = None
        x = self.root
        while x != None:
            y = x
            if val < x.val:
                x = x.left
            else:
                x = x.right
        node = BinaryTreeNode(val=val)

        if y == None:
            self.root = node
        elif node.val < y.val:
            y.left = node
        else:
            y.right = node

    def preorder(self):
        self.preorder_list = []
        self.preorder_bfs(self.root)
        return self.preorder_list

    def preorder_bfs(self, u):
        if u == None: return
        self.preorder_list.append(u.val)
        self.preorder_bfs(u.left)
        self.preorder_bfs(u.right)

    def inorder(self):
        self.inorder_list = []
        self.inorder_dfs(self.root)
        return self.inorder_list

    def inorder_dfs(self, u):
        if u == None: return
        self.inorder_dfs(u.left)
        self.inorder_list.append(u.val)
        self.inorder_dfs(u.right)

def print_elements(arr):
    print(' ' + ' '.join([str(item) for item in arr]))

m = int(input())
bst = BinarySearchTree()
for i in range(m):
    op = input()
    if op == 'print':
        print_elements(bst.inorder())
        print_elements(bst.preorder())
    else:
        num = int(op[7:])
        bst.insert(num)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
from enum import Enum, auto

class Color(Enum):
    WHITE = auto()
    GRAY = auto()
    BLACK = auto()

class BinaryTreeNode():
    def __init__(self, parent=None, left=None, right=None, val=None):
        self.parent = parent
        self.left = left
        self.right = right
        self.val = val
        self.color = Color.WHITE

class BinarySearchTree():
    def __init__(self, n):
        self.root = None
        self.nodes = deque([])
        self.num_nodes = n

    def set_root(self, val):
        node = BinaryTreeNode(val=val)
        self.root = len(self.nodes)
        self.nodes.append(node)

    def insert(self, val):
        y = None
        x = self.root
        while x != None:
            y = x
            if val < self.nodes[x].val:
                x = self.nodes[x].left
            else:
                x = self.nodes[x].right
        node = BinaryTreeNode(val=val, parent=y)

        if y == None:
            self.set_root(val)
        elif node.val < self.nodes[y].val:
            self.nodes[y].left = len(self.nodes)
            self.nodes.append(node)
        else:
            self.nodes[y].right = len(self.nodes)
            self.nodes.append(node)

    def init_color(self):
        for node in self.nodes:
            node.color = Color.WHITE

    def preorder(self):
        self.init_color()
        def preorder_bfs(s):
            print('', self.nodes[s].val, end='')
            self.nodes[s].color = Color.GRAY
            if  self.nodes[s].left != None and self.nodes[self.nodes[s].left].color == Color.WHITE:
                preorder_bfs(self.nodes[s].left)
            if  self.nodes[s].right != None and self.nodes[self.nodes[s].right].color == Color.WHITE:
                preorder_bfs(self.nodes[s].right)
                self.nodes[s].color = Color.BLACK
        preorder_bfs(self.root)
        print('')

    def inorder(self):
        self.init_color()

        inorder_stack = deque([])
        def inorder_dfs_init(s):
            inorder_stack.append(s)
            inorder_dfs()

        def inorder_dfs():
            u = inorder_stack.pop()
            self.nodes[u].color = Color.GRAY
            if self.nodes[u].left != None and self.nodes[self.nodes[u].left].color == Color.WHITE:
                inorder_stack.append(u)
                inorder_stack.append(self.nodes[u].left)
                inorder_dfs()
            print('', self.nodes[u].val, end='')
            if self.nodes[u].right != None and self.nodes[self.nodes[u].right].color == Color.WHITE:
                inorder_stack.append(self.nodes[u].right)
                inorder_dfs()
            self.nodes[u].color = Color.BLACK

        inorder_dfs_init(self.root)
        print('')

def print_elements(ordered):
    for ele in ordered:
        print(' {}'.format(ele), end='')
    print('')

m = int(input())
bst = BinarySearchTree(m)
for i in range(m):
    op = input()
    if op == 'print':
        bst.inorder()
        bst.preorder()
    else:
        num = int(op[7:])
        bst.insert(num)



Fixed submission:
class BinaryTreeNode():
    # __slots__ = ['left', 'right', 'val']
    def __init__(self, left=None, right=None, val=None):
        self.left = left
        self.right = right
        self.val = val

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

    def insert(self, val):
        y = None
        x = self.root
        while x != None:
            y = x
            if val < x.val:
                x = x.left
            else:
                x = x.right
        node = BinaryTreeNode(val=val)

        if y == None:
            self.root = node
        elif node.val < y.val:
            y.left = node
        else:
            y.right = node

    def preorder(self):
        self.preorder_list = []
        self.preorder_bfs(self.root)
        return self.preorder_list

    def preorder_bfs(self, u):
        if u == None: return
        self.preorder_list.append(u.val)
        self.preorder_bfs(u.left)
        self.preorder_bfs(u.right)

    def inorder(self):
        self.inorder_list = []
        self.inorder_dfs(self.root)
        return self.inorder_list

    def inorder_dfs(self, u):
        if u == None: return
        self.inorder_dfs(u.left)
        self.inorder_list.append(u.val)
        self.inorder_dfs(u.right)

def print_elements(arr):
    print(' ' + ' '.join([str(item) for item in arr]))

m = int(input())
bst = BinarySearchTree()
for i in range(m):
    op = input()
    if op == 'print':
        print_elements(bst.inorder())
        print_elements(bst.preorder())
    else:
        num = int(op[7:])
        bst.insert(num)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
from enum import Enum, auto

class BinaryTreeNode():
    __slots__ = ['left', 'right', 'val']
    def __init__(self, left=None, right=None, val=None):
        self.left = left
        self.right = right
        self.val = val

class BinarySearchTree():
    def __init__(self):
        self.root = None
        self.nodes = deque([])
        self.num_nodes = 0

    def insert(self, val):
        y = None
        x = self.root
        while x != None:
            y = x
            if val < self.nodes[x].val:
                x = self.nodes[x].left
            else:
                x = self.nodes[x].right
        node = BinaryTreeNode(val=val)

        if y == None:
            self.root = 0
        elif node.val < self.nodes[y].val:
            self.nodes[y].left = self.num_nodes
        else:
            self.nodes[y].right = self.num_nodes
        self.nodes.append(node)
        self.num_nodes += 1

    def preorder(self):
        def preorder_bfs(s):
            print('', self.nodes[s].val, end='')
            if  self.nodes[s].left != None:
                preorder_bfs(self.nodes[s].left)
            if  self.nodes[s].right != None:
                preorder_bfs(self.nodes[s].right)
        preorder_bfs(self.root)
        print('')

    def inorder(self):
        inorder_stack = deque([])
        def inorder_dfs_init(s):
            inorder_stack.append(s)
            inorder_dfs()

        def inorder_dfs():
            u = inorder_stack.pop()
            if self.nodes[u].left != None:
                inorder_stack.append(u)
                inorder_stack.append(self.nodes[u].left)
                inorder_dfs()
            print('', self.nodes[u].val, end='')
            if self.nodes[u].right != None:
                inorder_stack.append(self.nodes[u].right)
                inorder_dfs()

        inorder_dfs_init(self.root)
        print('')

m = int(input())
bst = BinarySearchTree()
for i in range(m):
    op = input()
    if op == 'print':
        bst.inorder()
        bst.preorder()
    else:
        num = int(op[7:])
        bst.insert(num)



Fixed submission:
class BinaryTreeNode():
    # __slots__ = ['left', 'right', 'val']
    def __init__(self, left=None, right=None, val=None):
        self.left = left
        self.right = right
        self.val = val

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

    def insert(self, val):
        y = None
        x = self.root
        while x != None:
            y = x
            if val < x.val:
                x = x.left
            else:
                x = x.right
        node = BinaryTreeNode(val=val)

        if y == None:
            self.root = node
        elif node.val < y.val:
            y.left = node
        else:
            y.right = node

    def preorder(self):
        self.preorder_list = []
        self.preorder_bfs(self.root)
        return self.preorder_list

    def preorder_bfs(self, u):
        if u == None: return
        self.preorder_list.append(u.val)
        self.preorder_bfs(u.left)
        self.preorder_bfs(u.right)

    def inorder(self):
        self.inorder_list = []
        self.inorder_dfs(self.root)
        return self.inorder_list

    def inorder_dfs(self, u):
        if u == None: return
        self.inorder_dfs(u.left)
        self.inorder_list.append(u.val)
        self.inorder_dfs(u.right)

def print_elements(arr):
    print(' ' + ' '.join([str(item) for item in arr]))

m = int(input())
bst = BinarySearchTree()
for i in range(m):
    op = input()
    if op == 'print':
        print_elements(bst.inorder())
        print_elements(bst.preorder())
    else:
        num = int(op[7:])
        bst.insert(num)

Buggy python submission (verdict: Runtime Error):
from collections import deque
from enum import Enum, auto

class BinaryTreeNode():
    __slots__ = ['left', 'right', 'val']
    def __init__(self, left=None, right=None, val=None):
        self.left = left
        self.right = right
        self.val = val

class BinarySearchTree():
    def __init__(self):
        self.root = None
        self.nodes = deque([])
        self.num_nodes = 0
        self.inorder = ''
        self.preorder = ''

    def insert(self, val):
        y = None
        x = self.root
        while x != None:
            y = x
            if val < self.nodes[x].val:
                x = self.nodes[x].left
            else:
                x = self.nodes[x].right
        node = BinaryTreeNode(val=val)

        if y == None:
            self.root = 0
        elif node.val < self.nodes[y].val:
            self.nodes[y].left = self.num_nodes
        else:
            self.nodes[y].right = self.num_nodes
        self.nodes.append(node)
        self.num_nodes += 1

    def preorder(self):
        self.preorder = ''
        def preorder_bfs(s):
            self.preorder += ' ' + str(self.nodes[s].val)
            if  self.nodes[s].left != None:
                preorder_bfs(self.nodes[s].left)
            if  self.nodes[s].right != None:
                preorder_bfs(self.nodes[s].right)
        preorder_bfs(self.root)
        return self.preorder

    def inorder(self):
        self.inorder = ''
        inorder_stack = deque([])
        def inorder_dfs_init(s):
            inorder_stack.append(s)
            inorder_dfs()

        def inorder_dfs():
            u = inorder_stack.pop()
            if self.nodes[u].left != None:
                inorder_stack.append(u)
                inorder_stack.append(self.nodes[u].left)
                inorder_dfs()
            self.inorder += ' ' + str(self.nodes[u].val)
            if self.nodes[u].right != None:
                inorder_stack.append(self.nodes[u].right)
                inorder_dfs()

        inorder_dfs_init(self.root)
        return self.inorder

m = int(input())
bst = BinarySearchTree()
for i in range(m):
    op = input()
    if op == 'print':
        print(bst.inorder())
        print(bst.preorder())
    else:
        num = int(op[7:])
        bst.insert(num)



Fixed submission:
class BinaryTreeNode():
    # __slots__ = ['left', 'right', 'val']
    def __init__(self, left=None, right=None, val=None):
        self.left = left
        self.right = right
        self.val = val

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

    def insert(self, val):
        y = None
        x = self.root
        while x != None:
            y = x
            if val < x.val:
                x = x.left
            else:
                x = x.right
        node = BinaryTreeNode(val=val)

        if y == None:
            self.root = node
        elif node.val < y.val:
            y.left = node
        else:
            y.right = node

    def preorder(self):
        self.preorder_list = []
        self.preorder_bfs(self.root)
        return self.preorder_list

    def preorder_bfs(self, u):
        if u == None: return
        self.preorder_list.append(u.val)
        self.preorder_bfs(u.left)
        self.preorder_bfs(u.right)

    def inorder(self):
        self.inorder_list = []
        self.inorder_dfs(self.root)
        return self.inorder_list

    def inorder_dfs(self, u):
        if u == None: return
        self.inorder_dfs(u.left)
        self.inorder_list.append(u.val)
        self.inorder_dfs(u.right)

def print_elements(arr):
    print(' ' + ' '.join([str(item) for item in arr]))

m = int(input())
bst = BinarySearchTree()
for i in range(m):
    op = input()
    if op == 'print':
        print_elements(bst.inorder())
        print_elements(bst.preorder())
    else:
        num = int(op[7:])
        bst.insert(num)

Buggy python submission (verdict: Runtime Error):
from collections import deque
from enum import Enum, auto

class BinaryTreeNode():
    __slots__ = ['left', 'right', 'val']
    def __init__(self, left=None, right=None, val=None):
        self.left = left
        self.right = right
        self.val = val

class BinarySearchTree():
    def __init__(self):
        self.root = None
        self.nodes = deque([])
        self.num_nodes = 0
        self.inorder_str = ''
        self.preorder_str = ''

    def insert(self, val):
        y = None
        x = self.root
        while x != None:
            y = x
            if val < self.nodes[x].val:
                x = self.nodes[x].left
            else:
                x = self.nodes[x].right
        node = BinaryTreeNode(val=val)

        if y == None:
            self.root = 0
        elif node.val < self.nodes[y].val:
            self.nodes[y].left = self.num_nodes
        else:
            self.nodes[y].right = self.num_nodes
        self.nodes.append(node)
        self.num_nodes += 1

    def preorder(self):
        self.preorder = ''
        def preorder_bfs(s):
            self.preorder_str += ' ' + str(self.nodes[s].val)
            if  self.nodes[s].left != None:
                preorder_bfs(self.nodes[s].left)
            if  self.nodes[s].right != None:
                preorder_bfs(self.nodes[s].right)
        preorder_bfs(self.root)
        return self.preorder_str

    def inorder(self):
        self.inorder = ''
        inorder_stack = deque([])
        def inorder_dfs_init(s):
            inorder_stack.append(s)
            inorder_dfs()

        def inorder_dfs():
            u = inorder_stack.pop()
            if self.nodes[u].left != None:
                inorder_stack.append(u)
                inorder_stack.append(self.nodes[u].left)
                inorder_dfs()
            self.inorder_str += ' ' + str(self.nodes[u].val)
            if self.nodes[u].right != None:
                inorder_stack.append(self.nodes[u].right)
                inorder_dfs()

        inorder_dfs_init(self.root)
        return self.inorder_str

m = int(input())
bst = BinarySearchTree()
for i in range(m):
    op = input()
    if op == 'print':
        print(bst.inorder())
        print(bst.preorder())
    else:
        num = int(op[7:])
        bst.insert(num)



Fixed submission:
class BinaryTreeNode():
    # __slots__ = ['left', 'right', 'val']
    def __init__(self, left=None, right=None, val=None):
        self.left = left
        self.right = right
        self.val = val

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

    def insert(self, val):
        y = None
        x = self.root
        while x != None:
            y = x
            if val < x.val:
                x = x.left
            else:
                x = x.right
        node = BinaryTreeNode(val=val)

        if y == None:
            self.root = node
        elif node.val < y.val:
            y.left = node
        else:
            y.right = node

    def preorder(self):
        self.preorder_list = []
        self.preorder_bfs(self.root)
        return self.preorder_list

    def preorder_bfs(self, u):
        if u == None: return
        self.preorder_list.append(u.val)
        self.preorder_bfs(u.left)
        self.preorder_bfs(u.right)

    def inorder(self):
        self.inorder_list = []
        self.inorder_dfs(self.root)
        return self.inorder_list

    def inorder_dfs(self, u):
        if u == None: return
        self.inorder_dfs(u.left)
        self.inorder_list.append(u.val)
        self.inorder_dfs(u.right)

def print_elements(arr):
    print(' ' + ' '.join([str(item) for item in arr]))

m = int(input())
bst = BinarySearchTree()
for i in range(m):
    op = input()
    if op == 'print':
        print_elements(bst.inorder())
        print_elements(bst.preorder())
    else:
        num = int(op[7:])
        bst.insert(num)

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

class BinaryTreeNode():
    __slots__ = ['left', 'right', 'val']
    def __init__(self, left=None, right=None, val=None):
        self.left = left
        self.right = right
        self.val = val

class BinarySearchTree():
    def __init__(self):
        self.root = None
        self.nodes = deque([])
        self.num_nodes = 0
        self.inorder_str = ''
        self.preorder_str = ''

    def insert(self, val):
        y = None
        x = self.root
        while x != None:
            y = x
            if val < self.nodes[x].val:
                x = self.nodes[x].left
            else:
                x = self.nodes[x].right
        node = BinaryTreeNode(val=val)

        if y == None:
            self.root = 0
        elif node.val < self.nodes[y].val:
            self.nodes[y].left = self.num_nodes
        else:
            self.nodes[y].right = self.num_nodes
        self.nodes.append(node)
        self.num_nodes += 1

    def preorder(self):
        self.preorder_str = ''
        def preorder_bfs(s):
            self.preorder_str += ' ' + str(self.nodes[s].val)
            if  self.nodes[s].left != None:
                preorder_bfs(self.nodes[s].left)
            if  self.nodes[s].right != None:
                preorder_bfs(self.nodes[s].right)
        preorder_bfs(self.root)
        return self.preorder_str

    def inorder(self):
        self.inorder_str = ''
        inorder_stack = deque([])
        def inorder_dfs_init(s):
            inorder_stack.append(s)
            inorder_dfs()

        def inorder_dfs():
            u = inorder_stack.pop()
            if self.nodes[u].left != None:
                inorder_stack.append(u)
                inorder_stack.append(self.nodes[u].left)
                inorder_dfs()
            self.inorder_str += ' ' + str(self.nodes[u].val)
            if self.nodes[u].right != None:
                inorder_stack.append(self.nodes[u].right)
                inorder_dfs()

        inorder_dfs_init(self.root)
        return self.inorder_str

m = int(input())
bst = BinarySearchTree()
for i in range(m):
    op = input()
    if op == 'print':
        print(bst.inorder())
        print(bst.preorder())
    else:
        num = int(op[7:])
        bst.insert(num)



Fixed submission:
class BinaryTreeNode():
    # __slots__ = ['left', 'right', 'val']
    def __init__(self, left=None, right=None, val=None):
        self.left = left
        self.right = right
        self.val = val

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

    def insert(self, val):
        y = None
        x = self.root
        while x != None:
            y = x
            if val < x.val:
                x = x.left
            else:
                x = x.right
        node = BinaryTreeNode(val=val)

        if y == None:
            self.root = node
        elif node.val < y.val:
            y.left = node
        else:
            y.right = node

    def preorder(self):
        self.preorder_list = []
        self.preorder_bfs(self.root)
        return self.preorder_list

    def preorder_bfs(self, u):
        if u == None: return
        self.preorder_list.append(u.val)
        self.preorder_bfs(u.left)
        self.preorder_bfs(u.right)

    def inorder(self):
        self.inorder_list = []
        self.inorder_dfs(self.root)
        return self.inorder_list

    def inorder_dfs(self, u):
        if u == None: return
        self.inorder_dfs(u.left)
        self.inorder_list.append(u.val)
        self.inorder_dfs(u.right)

def print_elements(arr):
    print(' ' + ' '.join([str(item) for item in arr]))

m = int(input())
bst = BinarySearchTree()
for i in range(m):
    op = input()
    if op == 'print':
        print_elements(bst.inorder())
        print_elements(bst.preorder())
    else:
        num = int(op[7:])
        bst.insert(num)

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

class BinaryTreeNode():
    # __slots__ = ['left', 'right', 'val']
    def __init__(self, left=None, right=None, val=None):
        self.left = left
        self.right = right
        self.val = val

class BinarySearchTree():
    def __init__(self):
        self.root = None
        self.nodes = deque([])
        self.num_nodes = 0

    def insert(self, val):
        y = None
        x = self.root
        while x != None:
            y = x
            if val < self.nodes[x].val:
                x = self.nodes[x].left
            else:
                x = self.nodes[x].right
        node = BinaryTreeNode(val=val)

        if y == None:
            self.root = 0
        elif node.val < self.nodes[y].val:
            self.nodes[y].left = self.num_nodes
        else:
            self.nodes[y].right = self.num_nodes
        self.nodes.append(node)
        self.num_nodes += 1

    def preorder(self):
        self.preorder_list = []
        self.preorder_bfs(self.root)
        return self.preorder_list

    def preorder_bfs(self, u):
        if u == None: return
        self.preorder_list.append(self.nodes[u].val)
        self.preorder_bfs(self.nodes[u].left)
        self.preorder_bfs(self.nodes[u].right)

    def inorder(self):
        self.inorder_list = []
        self.inorder_dfs(self.root)
        return self.inorder_list

    def inorder_dfs(self, u):
        if u == None: return
        self.inorder_dfs(self.nodes[u].left)
        self.inorder_list.append(self.nodes[u].val)
        self.inorder_dfs(self.nodes[u].right)

def print_elements(arr):
    print(' ' + ' '.join([str(item) for item in arr]))

m = int(input())
bst = BinarySearchTree()
for i in range(m):
    op = input()
    if op == 'print':
        print_elements(bst.inorder())
        print_elements(bst.preorder())
    else:
        num = int(op[7:])
        bst.insert(num)



Fixed submission:
class BinaryTreeNode():
    # __slots__ = ['left', 'right', 'val']
    def __init__(self, left=None, right=None, val=None):
        self.left = left
        self.right = right
        self.val = val

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

    def insert(self, val):
        y = None
        x = self.root
        while x != None:
            y = x
            if val < x.val:
                x = x.left
            else:
                x = x.right
        node = BinaryTreeNode(val=val)

        if y == None:
            self.root = node
        elif node.val < y.val:
            y.left = node
        else:
            y.right = node

    def preorder(self):
        self.preorder_list = []
        self.preorder_bfs(self.root)
        return self.preorder_list

    def preorder_bfs(self, u):
        if u == None: return
        self.preorder_list.append(u.val)
        self.preorder_bfs(u.left)
        self.preorder_bfs(u.right)

    def inorder(self):
        self.inorder_list = []
        self.inorder_dfs(self.root)
        return self.inorder_list

    def inorder_dfs(self, u):
        if u == None: return
        self.inorder_dfs(u.left)
        self.inorder_list.append(u.val)
        self.inorder_dfs(u.right)

def print_elements(arr):
    print(' ' + ' '.join([str(item) for item in arr]))

m = int(input())
bst = BinarySearchTree()
for i in range(m):
    op = input()
    if op == 'print':
        print_elements(bst.inorder())
        print_elements(bst.preorder())
    else:
        num = int(op[7:])
        bst.insert(num)