Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 9)

n = int(input())
LR = [tuple(map(int, input().split())) for _ in range(n)]

def quicksort(x):
    if x==[]: return []

    smallerSorted = quicksort([a for a in x[1:] if (a[0] < x[0][0] or (a[0] == x[0][0] and a[1] >= x[0][1])])
    biggerSorted = quicksort([a for a in x[1:] if (a[0] > x[0][0] or (a[0] == x[0][0] and a[1] < x[0][1]))])

    return(smallerSorted+[x[0]]+biggerSorted)

LR = quicksort(LR)

ans = [0] * (n+1)
temp = 10 ** 9
i = 1
for L, R in LR:
    temp = min(temp, R)
    if L > temp:
        break
    ans[i] = temp - L + 1
    i += 1
#print(ans)
temp = 10 ** 9
i = n - 1
L = LR[-1][0]
for x, R in reversed(LR):
    temp = min(temp, R)
    if L > temp:
        break
    ans[i] += temp - L + 1
    i -= 1

print(max(ans))

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 9)

n = int(input())
LR = [tuple(map(int, input().split())) for _ in range(n)]

def quicksort(x):
    if x==[]: return []

    smallerSorted = quicksort([a for a in x[1:] if a[0] < x[0][0] or (a[0] == x[0][0] and a[1] >= x[0][1])])
    biggerSorted = quicksort([a for a in x[1:] if a[0] > x[0][0] or (a[0] == x[0][0] and a[1] < x[0][1])])

    return(smallerSorted+[x[0]]+biggerSorted)

LR = quicksort(LR)

e = [[] for _ in range(n+2)]

ans = [0] * (n+1)
temp = 10 ** 9
i = 1
for L, R in LR:
    temp = min(temp, R)
    if L > temp:
        break
    ans[i] = temp - L + 1
    i += 1

temp = 10 ** 9
i = n - 1
L = LR[-1][0]
for x, R in reversed(LR):
    temp = min(temp, R)
    if L > temp:
        break
    ans[i] += temp - L + 1
    i -= 1

res = max(ans)
for L, R in LR:
    res = max(res, R - L + 1 + ans[0])

#print(LR)
#print(ans)
print(res)
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 6)

n, m = map(int, input().split())
e = [[] for _ in range(n)]

for _ in range(m):
    a, b = map(int, input().split())
    e[a-1].append(b-1)

c = [0] * n
def search_path(p, temp):
    c[p] = 1
    for x in e[p]:
        if x in temp:
            ans = [] + temp[temp.index(x):]
            check = 1
            while check == 1:
                check = 0
                #print(ans)
                for i in range(len(ans)-1):
                    for z in e[ans[i]]:
                        if z == ans[i+1]:
                            continue
                        elif z in ans:
                            t = ans.index(z)
                            if t < i:
                                ans = [] + ans[t:i+1]
                            else:
                                ans = [] + ans[i:t+1]
                            #print(ans, z)
                            check = 1
                            break
                    if check == 1:
                        break
                    else:
                        e[ans[i]] = []
                if check == 1:
                    continue
                for z in e[ans[-1]]:
                    if z == ans[0]:
                        continue
                    elif z in ans:
                        ans = [] + ans[ans.index(z):]
                        check = 1
                        #print(z, ans)
                        break
            print(len(ans))
            for z in ans:
                print(z+1)
            exit()
        else:
            search_path(x, temp + [x])


t = 1
for i in range(n):
    if c[i] == 0:
        ans = search_path(i, [i])

print(-1)

Fixed submission:
n = int(input())

if n % 2 == 0:
    print(0.5)
