Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
# Binary Search Tree
class Node:
    def __init__(self, v):
        self.value = v
        self.parent = None
        self.left = None
        self.right = None

# 木の根を引数として受け取り，データを挿入した新しい木の根を返す
def insert(node, x):
    if node is None:
        return Node(x)
    elif x == node.value:
        return node
    elif x < node.value:
        node.left = insert(node.left, x)
    else:
        node.right = insert(node.right, x)
    return node

def preorder_walk(node):
    if node:
        yield node.value
        for x in preorder_walk(node.left):
            yield x
        for x in preorder_walk(node.right):
            yield x

def inorder_walk(node):
    if node:
        for x in inorder_walk(node.left):
            yield x
        yield node.value
        for x in inorder_walk(node.right):
            yield x

root = None
n = int(input())
for i in range(n):
    cmd, *val = input().split()
    if cmd == "insert":
        root = insert(root, int(val[0]))
    elif cmd == "print":
        print("", *inorder_walk(root))
        print("", *preorder_walk(root))


Fixed submission:
# Binary Search Tree
class Node:
    def __init__(self, v):
        self.value = v
        self.parent = None
        self.left = None
        self.right = None

# 木の根を引数として受け取り，データを挿入した新しい木の根を返す
def insert_(node, x):
    if node is None:
        return Node(x)
    elif x == node.value:
        return node
    elif x < node.value:
        node.left = insert(node.left, x)
    else:
        node.right = insert(node.right, x)
    return node

# 再帰を使わないパターン
def insert(node):
    global root
    y = None
    x = root
    while x is not None:
        y = x
        if node.value < x.value:
            x = x.left
        else:
            x = x.right
    node.parent = y
    if y is None:
        root = node
    elif node.value < y.value:
        y.left = node
    else:
        y.right = node

def preorder_walk(node):
    if node:
        yield node.value
        for x in preorder_walk(node.left):
            yield x
        for x in preorder_walk(node.right):
            yield x

def inorder_walk(node):
    if node:
        for x in inorder_walk(node.left):
            yield x
        yield node.value
        for x in inorder_walk(node.right):
            yield x

root = None
n = int(input())
for i in range(n):
    cmd, *val = input().split()
    if cmd == "insert":
        #root = insert(root, int(val[0]))
        insert(Node(int(val[0])))
    elif cmd == "print":
        print("", *inorder_walk(root))
        print("", *preorder_walk(root))
Buggy python submission (verdict: Runtime Error):
x1, y1, x2, y2 = map(float, input().split())
print("{0:f}".format(sqrt((x1-x2)**2.0 + (y1-y2)**2.0)))


Fixed submission:
import math
x1, y1, x2, y2 = map(float, input().split())
print("{0:f}".format(math.sqrt((x1-x2)**2.0 + (y1-y2)**2.0)))
Buggy python submission (verdict: Runtime Error):
import math
while(True):
    if input() == '0':
        break
    a = map(int, input().split())
    m = sum(a) / len(a)
    b = 0
    for i in a:
        b += (i - m) ** 2.0
    stddev = math.sqrt(b / n)
    print(stddev)


Fixed submission:
import math
while(True):
    if input() == '0':
        break
    a = list(map(int, input().split()))
    m = sum(a) / len(a)
    b = 0
    for i in a:
        b += (i - m) ** 2.0
    stddev = math.sqrt(b / len(a))
    print(stddev)

Buggy python submission (verdict: Runtime Error):
import math
while(True):
    if input() == '0':
        break
    a = list(map(int, input().split()))
    m = sum(a) / len(a)
    b = 0
    for i in a:
        b += (i - m) ** 2.0
    stddev = math.sqrt(b / n)
    print(stddev)


Fixed submission:
import math
while(True):
    if input() == '0':
        break
    a = list(map(int, input().split()))
    m = sum(a) / len(a)
    b = 0
    for i in a:
        b += (i - m) ** 2.0
    stddev = math.sqrt(b / len(a))
    print(stddev)
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())
if(a<b):
    print("a < b")
elif(a>b):
    print("a > b")
else
    print("a == b")


Fixed submission:
a, b = map(int, input().split())
if(a<b):
    print("a < b")
elif(a>b):
    print("a > b")
else:
    print("a == b")
Buggy python submission (verdict: Runtime Error):
a = list(map(int, input().split()))
print(*a.sort())


