Buggy python submission (verdict: Runtime Error):
n = int(input())
tree = [None for i in range(n)]
root = set(range(n))

for i in range(n):
    i, l, r = map(int, input().split())
    left[i] = l
    right[i] = r
    root -= {1, r}

def preorder(i):
    if i == -1:
        return
    print(' ', i, sep = '')
    preorder(left[i])
    preorder(right[i])
      
def inorder(i):
    if i == -1:
        return
    inorder(left[i])
    print(' ', i, sep = '')
    inorder(right[i])
      
def postorder(i):
    if i == -1:
        return
    postorder(left[i])
    postorder(right[i])
    print(' ', i, sep = '')

print('Preorder')
preorder(root)
print()
  
print('Inorder')
inorder(root)
print()
  
print('Postorder')
postorder(root)
print()

Fixed submission:
n = int(input())
left = [None for i in range(n)]
right = [None for i in range(n)]
root = sum(range(n)) - n - 1

for i in range(n):
    i, l, r = map(int, input().split())
    left[i] = l
    right[i] = r
    root -= (l + r)

def Preorder(i):
    if (i == -1):
        return
    print(" {}".format(i), end = "")
    Preorder(left[i])
    Preorder(right[i])
      
def Inorder(i):
    if (i == -1):
        return
    Inorder(left[i])
    print(" {}".format(i), end = "")
    Inorder(right[i])
      
def Postorder(i):
    if (i == -1):
        return
    Postorder(left[i])
    Postorder(right[i])
    print(" {}".format(i), end = "")

print("Preorder")
Preorder(root)
print()
  
print("Inorder")
Inorder(root)
print()
  
print("Postorder")
Postorder(root)
print()

Buggy python submission (verdict: Runtime Error):
n = int(input())
tree = [None for i in range(n)]
root = set(range(n))

for i in range(n):
    i, l, r = map(int, input().split())
    left[i] = l
    right[i] = r
    root -= {1, r}

def preorder(i):
    if i == -1:
        return
    print(' ', i, sep = '', end = '')
    preorder(left[i])
    preorder(right[i])
      
def inorder(i):
    if i == -1:
        return
    inorder(left[i])
    print(' ', i, sep = '', end = '')
    inorder(right[i])
      
def postorder(i):
    if i == -1:
        return
    postorder(left[i])
    postorder(right[i])
    print(' ', i, sep = '', end = '')

print('Preorder')
preorder(root)
print()
  
print('Inorder')
inorder(root)
print()
  
print('Postorder')
postorder(root)
print()

Fixed submission:
n = int(input())
left = [None for i in range(n)]
right = [None for i in range(n)]
root = sum(range(n)) - n - 1

for i in range(n):
    i, l, r = map(int, input().split())
    left[i] = l
    right[i] = r
    root -= (l + r)

def Preorder(i):
    if (i == -1):
        return
    print(" {}".format(i), end = "")
    Preorder(left[i])
    Preorder(right[i])
      
def Inorder(i):
    if (i == -1):
        return
    Inorder(left[i])
    print(" {}".format(i), end = "")
    Inorder(right[i])
      
def Postorder(i):
    if (i == -1):
        return
    Postorder(left[i])
    Postorder(right[i])
    print(" {}".format(i), end = "")

print("Preorder")
Preorder(root)
print()
  
print("Inorder")
Inorder(root)
print()
  
print("Postorder")
Postorder(root)
print()

Buggy python submission (verdict: Runtime Error):
n = int(input())
tree = [None for i in range(n)]
root = set(range(n))

for i in range(n):
    i, l, r = map(int, input().split())
    left[i] = l
    right[i] = r
    root -= {1, r}

def preorder(i):
    if (i == -1):
        return
    print(" {}".format(i), end = "")
    preorder(left[i])
    preorder(right[i])
      
def inorder(i):
    if (i == -1):
        return
    inorder(left[i])
    print(" {}".format(i), end = "")
    inorder(right[i])
      
def postorder(i):
    if (i == -1):
        return
    postorder(left[i])
    postorder(right[i])
    print(" {}".format(i), end = "")

print('Preorder')
preorder(root)
print()
  
print('Inorder')
inorder(root)
print()
  
print('Postorder')
postorder(root)
print()

Fixed submission:
n = int(input())
left = [None for i in range(n)]
right = [None for i in range(n)]
root = sum(range(n)) - n - 1

for i in range(n):
    i, l, r = map(int, input().split())
    left[i] = l
    right[i] = r
    root -= (l + r)

def Preorder(i):
    if (i == -1):
        return
    print(" {}".format(i), end = "")
    Preorder(left[i])
    Preorder(right[i])
      