else:
    print(((n+1)//2)/n)
Buggy python submission (verdict: Time Limit Exceeded):
a, b = map(int, input().split())

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

n = gcd(a, b)

if n == 1:
    print(1)
    exit()

m = 2
ans = 1
while n > 1 and m <= n:
    if n % m == 0:
        ans += 1
        while n % m == 0:
            n //= m
    #print(n, m)
    m += 1

print(ans)


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

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

n = gcd(a, b)

if n == 1:
    print(1)
    exit()

m = 2
ans = 1
while m <= (n ** 0.5):
    if n % m == 0:
        ans += 1
        while n % m == 0:
            n //= m
    if n == 1:
        break
    m += 1

if n > 1:
    ans += 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())

dp = [float('inf') for _ in range(2 ** n)]
dp[0] = 0

for i in range(m):
    a, b = map(int, input().split())
    c = list(map(int, input().split()))
    k = 0
    p = 1
    for x in c:
        k += 2 ** (x-1)
    for j in range(2 ** n):
        L = j | k
        dp[L] = min(dp[L], dp[j] + a)

#print(dp)

if dp[-1] == float('inf'):
    print(-1)
else:
    print(dp[-1])

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

dp = [float('inf') for _ in range(2 ** n)]
dp[0] = 0

for i in range(m):
    a, b = map(int, input().split())
    c = list(map(int, input().split()))
    k = 0
    p = 1
    for x in c:
        k += 2 ** (x-1)
    for j in range(2 ** n):
        L = j | k
        dp[L] = min(dp[L], dp[j] + a)

#print(dp)

if dp[-1] == float('inf'):
    print(-1)
else:
    print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

def z_algorithm(str):
    len_str = len(str)
    p = [0] * len_str
    j = 0
    for i in range(1, len_str):
        if i + p[i-j] < j + p[j]:
            p[i] = p[i-j]
        else:
            k = max(0, j+p[j]-i)
            while i + k < len_str and str[k] == str[i+k] and k < i:
                k += 1
            p[i] = k
            j = i
    p[0] = 0
    return max(p)

ans = 0
for i in range(n-1):
    ans = max(ans, z_algorithm(s[i:]))

print(ans)

Fixed submission:
n = int(input())
s = input()

def z_algorithm(str):
    len_str = len(str)
    p = [0] * len_str
    j = 0
    for i in range(1, len_str):
        if i + p[i-j] < j + p[j]:
            p[i] = p[i-j]
        else:
            k = max(0, j+p[j]-i)
            while i + k < len_str and str[k] == str[i+k]:
                k += 1
            p[i] = k
            j = i
    p[0] = len_str
    return p

ans = 0
for x in range(n):
    temp = [] + z_algorithm(s[x:])
    for y in range(n - x):
        z = min(temp[y], y)
        ans = max(ans, z)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = list(input())

ans = 0
for i in range(n-1):
    for j in range(i+1, n):
        temp = 0
        for k in range(j - i):
            if j + k >= n:
                break
            if s[i+k] == s[j+k]:
                temp += 1
            else:
                break
        ans = max(temp, ans)

print(ans)


Fixed submission:
n = int(input())
s = input()

def z_algorithm(str):
    len_str = len(str)
    p = [0] * len_str
    j = 0
    for i in range(1, len_str):
        if i + p[i-j] < j + p[j]:
            p[i] = p[i-j]
        else:
            k = max(0, j+p[j]-i)
            while i + k < len_str and str[k] == str[i+k]:
                k += 1
            p[i] = k
            j = i
    p[0] = len_str
    return p

ans = 0
for x in range(n):
    temp = [] + z_algorithm(s[x:])
    for y in range(n - x):
        z = min(temp[y], y)
        ans = max(ans, z)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = list(input())

ans = 0
for i in range(n-1):
    for j in range(i+1, n):
        temp = 0
        for k in range(j - i):
            if j + k >= n:
                break
            if s[i+k] == s[j+k]:
                temp += 1
        ans = max(temp, ans)

print(ans)


Fixed submission:
n = int(input())
s = input()

def z_algorithm(str):
    len_str = len(str)
    p = [0] * len_str
    j = 0
    for i in range(1, len_str):
        if i + p[i-j] < j + p[j]:
            p[i] = p[i-j]
        else:
            k = max(0, j+p[j]-i)
            while i + k < len_str and str[k] == str[i+k]:
                k += 1
            p[i] = k
            j = i
    p[0] = len_str
    return p

ans = 0
for x in range(n):
    temp = [] + z_algorithm(s[x:])
    for y in range(n - x):
        z = min(temp[y], y)
        ans = max(ans, z)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left

n = int(input())
p = []

for i, x in enumerate(map(int, input().split())):
    p.append([x, i])

p.sort(reverse=True)

s = [-1, -1, p[0][1], n, n]

#print(p)

ans = 0
i = 2
for a, x in p[1:]:
    t = bisect_left(s, x)
    ans += a * ((x - s[t-1]) * (s[t+1] - s[t]) + (s[t] - x) * (s[t-1] - s[t-2]))
    #print(t, s)
    s.insert(t, x)
    i += 1


print(ans)




Fixed submission:
from bisect import bisect_left
import array

n = int(input())
p = []

for i, x in enumerate(map(int, input().split())):
    p.append([x, i])

p.sort(reverse=True)

s = array.array('i', [-1, -1, p[0][1], n, n])

#print(p)

ans = 0
i = 2
for a, x in p[1:]:
    t = bisect_left(s, x)
    ans += a * ((x - s[t-1]) * (s[t+1] - s[t]) + (s[t] - x) * (s[t-1] - s[t-2]))
    #print(t, s)
    s.insert(t, x)
    i += 1


print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left

n = int(input())
p = []

for i, x in enumerate(map(int, input().split())):
    p.append([x, i])

p.sort(reverse=True)

s = [-1, -1, p[0][1], n, n]

#print(p)

ans = 0
i = 2
for a, x in p[1:]:
    t = bisect_left(s, x)
    ans += a * ((x - s[t-1]) * (s[t+1] - s[t]) + (s[t] - x) * (s[t-1] - s[t-2]))
    #print(t, s)
    s.insert(t, x)
    i += 1


print(ans)




Fixed submission:
from bisect import bisect_left
import array

n = int(input())
p = []

for i, x in enumerate(map(int, input().split())):
    p.append([x, i])

p.sort(reverse=True)

s = array.array('i', [-1, -1, p[0][1], n, n])

#print(p)

ans = 0
i = 2
for a, x in p[1:]:
    t = bisect_left(s, x)
    ans += a * ((x - s[t-1]) * (s[t+1] - s[t]) + (s[t] - x) * (s[t-1] - s[t-2]))
    #print(t, s)
    s.insert(t, x)
    i += 1


print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = list(map(int, input().split()))

dp = [[0 for _ in range(2 ** n)] for _ in range(18)]
dp[0] = [] + s

#for x in dp: print(x)

m = (n-1) ** 2
for a in range(n):
    #print(dp[a])
    for i in range(1 << (n-a-1)):
        #print(a, i)
        if dp[a][i*2] == dp[a][i*2+1]:
            print('No')
            exit()
        else:
            dp[a+1][i] = max(dp[a][i*2], dp[a][i*2+1])
    #m //= 2
    #print(dp[a+1])

print('Yes')

Fixed submission:
n = int(input())
s = [list(map(int, input().split()))]

s[0].sort(reverse=True)

t = [s[0].pop(0)]
s.append([0 for _ in range(2 ** n - 1)])
a = 0
b = 1
p = 1
q = 2 ** n - 1
for _ in range(n):
    #print(s)
    j = 0
    k = 0
    for i in range(p):
        if j >= q:
            print('No')
            exit()
        #print(i, t, s)
        while t[i] <= s[a][j]:
            s[b][k] = s[a][j]
            j += 1
            k += 1
            if j >= q:
                print('No')
                exit()
        t.append(s[a][j])
        j += 1
    t.sort(reverse=True)

    #print(i, j, q)
    while j < q:
        s[b][k] = s[a][j]
        k += 1
        j += 1
    a, b = b, a
    #print(s)
    q -= p
    p *= 2
print('Yes')
Buggy python submission (verdict: Time Limit Exceeded):
from copy import deepcopy

n = int(input())
a = [list(map(lambda x:int(x) - 1, input().split())) for _ in range(n)]

d = [0] * n

ans = 0
temp = set([x for x in range(n)])
while 1:
    next_temp = set()
    for t in temp:
        if d[t] >= n - 1:
            continue
        u = a[t][d[t]]
        if a[u][d[u]] == t:
            next_temp.add(t)
            next_temp.add(u)
    #print(next_temp, d)
    for t in next_temp:
        d[t] += 1
    if len(next_temp) == 0:
        break
    temp = deepcopy(next_temp)
    ans += 1

if d.count(n-1) == n:
    print(ans)
else:
    print(-1)

Fixed submission:
from copy import deepcopy
from heapq import heappop, heappush

n = int(input())
a = [list(map(lambda x:int(x) - 1, input().split())) for _ in range(n)]

d = [0] * n

ans = 0
temp = []
for x in range(n):
    heappush(temp, x)
while 1:
    next_temp = []
    while len(temp) > 0:
        x = heappop(temp)
        if d[x] >= n-1:
            continue
        y = a[x][d[x]]
        #print(x, y)
        if y not in next_temp:
            if a[y][d[y]] == x:
                heappush(next_temp, x)
                heappush(next_temp, y)
    #print(next_temp)
    for t in next_temp:
        d[t] += 1
    if len(next_temp) == 0:
        break
    temp = [] + next_temp
    ans += 1

#print(d)

if d.count(n-1) == n:
    print(ans)
else:
    print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
from copy import deepcopy

n = int(input())
a = [list(map(lambda x:int(x) - 1, input().split())) for _ in range(n)]

d = [0] * n

ans = 0
temp = set([x for x in range(n)])
while 1:
    next_temp = set()
    for t in temp:
        if d[t] >= n - 1:
            continue
        u = a[t][d[t]]
        if a[u][d[u]] == t:
            next_temp.add(t)
            next_temp.add(u)
    #print(next_temp, d)
    for t in next_temp:
        d[t] += 1
    if len(next_temp) == 0:
        break
    temp = deepcopy(next_temp)
    ans += 1

if d.count(n-1) == n:
    print(ans)
else:
    print(-1)

Fixed submission:
from copy import deepcopy
from heapq import heappop, heappush

n = int(input())
a = [list(map(lambda x:int(x) - 1, input().split())) for _ in range(n)]

d = [0] * n

ans = 0
temp = []
for x in range(n):
    heappush(temp, x)
while 1:
    next_temp = []
    while len(temp) > 0:
        x = heappop(temp)
        if d[x] >= n-1:
            continue
        y = a[x][d[x]]
        #print(x, y)
        if y not in next_temp:
            if a[y][d[y]] == x:
                heappush(next_temp, x)
                heappush(next_temp, y)
    #print(next_temp)
    for t in next_temp:
        d[t] += 1
    if len(next_temp) == 0:
        break
    temp = [] + next_temp
    ans += 1

#print(d)

if d.count(n-1) == n:
    print(ans)
else:
    print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
from operator import itemgetter

n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]