Fixed submission:
a = list(map(int, input().split()))
a.sort()
print(" ".join(map(str, a)))

Buggy python submission (verdict: Runtime Error):
a = list(map(int, input().split()))
print(*i) for i in a.sort()


Fixed submission:
a = list(map(int, input().split()))
a.sort()
print(" ".join(map(str, a)))

Buggy python submission (verdict: Runtime Error):
a = list(map(int, input().split()))
[print(*i) for i in a.sort()]


Fixed submission:
a = list(map(int, input().split()))
a.sort()
print(" ".join(map(str, a)))
Buggy python submission (verdict: Runtime Error):
W, H, x, y, r = int(input().split())
if(x < r || y < r):
    print("No")
elif(x > (W - r) || y > (H - r)):
    print("No")
else:
    print("Yes")


Fixed submission:
W, H, x, y, r = map(int, input().split())
if(x < r or y < r):
    print("No")
elif(x > (W - r) or y > (H - r)):
    print("No")
else:
    print("Yes")

Buggy python submission (verdict: Runtime Error):
W, H, x, y, r = int(input().split())
if(x < r or y < r):
    print("No")
elif(x > (W - r) or y > (H - r)):
    print("No")
else:
    print("Yes")


Fixed submission:
W, H, x, y, r = map(int, input().split())
if(x < r or y < r):
    print("No")
elif(x > (W - r) or y > (H - r)):
    print("No")
else:
    print("Yes")
Buggy python submission (verdict: Runtime Error):
import sys
lines = sys.stdin.readlines()
for i in range(lines):
    a = int(lines[i])
    if(a == 0):
        break
    else:
        print("Case {0}: {1}".format(i+1, a))


Fixed submission:
import sys
lines = sys.stdin.readlines()
for i in range(len(lines)):
    a = int(lines[i])
    if(a == 0):
        break
    else:
        print("Case {0}: {1}".format(i+1, a))

Buggy python submission (verdict: Runtime Error):
import sys
lines = sys.stdin.readlines()
for i in range(lines.len):
    a = int(lines[i])
    if(a == 0):
        break
    else:
        print("Case {0}: {1}".format(i+1, a))


Fixed submission:
import sys
lines = sys.stdin.readlines()
for i in range(len(lines)):
    a = int(lines[i])
    if(a == 0):
        break
    else:
        print("Case {0}: {1}".format(i+1, a))

Buggy python submission (verdict: Runtime Error):
import sys
lines = sys.stdin.readlines()
for i in range(lines.length):
    a = int(lines[i])
    if(a == 0):
        break
    else:
        print("Case {0}: {1}".format(i+1, a))


Fixed submission:
import sys
lines = sys.stdin.readlines()
for i in range(len(lines)):
    a = int(lines[i])
    if(a == 0):
        break
    else:
        print("Case {0}: {1}".format(i+1, a))
Buggy python submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
cnt = 0
for i in range(a, b+1):
    if(!(c % i)):
        cnt += 1
print(cnt)


Fixed submission:
a, b, c = map(int, input().split())
cnt = 0
for i in range(a, b+1):
    if(not(c % i)):
        cnt += 1