def Inorder(i):
    if (i == -1):
        return
    Inorder(left[i])
    print(" {}".format(i), end = "")
    Inorder(right[i])
      
def Postorder(i):
    if (i == -1):
        return
    Postorder(left[i])
    Postorder(right[i])
    print(" {}".format(i), end = "")

print("Preorder")
Preorder(root)
print()
  
print("Inorder")
Inorder(root)
print()
  
print("Postorder")
Postorder(root)
print()

Buggy python submission (verdict: Runtime Error):
n = int(input())
tree = [None for i in range(n)]
root = set(range(n))

for i in range(n):
    i, l, r = map(int, input().split())
    left[i] = l
    right[i] = r
    root -= {1, r}

def preorder(i):
    if (i == -1):
        return
    (l, r) = tree[i]
    print(" {}".format(i), end = "")
    preorder(left[i])
    preorder(right[i])
      
def inorder(i):
    if (i == -1):
        return
    (l, r) = tree[i]
    inorder(left[i])
    print(" {}".format(i), end = "")
    inorder(right[i])
      
def postorder(i):
    if (i == -1):
        return
    (l, r) = tree[i]
    postorder(left[i])
    postorder(right[i])
    print(" {}".format(i), end = "")

print('Preorder')
preorder(root)
print()
  
print('Inorder')
inorder(root)
print()
  
print('Postorder')
postorder(root)
print()

Fixed submission:
n = int(input())
left = [None for i in range(n)]
right = [None for i in range(n)]
root = sum(range(n)) - n - 1

for i in range(n):
    i, l, r = map(int, input().split())
    left[i] = l
    right[i] = r
    root -= (l + r)

def Preorder(i):
    if (i == -1):
        return
    print(" {}".format(i), end = "")
    Preorder(left[i])
    Preorder(right[i])
      
def Inorder(i):
    if (i == -1):
        return
    Inorder(left[i])
    print(" {}".format(i), end = "")
    Inorder(right[i])
      
def Postorder(i):
    if (i == -1):
        return
    Postorder(left[i])
    Postorder(right[i])
    print(" {}".format(i), end = "")

print("Preorder")
Preorder(root)
print()
  
print("Inorder")
Inorder(root)
print()
  
print("Postorder")
Postorder(root)
print()

Buggy python submission (verdict: Runtime Error):
n = int(input())
left = [None for i in range(n)]
right = [None for i in range(n)]
root = set(range(n))

for i in range(n):
    i, l, r = map(int, input().split())
    left[i] = l
    right[i] = r
    root -= (1 + r)

def preorder(i):
    if (i == -1):
        return
    print(" {}".format(i), end = "")
    preorder(left[i])
    preorder(right[i])
      
def inorder(i):
    if (i == -1):
        return
    inorder(left[i])
    print(" {}".format(i), end = "")
    inorder(right[i])
      
def postorder(i):
    if (i == -1):
        return
    postorder(left[i])
    postorder(right[i])
    print(" {}".format(i), end = "")

print('Preorder')
preorder(root)
print()
  
print('Inorder')
inorder(root)
print()
  
print('Postorder')
postorder(root)
print()

Fixed submission:
n = int(input())
left = [None for i in range(n)]
right = [None for i in range(n)]
root = sum(range(n)) - n - 1

for i in range(n):
    i, l, r = map(int, input().split())
    left[i] = l
    right[i] = r
    root -= (l + r)

def Preorder(i):
    if (i == -1):
        return
    print(" {}".format(i), end = "")
    Preorder(left[i])
    Preorder(right[i])
      
def Inorder(i):
    if (i == -1):
        return
    Inorder(left[i])
    print(" {}".format(i), end = "")
    Inorder(right[i])
      
def Postorder(i):
    if (i == -1):
        return
    Postorder(left[i])
    Postorder(right[i])
    print(" {}".format(i), end = "")

print("Preorder")
Preorder(root)
print()
  
print("Inorder")
Inorder(root)
print()
  
print("Postorder")
Postorder(root)
print()

Buggy python submission (verdict: Runtime Error):
n = int(input())
left = [None for i in range(n)]
right = [None for i in range(n)]
root = set(range(n))

for i in range(n):
    i, l, r = map(int, input().split())
    left[i] = l
    right[i] = r
    root -= (l + r)

def preorder(i):
    if (i == -1):
        return
    print(" {}".format(i), end = "")
    preorder(left[i])
    preorder(right[i])
      
def inorder(i):
    if (i == -1):
        return
    inorder(left[i])
    print(" {}".format(i), end = "")
    inorder(right[i])
      