d = [0] * (m+1)

ab.sort(key=itemgetter(1), reverse=True)

for a, b in ab:
    x = m - a
    while x >= 0:
        if d[x] == 0:
            d[x] = b
            break
        x -= 1

print(sum(d))

Fixed submission:
from heapq import heappop, heappush

n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]

h = []

ans = 0

ab.sort()
i = 0
for d in range(1, m+1):
    while i < n:
        if ab[i][0] <= d:
            heappush(h, - ab[i][1])
            i += 1
        else:
            break
    if len(h) > 0:
        ans -= heappop(h)

print(ans)
Buggy python submission (verdict: Runtime Error):
k = int(input())
x, y = map(int, input().split())

if k % 2 == 0 and (x + y) % 2 == 1:
    print(-1)
    exit()

a = 1
b = 1
d = 0
if x < 0:
    x *= -1
    a = -1
if y < 0:
    y *= -1
    b = -1
if x < y:
    d = 1
    x, y = y, x

def show_xy(tx, ty):
    if d == 1:
        print(ty * a, tx * b)
    else:
        print(tx * a, ty * b)

if x + y < k and (x + y) % 2 == 1:
    f = [0,0]
    print(f[99])
    exit()
    temp_x = x
    temp_y = x - k
    show_xy(temp_x, temp_y)
    temp_x = x + (k+x-y)//2
    temp_y += k - (k+x-y)//2
    show_xy(temp_x, temp_y)
    temp_x = x
    temp_y = y
    show_xy(temp_x, temp_y)
    exit()