print(cnt)
Buggy python submission (verdict: Runtime Error):
a, b = map(float, input().split())
print(a//b, a%b, "{0:.f}".format(a/b))


Fixed submission:
a, b = map(float, input().split())
print(a//b, a%b, "{0:f}".format(a/b))
Buggy python submission (verdict: Runtime Error):
while(True):
    a, op, b = input().spilt
    a = int(a)
    b = int(b)
    if(op == '+'):
        print(a+b)
    elif(op == '-'):
        print(a-b)
    elif(op == '*'):
        print(a*b)
    elif(op == '/'):
        print(a//b)
    elif(op == '?'):
        break


Fixed submission:
while(True):
    a, op, b = input().split()
    a = int(a)
    b = int(b)
    if(op == '+'):
        print(a+b)
    elif(op == '-'):
        print(a-b)
    elif(op == '*'):
        print(a*b)
    elif(op == '/'):
        print(a//b)
    elif(op == '?'):
        break

Buggy python submission (verdict: Runtime Error):
while(True):
    a, op, b = input().spilt()
    a = int(a)
    b = int(b)
    if(op == '+'):
        print(a+b)
    elif(op == '-'):
        print(a-b)
    elif(op == '*'):
        print(a*b)
    elif(op == '/'):
        print(a//b)
    elif(op == '?'):
        break


Fixed submission:
while(True):
    a, op, b = input().split()
    a = int(a)
    b = int(b)
    if(op == '+'):
        print(a+b)
    elif(op == '-'):
        print(a-b)
    elif(op == '*'):
        print(a*b)
    elif(op == '/'):
        print(a//b)
    elif(op == '?'):
        break

Buggy python submission (verdict: Runtime Error):
while(True):
    a, op, b = map(input().spilt())
    a = int(a)
    b = int(b)
    if(op == '+'):
        print(a+b)
    elif(op == '-'):
        print(a-b)
    elif(op == '*'):
        print(a*b)
    elif(op == '/'):
        print(a//b)
    elif(op == '?'):
        break


Fixed submission:
while(True):
    a, op, b = input().split()
    a = int(a)
    b = int(b)
    if(op == '+'):
        print(a+b)
    elif(op == '-'):
        print(a-b)
    elif(op == '*'):
        print(a*b)
    elif(op == '/'):
        print(a//b)
    elif(op == '?'):
        break
Buggy python submission (verdict: Runtime Error):
H, W = input().split()
for i in range(H):
    for k in range(W):
        print("#", end = "")
    print("")


Fixed submission:
while(True):
    H, W = map(int, input().split())
    if(H == 0 and W == 0):
        break
    for i in range(H):
        for k in range(W):
            print("#", end = "")
        print("")
    print("")
Buggy python submission (verdict: Runtime Error):
while True:
    m, f, r = map(int, input().split())
    if m == -1 and f == -1 and r == -1:
        break
    elif m == -1 or f == -1:
        grade = "F"
    elif (m + f) => 80:
        grade = "A"
    elif (m + f) => 65:
        grade = "B"
    elif (m + f) => 50:
        grade = "C"
    elif (m + f) => 30:
        if r > 50:
            grade = "C"
        else:
            grade = "D"
    else:
        grade = "F"
    print(grade)


Fixed submission:
while True:
    m, f, r = map(int, input().split())
    if m == -1 and f == -1 and r == -1:
        break
    elif m == -1 or f == -1:
        grade = "F"
    elif (m + f) >= 80:
        grade = "A"
    elif (m + f) >= 65:
        grade = "B"
    elif (m + f) >= 50:
        grade = "C"
    elif (m + f) >= 30:
        if r >= 50:
            grade = "C"
        else:
            grade = "D"
    else:
        grade = "F"
    print(grade)

Buggy python submission (verdict: Runtime Error):
while True:
    m, f, r = map(int, input().split())
    if m == -1 and f == -1 and r == -1:
        break
    elif m == -1 or f == -1:
        grade = "F"
    elif (m + f) >= 80:
        grade = "A"
    elif (m + f) => 65:
        grade = "B"
    elif (m + f) => 50:
        grade = "C"
    elif (m + f) => 30:
        if r > 50:
            grade = "C"
        else:
            grade = "D"
    else:
        grade = "F"
    print(grade)


Fixed submission:
while True:
    m, f, r = map(int, input().split())
    if m == -1 and f == -1 and r == -1:
        break
    elif m == -1 or f == -1:
        grade = "F"
    elif (m + f) >= 80:
        grade = "A"
    elif (m + f) >= 65:
        grade = "B"
    elif (m + f) >= 50:
        grade = "C"
    elif (m + f) >= 30:
        if r >= 50:
            grade = "C"
        else:
            grade = "D"
    else:
        grade = "F"
    print(grade)
Buggy python submission (verdict: Runtime Error):
while(True):
    n, x = map(int, input().spilt())
    if n == 0 and x == 0:
        break
    else:
        cnt = 0
        for i in range(1, n+1):
            for k in range(i+1, n+1):
                for l in range(k+1, n+1):
                    if i + k + l == x:
                        cnt += 1
        print(cnt)


Fixed submission:
while(True):
    n, x = map(int, input().split())
    if n == 0 and x == 0:
        break
    else:
        cnt = 0
        for i in range(1, n+1):
            for k in range(i+1, n+1):
                for l in range(k+1, n+1):
                    if i + k + l == x:
                        cnt += 1
        print(cnt)
Buggy python submission (verdict: Runtime Error):
r, c = map(int, input().split())
table = []
for i in range(r):
    table.append(list(map(int, input().split())))
for i in table:
    i.append(sum(i))
b = []
for i in range(c):
    b.append(sum(list(table[i for i in range(r)])))
b.append(sum(b))
for i in table:
    print(" ".join(map(str, i)))
print(" ".join(map(str, b)))


Fixed submission:
r, c = map(int, input().split())
table = []
for i in range(r):
    table.append(list(map(int, input().split())))
for i in table:
    i.append(sum(i))
b = []
for i in range(c):
    x = 0
    for k in range(r):
        x += table[k][i]
    b.append(x)
b.append(sum(b))
for i in table:
    print(" ".join(map(str, i)))
print(" ".join(map(str, b)))

Buggy python submission (verdict: Runtime Error):
r, c = map(int, input().split())
table = []
for i in range(r):
    table.append(list(map(int, input().split())))
for i in table:
    i.append(sum(i))
b = []
for i in range(c):
    b.append(sum(list(table[k for k in range(r)])))
b.append(sum(b))
for i in table:
    print(" ".join(map(str, i)))
print(" ".join(map(str, b)))


Fixed submission:
r, c = map(int, input().split())
table = []
for i in range(r):
    table.append(list(map(int, input().split())))
for i in table:
    i.append(sum(i))
b = []
for i in range(c):
    x = 0
    for k in range(r):
        x += table[k][i]
    b.append(x)
b.append(sum(b))
for i in table:
    print(" ".join(map(str, i)))
print(" ".join(map(str, b)))

Buggy python submission (verdict: Runtime Error):
r, c = map(int, input().split())
table = []
for i in range(r):
    table.append(list(map(int, input().split())))
for i in table:
    i.append(sum(i))
b = []
for i in range(c):
    b.append(sum(list(table[i][k for k in range(r)])))
b.append(sum(b))
for i in table:
    print(" ".join(map(str, i)))
print(" ".join(map(str, b)))


Fixed submission:
r, c = map(int, input().split())
table = []
for i in range(r):
    table.append(list(map(int, input().split())))
for i in table:
    i.append(sum(i))
b = []
for i in range(c):
    x = 0
    for k in range(r):
        x += table[k][i]
    b.append(x)
b.append(sum(b))
for i in table:
    print(" ".join(map(str, i)))
print(" ".join(map(str, b)))

Buggy python submission (verdict: Runtime Error):
r, c = map(int, input().split())
table = []
for i in range(r):
    table.append(list(map(int, input().split())))
for i in table:
    i.append(sum(i))
b = []
for i in range(c):
    b.append(sum(list(table[k for k in range(r)][i])))
b.append(sum(b))
for i in table:
    print(" ".join(map(str, i)))
print(" ".join(map(str, b)))


Fixed submission:
r, c = map(int, input().split())
table = []
for i in range(r):
    table.append(list(map(int, input().split())))
for i in table:
    i.append(sum(i))
b = []
for i in range(c):
    x = 0
    for k in range(r):
        x += table[k][i]
    b.append(x)
b.append(sum(b))
for i in table:
    print(" ".join(map(str, i)))
print(" ".join(map(str, b)))
Buggy python submission (verdict: Runtime Error):
n, m, l = map(int, input().split())
a = []
b = []
c = []
for i in range(n):
    c.append([0 for k in range(l)])
for i in range(n):
    a.append(list(map(int, input().split())))
for i in range(m):
    b.append(list(map(int, input().split())))
for s in range(n):
    for t in range(m):
        elm = 0
        for u in range(l):
            elm += a[s][t] * b[t][u]
        c[s][t] = elm
for i in c:
    print(" ".join(str, i))


Fixed submission:
n, m, l = map(int, input().split())
a = []
b = []
c = []
for i in range(n):
    c.append([0 for k in range(l)])
for i in range(n):
    a.append(list(map(int, input().split())))
for i in range(m):
    b.append(list(map(int, input().split())))
for s in range(n):
    for t in range(l):
        elm = 0
        for u in range(m):
            elm += a[s][u] * b[u][t]
        c[s][t] = elm
for i in c:
    print(" ".join(map(str, i)))

Buggy python submission (verdict: Runtime Error):
n, m, l = map(int, input().split())
a = []
b = []
c = []
for i in range(n):
    c.append([0 for k in range(l)])
for i in range(n):
    a.append(list(map(int, input().split())))
for i in range(m):
    b.append(list(map(int, input().split())))
for s in range(n):
    for t in range(m):
        elm = 0
        for u in range(l):
            elm += a[s][t] * b[t][u]
        c[s][t] = elm
for i in c:
    print(" ".join(str, i))


Fixed submission:
n, m, l = map(int, input().split())
a = []
b = []
c = []
for i in range(n):
    c.append([0 for k in range(l)])
for i in range(n):
    a.append(list(map(int, input().split())))
for i in range(m):
    b.append(list(map(int, input().split())))
for s in range(n):
    for t in range(l):
        elm = 0
        for u in range(m):
            elm += a[s][u] * b[u][t]
        c[s][t] = elm
for i in c:
    print(" ".join(map(str, i)))
Buggy python submission (verdict: Runtime Error):
while(True):
    for i in input():
        x += int(i)
    print(x)


Fixed submission:
while(True):
    num = input()
    if num == '0':
        break
    x = 0
    for i in num:
        x += int(i)
    print(x)

Buggy python submission (verdict: Runtime Error):
while(True):
    x = 0
    for i in input():
        x += int(i)
    print(x)


Fixed submission:
while(True):
    num = input()
    if num == '0':
        break
    x = 0
    for i in num:
        x += int(i)
    print(x)
Buggy python submission (verdict: Runtime Error):
w = input()
cnt = 0
while(True):
    t = input()
    if t == "END_OF_TEXT":
        break
    t = list(map(lower, t.split()))
    for i in t:
        if i == w:
            cnt += 1
print(cnt)


Fixed submission:
w = input()
cnt = 0
while(True):
    t = input()
    if t == "END_OF_TEXT":
        break
    t = t.lower().split()
    for i in t:
        if i == w:
            cnt += 1
print(cnt)

Buggy python submission (verdict: Runtime Error):
w = input()
cnt = 0
while(True):
    t = input()
    if t == "END_OF_TEXT":
        break
    t = list(map(lower(), t.split()))
    for i in t:
        if i == w:
            cnt += 1
print(cnt)


Fixed submission:
w = input()
cnt = 0
while(True):
    t = input()
    if t == "END_OF_TEXT":
        break
    t = t.lower().split()
    for i in t:
        if i == w:
            cnt += 1
print(cnt)

Buggy python submission (verdict: Runtime Error):
w = input()
cnt = 0
while(True):
    t = input()
    if t == "END_OF_TEXT":
        break
    t = t.lower
    t = list(t.split())
    for i in t:
        if i == w:
            cnt += 1
print(cnt)


Fixed submission:
w = input()
cnt = 0
while(True):
    t = input()
    if t == "END_OF_TEXT":
        break
    t = t.lower().split()
    for i in t:
        if i == w:
            cnt += 1
print(cnt)

Buggy python submission (verdict: Runtime Error):
w = input()
cnt = 0
while(True):
    t = input()
    if t == "END_OF_TEXT":
        break
    t = t.lower
    t = t.split()
    for i in t:
        if i == w:
            cnt += 1
print(cnt)


Fixed submission:
w = input()
cnt = 0
while(True):
    t = input()
    if t == "END_OF_TEXT":
        break
    t = t.lower().split()
    for i in t:
        if i == w:
            cnt += 1
print(cnt)

Buggy python submission (verdict: Runtime Error):
w = input()
cnt = 0
while(True):
    t = input()
    if t == "END_OF_TEXT":
        break
    t = t.lower
    tlist = t.split()
    for i in tlist:
        if i == w:
            cnt += 1
print(cnt)


Fixed submission:
w = input()
cnt = 0
while(True):
    t = input()
    if t == "END_OF_TEXT":
        break
    t = t.lower().split()
    for i in t:
        if i == w:
            cnt += 1
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = []

for i in range(N):
	a.append(int(input()))

max_dist = -10e10

for i in range(N-1):
	for j in range(i + 1, N):
		if a[j] - a[i] > max_dist:
			max_dist = a[j] - a[i]

print(max_dist)


Fixed submission:
N = int(input())
a = []

for i in range(N):
	a.append(int(input()))

maxv = -10e10
minv = a[0]

for i in range(1, N):
	maxv = a[i] - minv if maxv < a[i] - minv else maxv
	minv = a[i] if minv > a[i] else minv

print(maxv)
Buggy python submission (verdict: Runtime Error):
a, b = [int(elem) for elem in input().split]
print(a * b, (a + b) * 2)


Fixed submission:
a, b = [int(elem) for elem in input().split()]
print(a * b, (a + b) * 2)
Buggy python submission (verdict: Runtime Error):
def is_float_str(num_str, default=0):
    try:
        return {"is_float": True, "val": float(num_str)}
    except ValueError:
        return {"is_float": False, "val": default}


def compute(operand, val1, val2):
    if operand == "+":
        return val1 + val2
    elif operand == "-":
        return val1 - val2
    elif operand == "*":
        return val1 * val2
    elif operand == "/":
        return val1 / val2


def get_input():
    while True:
        try:
            yield input()
        except EOFError:
            break


# split with ' '
formulas = list(get_input())
for (i, formula) in enumerate(formulas, 0):
    formulas[i] = formula.split(' ')
stack = []

for formula in formulas:
    for elm in formula:
        if is_float_str(elm)["is_float"]:
            stack.append(is_float_str(elm)["val"])
        elif elm in ['+', '-', '*', '/']:
            stack.append(compute(elm, stack.pop(), stack.pop()))

if len(stack) == 1:
    print(str(stack[0]) + '\n')


Fixed submission:
def is_float_str(num_str, default=0):
    try:
        return {"is_float": True, "val": float(num_str)}
    except ValueError:
        return {"is_float": False, "val": default}


def compute(operand, val1, val2):
    if operand == "+":
        return val2 + val1
    elif operand == "-":
        return val2 - val1
    elif operand == "*":
        return val2 * val1
    elif operand == "/":
        return val2 / val1


def get_input():
    while True:
        try:
            yield input()
        except EOFError:
            break


if __name__ == '__main__':
    # split with ' '
    formulas = list(get_input())
    for (i, formula) in enumerate(formulas, 0):
        formulas[i] = formula.split(' ')
    stack = []

    for formula in formulas:
        stack = []
        for elm in formula:
            if is_float_str(elm)["is_float"]:
                stack.append(is_float_str(elm)["val"])
            elif elm in ['+', '-', '*', '/']:
                stack.append(compute(elm, stack.pop(), stack.pop()))
        if len(stack) == 1:
            print(format(stack[0], '.6f'))
Buggy python submission (verdict: Runtime Error):
import itertools
while True:
	try: n=int(input())
	except EOEError: break
	ans=0
	for (i,j,k) in itertools.product(range(10),range(10),range(10)):
		ans+=(0<=n-(i+j+k)<=9)
	print(ans)



Fixed submission:
import itertools
while True:
	try: n=int(input())
	except EOFError: break
	ans=0
	for (i,j,k) in itertools.product(range(10),range(10),range(10)):
		ans+=(0<=n-(i+j+k)<=9)
	print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
def main():
	while True:
		n,m=map(int,input().split())
		if n==0 and m==0:
			break
		p=list()
		for i in range(n):
			p.append(int(input()))
		p.append(0)
		ls=list()
		for i in p:
			for j in p:
				if i+j<=m:
					ls.append(i+j)
		ans=0
		for x in ls:
			idx=bisect.bisect_right(ls,m-x)
			if idx==0:
				continue
			idx-=1
			ans=max(ans,x+ls[idx])

		print(ans)

if __name__=="__main__":
	main()



Fixed submission:
import bisect
def main():
	while True:
		n,m=map(int,input().split())
		if n==0 and m==0:
			break
		p=[0]+sorted([int(input()) for i in range(n)])
		s=list()
		for i in range(n+1):
			for j in p[i:]:
				if p[i]+j>m:
					break
				s+=[p[i]+j]
		s.sort()
		print(max(i+s[bisect.bisect_right(s,m-i)-1] for i in s))

if __name__=="__main__":
	main()
Buggy python submission (verdict: Runtime Error):
n=int(input())
*a=map(int,input().split())

for i in range(n):
	v=a[i]
	j=i-1
	while j>=0 and a[j]>v:
		a[j+1]=a[j]
		j-=1
	a[j+1]=v

	print(*a)



Fixed submission:
n=int(input())
a=list(map(int,input().split()))

for i in range(n):
	v=a[i]
	j=i-1
	while j>=0 and a[j]>v:
		a[j+1]=a[j]
		j-=1
	a[j+1]=v

	print(*a)