def postorder(i):
    if (i == -1):
        return
    postorder(left[i])
    postorder(right[i])
    print(" {}".format(i), end = "")

print('Preorder')
preorder(root)
print()
  
print('Inorder')
inorder(root)
print()
  
print('Postorder')
postorder(root)
print()

Fixed submission:
n = int(input())
left = [None for i in range(n)]
right = [None for i in range(n)]
root = sum(range(n)) - n - 1

for i in range(n):
    i, l, r = map(int, input().split())
    left[i] = l
    right[i] = r
    root -= (l + r)

def Preorder(i):
    if (i == -1):
        return
    print(" {}".format(i), end = "")
    Preorder(left[i])
    Preorder(right[i])
      
def Inorder(i):
    if (i == -1):
        return
    Inorder(left[i])
    print(" {}".format(i), end = "")
    Inorder(right[i])
      
def Postorder(i):
    if (i == -1):
        return
    Postorder(left[i])
    Postorder(right[i])
    print(" {}".format(i), end = "")

print("Preorder")
Preorder(root)
print()
  
print("Inorder")
Inorder(root)
print()
  
print("Postorder")
Postorder(root)
print()

Buggy python submission (verdict: Runtime Error):
n = int(input())
left = [None for i in range(n)]
right = [None for i in range(n)]
root = set(range(n))

for i in range(n):
    i, l, r = map(int, input().split())
    left[i] = l
    right[i] = r
    root -= (l + r)

def Preorder(i):
    if (i == -1):
        return
    print(" {}".format(i), end = "")
    Preorder(left[i])
    Preorder(right[i])
      
def Inorder(i):
    if (i == -1):
        return
    Inorder(left[i])
    print(" {}".format(i), end = "")
    Inorder(right[i])
      
def Postorder(i):
    if (i == -1):
        return
    Postorder(left[i])
    Postorder(right[i])
    print(" {}".format(i), end = "")

print("Preorder")
Preorder(root)
print()
  
print("Inorder")
Inorder(root)
print()
  
print("Postorder")
Postorder(root)
print()

Fixed submission:
n = int(input())
left = [None for i in range(n)]
right = [None for i in range(n)]
root = sum(range(n)) - n - 1

for i in range(n):
    i, l, r = map(int, input().split())
    left[i] = l
    right[i] = r
    root -= (l + r)

def Preorder(i):
    if (i == -1):
        return
    print(" {}".format(i), end = "")
    Preorder(left[i])
    Preorder(right[i])
      
def Inorder(i):
    if (i == -1):
        return
    Inorder(left[i])
    print(" {}".format(i), end = "")
    Inorder(right[i])
      
def Postorder(i):
    if (i == -1):
        return
    Postorder(left[i])
    Postorder(right[i])
    print(" {}".format(i), end = "")

print("Preorder")
Preorder(root)
print()
  
print("Inorder")
Inorder(root)
print()
  
print("Postorder")
Postorder(root)
print()

Buggy python submission (verdict: Runtime Error):
n = int(input())
left = [None for i in range(n)]
right = [None for i in range(n)]
root = sum(range(n))

for i in range(n):
    i, l, r = map(int, input().split())
    left[i] = l
    right[i] = r
    root -= (l + r)

def Preorder(i):
    if (i == -1):
        return
    print(" {}".format(i), end = "")
    Preorder(left[i])
    Preorder(right[i])
      
def Inorder(i):
    if (i == -1):
        return
    Inorder(left[i])
    print(" {}".format(i), end = "")
    Inorder(right[i])
      
def Postorder(i):
    if (i == -1):
        return
    Postorder(left[i])
    Postorder(right[i])
    print(" {}".format(i), end = "")

print("Preorder")
Preorder(root)
print()
  
print("Inorder")
Inorder(root)
print()
  
print("Postorder")
Postorder(root)
print()

Fixed submission:
n = int(input())
left = [None for i in range(n)]
right = [None for i in range(n)]
root = sum(range(n)) - n - 1

for i in range(n):
    i, l, r = map(int, input().split())
    left[i] = l
    right[i] = r
    root -= (l + r)

def Preorder(i):
    if (i == -1):
        return
    print(" {}".format(i), end = "")
    Preorder(left[i])
    Preorder(right[i])
      
def Inorder(i):
    if (i == -1):
        return
    Inorder(left[i])
    print(" {}".format(i), end = "")
    Inorder(right[i])
      
def Postorder(i):
    if (i == -1):
        return
    Postorder(left[i])
    Postorder(right[i])
    print(" {}".format(i), end = "")

print("Preorder")
Preorder(root)
print()
  
print("Inorder")
Inorder(root)
print()
  
print("Postorder")
Postorder(root)
print()