c = (k - (x + y) % k) % k
if x + y < k:
    n = 2
else:
    n = (x + y) // k + (c % 2)
    if (x + y) // k != 0:
        n += 1

print(n)

ans = 0
temp_x = 0
temp_y = 0

temp = - (k * n - x - y) // 2
while 1:
    temp_y -= k
    if temp_y >=  temp:
        show_xy(temp_x, temp_y)
    else:
        temp_x = temp - temp_y
        temp_y = temp
        #print(temp_x * a, temp_y * b)
        break

while temp_x <= x:
    show_xy(temp_x, temp_y)
    temp_x += k

temp_y += temp_x - x
temp_x = x

while temp_y <= y:
    show_xy(temp_x, temp_y)
    temp_y += k


Fixed submission:
import math

k = int(input())
x, y = map(int, input().split())

if k % 2 == 0 and (x + y) % 2 == 1:
    print(-1)
    exit()

a = 1
b = 1
d = 0
if x < 0:
    x *= -1
    a = -1
if y < 0:
    y *= -1
    b = -1
if x < y:
    d = 1
    x, y = y, x

def show_xy(tx, ty):
    if d == 1:
        print(ty * a, tx * b)
    else:
        print(tx * a, ty * b)

if x + y < k and (x + y) % 2 == 1:
    print(3)
    temp_x = x
    temp_y = x - k
    show_xy(temp_x, temp_y)
    temp_x = x + (k+x-y)//2
    temp_y += k - (k+x-y)//2
    show_xy(temp_x, temp_y)
    temp_x = x
    temp_y = y
    show_xy(temp_x, temp_y)
    exit()

c = (k - ((x + y) % k)) % k
if x + y < k:
    n = 2
else:
    n = math.ceil((x + y) / k) + (c % 2)

print(n)

ans = 0
temp_x = 0
temp_y = 0

temp = - (k * n - x - y) // 2
while 1:
    temp_y -= k
    if temp_y >=  temp:
        show_xy(temp_x, temp_y)
    else:
        temp_x = temp - temp_y
        temp_y = temp
        #print(temp_x * a, temp_y * b)
        break

while temp_x <= x:
    show_xy(temp_x, temp_y)
    temp_x += k

temp_y += temp_x - x
temp_x = x

while temp_y <= y:
    show_xy(temp_x, temp_y)
    temp_y += k
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))

c = set(a)
if len(c) > 3:
    print('No')
    exit()

c = list(c).sort()
if len(c) == 1:
    if c[0] == 0:
        print('Yes')
    else:
        print('No')
elif len(c) == 2:
    if c[0] == 0 and a.count(0) * 2 == a.count(c[1]):
        print('Yes')
    else:
        print('No')
else:
    if c[0] ^ c[1] == c[2] and a.count(c[0]) == a.count(c[1]) and a.count(c[1]) == a.count(c[2]):
        print('Yes')
    else:
        print('No')



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

c = list(set(a))
c.sort()
if len(c) > 3:
    print('No')
    exit()

if len(c) == 1:
    if c[0] == 0:
        print('Yes')
    else:
        print('No')
elif len(c) == 2:
    if c[0] == 0 and a.count(0) * 2 == a.count(c[1]):
        print('Yes')
    else:
        print('No')
else:
    if c[0] ^ c[1] == c[2] and a.count(c[0]) == a.count(c[1]) and a.count(c[1]) == a.count(c[2]):
        print('Yes')
    else:
        print('No')
Buggy python submission (verdict: Runtime Error):
a, b, c, d = map(int, input().split())

def gcd(n, m):
	while m:
		n, m = m, n % m
	return n

def lcm(n, m):
	return n * m // gcd (n, m)

if c == 1 or d == 1:
    print(hoge)
    print(b - a + 1)
    exit()

if a == 1:
    div_a = 0
else:
    div_a = (a-1) // c + (a-1) // d - (a-1) // lcm(c, d)
div_b = b // c + b // d - b // lcm(c, d)

print(b - a + 1 - div_b + div_a)

Fixed submission:
a, b, c, d = map(int, input().split())

def gcd(n, m):
	while m:
		n, m = m, n % m
	return n

def lcm(n, m):
	return n * m // gcd (n, m)

if c == 1 or d == 1:
    print(0)
    exit()

if a == 1:
    div_a = 0
else:
    div_a = (a-1) // c + (a-1) // d - (a-1) // lcm(c, d)
div_b = b // c + b // d - b // lcm(c, d)

print(b - a + 1 - div_b + div_a)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())

if k == 0:
    print(hoge)
    exit()

if k > (n - 1) * (n - 2) // 2:
    print(-1)
    exit()

ans = [[0 for _ in range(n)] for _ in range(n)]

for i in range(1, n):
    ans[0][i] = 1

m = n-1

temp = (n-1) * (n-2) // 2 - k
for i in range(1, n):
    for j in range(i+1, n):
        ans[i][j] = 1
        m += 1
        temp -= 1
        if temp == 0:
            break
    if temp == 0:
        break

print(m)
for i in range(n):
    for j in range(n):
        if ans[i][j] == 1:
            print(i+1, j+1)

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

if k > (n - 1) * (n - 2) // 2:
    print(-1)
    exit()

ans = [[0 for _ in range(n)] for _ in range(n)]

for i in range(1, n):
    ans[0][i] = 1

m = n-1

temp = (n-1) * (n-2) // 2 - k
for i in range(1, n):
    if temp == 0:
        break
    for j in range(i+1, n):
        ans[i][j] = 1
        m += 1
        temp -= 1
        if temp == 0:
            break

print(m)
for i in range(n):
    for j in range(n):
        if ans[i][j] == 1:
            print(i+1, j+1)
Buggy python submission (verdict: Runtime Error):
from heapq import heappop, heappush

n, m = map(int, input().split())
a = list(map(int, input().split()))
bc = [tuple(int(x) for x in input().split()) for _ in range(m)]

h = []

for x in a:
    heappush(h, x)

for b, c in bc:
    for _ in range(b):
        temp = heappop(h)
        if temp >= c:
            heappush(h, temp)
            break
        else:
            heappush(h, c)

print(sum(h))

from heapq import heappop, heappush

n, m = map(int, input().split())
a = list(map(int, input().split()))
bc = [tuple(int(x) for x in input().split()) for _ in range(m)]

h = []

for x in a:
    heappush(h, x)

for b, c in bc:
    for _ in range(b):
        temp = heappop(h)
        if temp >= c:
            heappush(h, temp)
            break
        else:
            heappush(h, c)

print(sum(h))



Fixed submission:
from heapq import heappop, heappush

n, m = map(int, input().split())
a = list(map(int, input().split()))
bc = [tuple(int(x) for x in input().split()) for _ in range(m)]

bc.sort(reverse=True)

h = []

for x in a:
    heappush(h, x)

for b, c in bc:
    for _ in range(b):
        temp = heappop(h)
        if temp >= c:
            heappush(h, temp)
            break
        else:
            heappush(h, c)

print(sum(h))

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappop, heappush

n, m = map(int, input().split())
a = list(map(int, input().split()))
bc = [tuple(int(x) for x in input().split()) for _ in range(m)]

h = []

for x in a:
    heappush(h, x)

for b, c in bc:
    for _ in range(b):
        temp = heappop(h)
        if temp >= c:
            heappush(h, temp)
            break
        else:
            heappush(h, c)

print(sum(h))



Fixed submission:
from heapq import heappop, heappush

n, m = map(int, input().split())
a = list(map(int, input().split()))
bc = [tuple(int(x) for x in input().split()) for _ in range(m)]

bc.sort(reverse=True)

h = []

for x in a:
    heappush(h, x)

for b, c in bc:
    for _ in range(b):
        temp = heappop(h)
        if temp >= c:
            heappush(h, temp)
            break
        else:
            heappush(h, c)

print(sum(h))
Buggy python submission (verdict: Runtime Error):
n = int(input())
uvw = [tuple(int(x) for x in input().split()) for _ in range(n-1)]

c = [-1] * n

r = [[] for _ in range(n)]

for u, v, w in uvw:
    r[u-1].append([v-1, w])
    r[v-1].append([u-1, w])

def f(p):
    count = 0
    for x, w in r[p]:
        if c[x] == -1:
            if w % 2 == 0:
                c[x] = c[p]
                f(x)
            else:
                c[x] = (c[p] + 1) % 2
                f(x)
            count += 1
    #print(count)

c[0] = 0
f(0)

for x in c:
    print(x)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 5)

n = int(input())
uvw = [tuple(int(x) for x in input().split()) for _ in range(n-1)]

c = [-1] * n

r = [[] for _ in range(n)]

for u, v, w in uvw:
    r[u-1].append([v-1, w])
    r[v-1].append([u-1, w])

def f(p):
    count = 0
    for x, w in r[p]:
        if c[x] == -1:
            if w % 2 == 0:
                c[x] = c[p]
                f(x)
            else:
                c[x] = (c[p] + 1) % 2
                f(x)
            count += 1
    #print(count)

c[0] = 0
f(0)

for x in c:
    print(x)
Buggy python submission (verdict: Runtime Error):
n = int(input())

ans = 0
x = 1

while x < n:
    if n % x == 0:
        m = n // x - 1
        if m <= x:
            break
        else:
            ans += m
    x += 1

print(ans)

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

print(n - k + 1)