Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
lis = [int(input()) for _ in range(N)]
l_copy = lis.copy()

for i in lis:
    lis = l_copy.copy()
    lis.remove(i)
    print(max(lis))



Fixed submission:
N = int(input())
lis = [int(input()) for _ in range(N)]
lis_c = lis.copy()

mx1 = max(lis_c)
lis_c.remove(mx1)
mx2 = max(lis_c)

for i in lis:
    if i == mx1:
        print(mx2)
    else:
        print(mx1)
Buggy python submission (verdict: Runtime Error):
N = int(input())
lis = [(input() + " " + str(i+1)).split() for i in range(N)]

lis = [k for k in lis]

lis.sort(key=lambda k: int(k[1]), reverse=True)
lis.sort(key=lambda k: k[0])


for j in lis:
    print(j[2])
N = int(input())
lis = [(input() + " " + str(i+1)).split() for i in range(N)]

lis = [k for k in lis]

lis.sort(key=lambda k: int(k[1]), reverse=True)
lis.sort(key=lambda k: k[0])


for j in lis:
    print(j[2])


Fixed submission:
N = int(input())
lis = [(input() + " " + str(i+1)).split() for i in range(N)]

lis = [k for k in lis]

lis.sort(key=lambda k: int(k[1]), reverse=True)
lis.sort(key=lambda k: k[0])


for j in lis:
    print(j[2])
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
dic = {i:0 for i in range(1, N+1)}
c = 0

for i in range(M):
    L, R = map(int, input().split())
    for j in range(L, R+1):
        dic[j] = dic[j] + 1

for id, val in dic.items():
    if val == M:
        c += 1

print(c)

Fixed submission:
N, M = map(int, input().split())
L = 0
R = N

for i in range(M):
    L_new, R_new = map(int, input().split())
    if L < L_new:
        L = L_new
    if R_new < R:
        R = R_new

if L > R:
    print(0)
else:
    print(R-L+1)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
shop = [list(map(int, input().split())) for _ in range(N)]
drink = 0
money = 0

shop.sort(key=lambda x: x[0])

for i in range(N):
    if drink + shop[i][1] <= M:
        drink += shop[i][1]
        money += shop[i][0] * shop[i][1]
        if drink == M:
            print(money)
            break
    else:
        for j in range(shop[i][1]):
            drink += 1
            money += shop[i][0]
            if drink == M:
                print(money)
                break



Fixed submission:
from bisect import bisect_left
from itertools import accumulate

N, M = map(int, input().split())
shop = [list(map(int, input().split())) for _ in range(N)]
shop.sort(key=lambda x: x[0])

cnt = 0
ans = 0

for i in range(N):
    cnt += shop[i][1]
    if M <= cnt:
        dif = cnt - M
        ans += shop[i][0] * shop[i][1] - dif * shop[i][0]
        break
    else:
        ans += shop[i][0] * shop[i][1]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
shop = [list(map(int, input().split())) for _ in range(N)]
drink = 0
money = 0

shop.sort(key=lambda x: x[0])

for i in range(N):
    for j in range(shop[i][1]):
        drink += 1
        money += shop[i][0]
        if drink == M:
            print(money)
            break




Fixed submission:
from bisect import bisect_left
from itertools import accumulate

N, M = map(int, input().split())
shop = [list(map(int, input().split())) for _ in range(N)]
shop.sort(key=lambda x: x[0])

cnt = 0
ans = 0

for i in range(N):
    cnt += shop[i][1]
    if M <= cnt:
        dif = cnt - M
        ans += shop[i][0] * shop[i][1] - dif * shop[i][0]
        break
    else:
        ans += shop[i][0] * shop[i][1]

print(ans)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
H = [int(input()) for _ in range(N)]
H.sort()
df = 0
min_h = H[K-1]-H[0]

for i in range(1, K):
    new_h = H[i+K-1]-H[i]
    if new_h < min_h:
        min_h = new_h

print(min_h)


Fixed submission:
N, K = map(int, input().split())
H = [int(input()) for _ in range(N)]
H.sort()
df = 0
min_h = H[K-1]-H[0]

for i in range(1, N-K+1):
    new_h = H[i+K-1]-H[i]
    if new_h < min_h:
        min_h = new_h

print(min_h)
Buggy python submission (verdict: Time Limit Exceeded):
A, B, K = map(int, input().split())

left = A+K-1
right = B-K+1

if left < right:
    for i in range(A, B+1):
        if i <= left or right <= i:
            print(i)
else:
    for i in range(A, B+1):
        print(i)


Fixed submission:
A, B, K = map(int, input().split())
if B-A+1 >= 2*K: # A以上B以下の整数の数が2K以上
    res_list = [i for i in range(A, A+K)] + [i for i in range(B-K+1, B+1)]
else: # A以上B以下の整数の数が2K未満
    res_list = [i for i in range(A, B+1)]
for i in res_list:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
A, B, K = map(int, input().split())

left = A+K-1
right = B-K+1

if left < right:
    l1 = [i for i in range(A, B + 1) if i <= left or right <= i ]
else:
    l1 = [i for i in range(A, B+1)]

for i in l1:
    print(i)



Fixed submission:
A, B, K = map(int, input().split())
if B-A+1 >= 2*K: # A以上B以下の整数の数が2K以上
    res_list = [i for i in range(A, A+K)] + [i for i in range(B-K+1, B+1)]
else: # A以上B以下の整数の数が2K未満
    res_list = [i for i in range(A, B+1)]
for i in res_list:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
A, B, K = map(int, input().split())
l1 = [i for i in range(A, B+1) if B-K+1 <= i]
l2 = [i for i in range(A, B+1) if i <= A+K-1]

ans = list(set(l1) | set(l2))
ans.sort()

for i in ans:
    print(i)

Fixed submission:
A, B, K = map(int, input().split())
if B-A+1 >= 2*K: # A以上B以下の整数の数が2K以上
    res_list = [i for i in range(A, A+K)] + [i for i in range(B-K+1, B+1)]
else: # A以上B以下の整数の数が2K未満
    res_list = [i for i in range(A, B+1)]
for i in res_list:
    print(i)
Buggy python submission (verdict: Runtime Error):
N = int(input())
lank = [0, 0, 0, 0, 0, 0, 0, 0]
a = list(map(int, input().split()))

for i in range(N):
    if 1 <= a[i] <= 399:
        lank[0] = 1
    elif 400 <= a[i] <= 799:
        lank[1] = 1
    elif 800 <= a[i] <= 1199:
        lank[2] = 1
    elif 1200 <= a[i] <= 1599:
        lank[3] = 1
    elif 1600 <= a[i] <= 1999:
        lank[4] = 1
    elif 2000 <= a[i] <= 2399:
        lank[5] = 1
    elif 2400 <= a[i] <= 2799:
        lank[6] = 1
    elif 2800 <= a[i] <= 3199:
        lank[7] = 1
    else:
        idx = lank.index(0)
        lank[idx] = 2

number_min = lank.count(1)
number_max = lank.count(1) + lank.count(2)

print(number_min, number_max)

Fixed submission:
N = int(input())
lank = [0, 0, 0, 0, 0, 0, 0, 0]
a = list(map(int, input().split()))
cnt = 0

for i in range(N):
    if 1 <= a[i] <= 399:
        lank[0] = 1
    elif 400 <= a[i] <= 799:
        lank[1] = 1
    elif 800 <= a[i] <= 1199:
        lank[2] = 1
    elif 1200 <= a[i] <= 1599:
        lank[3] = 1
    elif 1600 <= a[i] <= 1999:
        lank[4] = 1
    elif 2000 <= a[i] <= 2399:
        lank[5] = 1
    elif 2400 <= a[i] <= 2799:
        lank[6] = 1
    elif 2800 <= a[i] <= 3199:
        lank[7] = 1
    else:
        cnt += 1

number_min = max(1, lank.count(1))
number_max = lank.count(1) + cnt

print(number_min, number_max)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
ans = 1

for i in range(1, N+1):
    ans *= i

print(ans % (10**9+7))

Fixed submission:
N = int(input())
ans = 1

for i in range(1, N+1):
    ans = i * ans % (10**9+7)

print(ans)
Buggy python submission (verdict: Runtime Error):
A, B, C = map(int, input().split())

if any(i % 2 == 0 for i in [A, B, C]):
    print(0)
else:
    AB = A * B
    lis = [AB] * C
    mid = len(lis) // 2
    print(sum(lis[mid:]) - sum(lis[0:mid]))


Fixed submission:
A, B, C = map(int, input().split())

if any(i % 2 == 0 for i in [A, B, C]):
    print(0)
else:
    print(min(A*B, B*C, C*A))

Buggy python submission (verdict: Time Limit Exceeded):
A, B, C = map(int, input().split())

if any(i % 2 == 0 for i in [A, B, C]):
    print(0)
else:
    AB = A * B
    lis = [AB for i in range(C)]
    mid = len(lis) // 2
    print(sum(lis[mid:]) - sum(lis[0:mid]))


Fixed submission:
A, B, C = map(int, input().split())

if any(i % 2 == 0 for i in [A, B, C]):
    print(0)
else:
    print(min(A*B, B*C, C*A))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
from math import factorial


def perm(n, r):
    return factorial(n) // factorial(n - r)


def comb(n, r):
    if n < r:
        return 0
    return perm(n, r) // factorial(r)


N = int(input())
A = list(map(int, input().split()))
C = Counter(A)
D = {k: comb(v, 2) for k, v in C.items()}
_all = sum(D.values())
for a in A:
    print(_all - D[a] + comb(C[a] - 1, 2))


Fixed submission:
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
C = Counter(A)
combinations = [0] + [c * (c - 1) // 2 for c in range(1, 1 + max(C.values()))]
_all = sum([combinations[c] for c in C.values()])
for a in A:
    print(_all - combinations[C[a]] + combinations[C[a] - 1])
Buggy python submission (verdict: Runtime Error):
S = input()
ok = True
for i in range(0, len(S), 2):
    if not (S[i] == "h" and S[i + 1] == "i"):
        ok = False
        break
print("Yes" if ok else "No")


Fixed submission:
S = input()
ok = True
for i in range(0, len(S), 2):
    try:
        if not (S[i] == "h" and S[i + 1] == "i"):
            ok = False
            break
    except IndexError:
        ok = False
        break
print("Yes" if ok else "No")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

ans = 0
i = 0
while i < len(A):
    if (i + 1) == A[i]:
        i += 1
    else:
        A.pop(i)
        ans += 1

if A:
    print(ans)
else:
    print(-1)


Fixed submission:
N = int(input())
A = list(map(int, input().split()))

ans = 0
num = 1
for a in A:
    if a == num:
        num += 1
    else:
        ans += 1

if ans == N:
    ans = -1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
A = [0] + A
ans = 0
i = 1
while i < len(A):
    if A[i] == i:
        i += 1
    else:
        ans += 1
        A.pop(i)
if ans >= N:
    ans = -1
print(ans)


Fixed submission:
N = int(input())
A = list(map(int, input().split()))

ans = 0
num = 1
for a in A:
    if a == num:
        num += 1
    else:
        ans += 1

if ans == N:
    ans = -1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
A = [0] + A
ans = 0
i = 1
while i < len(A):
    if A[i] == i:
        i += 1
    else:
        ans += 1
        A.pop(i)
if ans >= N:
    ans = -1
print(ans)


Fixed submission:
N = int(input())
A = list(map(int, input().split()))

ans = 0
num = 1
for a in A:
    if a == num:
        num += 1
    else:
        ans += 1

if ans == N:
    ans = -1

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

n = int(input())
A = list(map(int, input().split()))

sum_even = sum(A[::2])
sum_odd = sum(A[1::2]) + A[0]
ANS = A[:]
A = deque(A)
minus = False
for _ in range(n - 1):
    A.rotate(-1)
    for i in range(n):
        if minus:
            ANS[i] -= A[i]
        else:
            ANS[i] += A[i]
    minus = not minus
ANS = deque(ANS)
ANS.rotate()
print(*ANS)


Fixed submission:
from collections import deque

n = int(input())
A = list(map(int, input().split()))

B = [0] * n
B[0] = A[0]
B[1] = A[1]
for i in range(2, n):
    B[i] = B[i - 2] + A[i]

ANS = [0] * n
for i in range(n):
    ans = 0
    if i % 2 == 0:
        ans += B[-1] - B[-2]
    else:
        ans += B[-2] - B[-1]

    if i - 2 >= 0:
        ans -= B[i - 2] * 2

    if i - 1 >= 0:
        ans += B[i - 1] * 2

    ANS[i] = ans

print(*ANS)
Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())
M = [input() for _ in range(H)]

S = [[0] * W for _ in range(H)]
for i in range(H):
    for j in range(W):
        if M[i][j] == ".":
            if j > 0:
                S[i][j] = S[i][j - 1] + 1
            else:
                S[i][j] = 1
    for j in range(W - 2, -1, -1):
        S[i][j] = max(S[i][j], S[i][j + 1]) * (1 if S[i][j] else 0)

T = [[0] * W for _ in range(H)]
for j in range(W):
    for i in range(H):
        if M[i][j] == ".":
            if i > 0:
                T[i][j] = T[i - 1][j] + 1
            else:
                T[i][j] = 1
    for i in range(H - 2, -1, -1):
        T[i][j] = max(T[i][j], T[i + 1][j]) * (1 if T[i][j] else 0)

ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, S[i][j] + T[i][j] - 1)
print(ans)


Fixed submission:
H, W = map(int, input().split())
M = [input() for _ in range(H)]

S = [[0] * W for _ in range(H)]
for i in range(H):
    for j in range(W):
        if M[i][j] == ".":
            if j > 0:
                S[i][j] = S[i][j - 1] + 1
            else:
                S[i][j] = 1
    for j in range(W - 2, -1, -1):
        S[i][j] = max(S[i][j], S[i][j + 1]) * (1 if S[i][j] else 0)

T = [[0] * W for _ in range(H)]
for j in range(W):
    for i in range(H):
        if M[i][j] == ".":
            if i > 0:
                T[i][j] = T[i - 1][j] + 1
            else:
                T[i][j] = 1
    for i in range(H - 2, -1, -1):
        T[i][j] = max(T[i][j], T[i + 1][j]) * (1 if T[i][j] else 0)

ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, S[i][j] + T[i][j] - 1)
print(ans)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))
BC = [None] * M
for i in range(M):
    BC[i] = tuple(map(int, input().split()))
BC.sort(key=lambda tpl: tpl[1], reverse=True)  # sort by C descendant

D = [0] * N
i = 0
j = 0
while i < N and j < M:
    b, c = BC[j]
    for k in range(i, min(i + b, N)):
        D[k] = c
    i += b
    j += 1

for i in range(N):
    A[i] = max(A[i], D[i])

print(sum(A))


Fixed submission:
A, B = map(int, input().split())


def f():
    if A <= 5:
        return 0
    elif 6 <= A <= 12:
        return B // 2
    else:
        return B


print(f())
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))
BC = [None] * M
for i in range(M):
    BC[i] = tuple(map(int, input().split()))
BC.sort(key=lambda tpl: tpl[1], reverse=True)  # sort by C descendant

D = [0] * N
i = 0
j = 0
while i < N and j < M:
    b, c = BC[j]
    for k in range(i, i + b):
        D[k] = c
    i += b
    j += 1

for i in range(N):
    A[i] = max(A[i], D[i])

print(sum(A))


Fixed submission:
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))
BC = [None] * M
for i in range(M):
    BC[i] = tuple(map(int, input().split()))
BC.sort(key=lambda tpl: tpl[1], reverse=True)  # sort by C descendant

D = [0] * N
i = 0
j = 0
while i < N and j < M:
    b, c = BC[j]
    for k in range(i, min(i + b, N)):
        D[k] = c
    i += b
    j += 1

for i in range(N):
    A[i] = max(A[i], D[i])

print(sum(A))

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))
BC = [None] * M
for i in range(M):
    BC[i] = tuple(map(int, input().split()))
BC.sort(key=lambda tpl: tpl[1], reverse=True)  # sort by C descendant

D = [0] * N
i = 0
j = 0
while i < N and j < M:
    b, c = BC[j]
    for k in range(i, i + b):
        D[k] = c
    i += b
    j += 1

for i in range(N):
    A[i] = max(A[i], D[i])

print(sum(A))


Fixed submission:
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))
BC = [None] * M
for i in range(M):
    BC[i] = tuple(map(int, input().split()))
BC.sort(key=lambda tpl: tpl[1], reverse=True)  # sort by C descendant

D = [0] * N
i = 0
j = 0
while i < N and j < M:
    b, c = BC[j]
    for k in range(i, min(i + b, N)):
        D[k] = c
    i += b
    j += 1

for i in range(N):
    A[i] = max(A[i], D[i])

print(sum(A))
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()

W = [0] * N
W[-1] += S[-1] == "."
for i in range(N - 2, -1, -1):
    W[i] = W[i + 1] + (S[i] == ".")

B = [0] * N
B[0] += S[0] == "#"
for i in range(1, N):
    B[i] = B[i - 1] + (S[i] == "#")

T = [w + b for w, b in zip(W, B)]
print(min(*T, W[0], B[-1]))


Fixed submission:
N = int(input())
S = input()

W = [0] * N
W[-1] += S[-1] == "."
for i in range(N - 2, -1, -1):
    W[i] = W[i + 1] + (S[i] == ".")

B = [0] * N
B[0] += S[0] == "#"
for i in range(1, N):
    B[i] = B[i - 1] + (S[i] == "#")

T = [w + b - 1 for w, b in zip(W, B)]
T = min(T)
print(min(T, W[0], B[-1]))
Buggy python submission (verdict: Runtime Error):
A = [int(input()) for _ in range(5)]
ans = 0
I = [i for i, a in enumerate(A) if a % 10 == 0]
for i in reversed(I):
    ans += A.pop(i)
A.sort(key=lambda a: a % 10)
ans += A.pop(0)
for i in range(len(A)):
    A[i] += 10 - (A[i] % 10)
ans += sum(A)
print(ans)


Fixed submission:
from sys import stdin

num_dishes = 5
dishes = []
for i in range(5):
    dishes.append(int(stdin.readline()))
for i in range(0, num_dishes - 1):
    for j in range(i + 1, num_dishes):
        if (dishes[i] % 10 > dishes[j] % 10):
            dishes[i], dishes[j] = dishes[j], dishes[i]
dishes.sort(key=lambda d: d % 10)
got = False
ans = 0
for dish in dishes:
    if dish % 10 == 0:
        ans += dish
        continue
    else:
        if got:
            ans += dish + (10 - dish % 10)
        else:
            got = True
            ans += dish
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
X, Y, Z, K = map(int, input().split())

A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

N = []
for a in A:
    for b in B:
        N.append(a + b)
N.sort(reverse=True)
N = N[:K]

M = []
for n in N:
    for c in C:
        M.append(n + c)
M.sort(reverse=True)
M = M[:K]

print(*M, sep="\n")


Fixed submission:
X, Y, Z, K = map(int, input().split())

A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

N = []
for a in A:
    for b in B:
        N.append(a + b)
N.sort(reverse=True)
N = N[:K]

M = []
for n in N:
    for c in C:
        M.append(n + c)
M.sort(reverse=True)
M = M[:K]

print(*M, sep="\n")
Buggy python submission (verdict: Time Limit Exceeded):
N, Q = [int(i) for i in input().split()]
S = input()
L = [0 for i in range(Q)]
R = [0 for i in range(Q)]
for i in range(Q):
    L[i], R[i] = [int(i) for i in input().split()]

for i in range(Q):
    ans = 0
    substr = S[L[i] - 1:R[i]]
    while substr:
        i = substr[:-1].find('A')
        if i < 0:  # not found
            break
        elif substr[i + 1] == 'C':  # found AC
            ans += 1
            substr = substr[i + 2:]
        else:  # found A without C
            substr = substr[i + 1:]
    print(ans)


Fixed submission:
N, Q = map(int, input().split())
S = input()
L, R = [0] * Q, [0] * Q
for q in range(Q):
    L[q], R[q] = map(int, input().split())

t = [0] * (N + 1)
for i in range(N):
    t[i + 1] = t[i] + (1 if S[i:i + 2] == 'AC' else 0)

for q in range(Q):
    l, r = L[q], R[q]
    print(t[r - 1] - t[l - 1])
Buggy python submission (verdict: Time Limit Exceeded):
A, B = map(int, input().split())


def f(a, b):
    ans = a
    while a < b:
        a += 1
        ans ^= a
    return ans


print(f(A, B))


Fixed submission:
def get_bin_arr(n):
    arr = []
    while n > 0:
        arr.append(n & 1)
        n >>= 1
    return arr


def bin_arr_to_int(arr):
    return sum([2**i * digit for i, digit in enumerate(arr)])


def count_ones(idx, tier):
    half_cycle = 2**tier
    full_cycle = half_cycle * 2
    return (idx // full_cycle) * half_cycle \
        + max(idx % full_cycle - half_cycle, 0)


# A <= B
A, B = map(int, input().split())

a = get_bin_arr(A)
b = get_bin_arr(B)

my_max = 10**12
bin_digits = len(get_bin_arr(my_max))

# fill
a += [0] * (bin_digits - len(a))
b += [0] * (bin_digits - len(b))

ones = [0] * bin_digits

for i in range(bin_digits):
    ones[i] = count_ones(B + 1, i) - count_ones(A, i)

ans = [i % 2 for i in ones]
print(int(bin_arr_to_int(ans)))
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
H = list(map(int, input().split()))
DP = []
for i in range(min(N, K + 1)):
    DP.append(abs(H[0] - H[i]))
for i in range(K + 1, N):
    diff = float("inf")
    for d in range(1, K + 1):
        diff = min(diff, DP[-d] + abs(H[i - d] - H[i]))
    DP.append(diff)
print(DP[-1])


Fixed submission:
N, K = map(int, input().split())
H = list(map(int, input().split()))
DP = []
for i in range(min(N, K + 1)):
    DP.append(abs(H[0] - H[i]))
for i in range(K + 1, N):
    diff = float("inf")
    for d in range(1, K + 1):
        diff = min(diff, DP[-d] + abs(H[i - d] - H[i]))
    DP.append(diff)
print(DP[-1])
Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
w = [0] * N
v = [0] * N
for i in range(N):
    w[i], v[i] = map(int, input().split())
DP = [[0] * (W + 1)]
for i in range(1, N + 1):
    row = DP[i - 1][:]
    for j in range(W, -1, -1):
        new_j = j + w[i - 1]
        if 0 <= new_j <= W:
            row[new_j] = max(row[new_j], row[j] + v[i - 1])
    DP.append(row)
print(DP[-1][-1])


Fixed submission:
N, W = map(int, input().split())
w = [0] * N
v = [0] * N
for i in range(N):
    w[i], v[i] = map(int, input().split())
DP = [[0] * (W + 1)]
for i in range(1, N + 1):
    row = DP[i - 1][:]
    for j in range(W, -1, -1):
        new_j = j + w[i - 1]
        if 0 <= new_j <= W:
            row[new_j] = max(row[new_j], row[j] + v[i - 1])
    DP.append(row)
print(DP[-1][-1])
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
C = [tuple(map(int, input().split())) for _ in range(M)]
P = {c[0]: [] for c in C}
for c in C:
    P[c[0]].append(c[1])
for p in P:
    P[p].sort()
for c in C:
    print('{:06}{:06}'.format(c[0], 1 + P[c[0]].index(c[1])))


Fixed submission:
N, M = map(int, input().split())
C = [tuple(map(int, input().split())) for _ in range(M)]
P = {c[0]: [] for c in C}
for c in C:
    P[c[0]].append(c[1])
for p in P:
    P[p].sort()
    P[p] = {P[p][i]: i + 1 for i in range(len(P[p]))}
for c in C:
    print('{:06}{:06}'.format(c[0], P[c[0]][c[1]]))

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
P = [0] * M
Y = [0] * M
for i in range(M):
    P[i], Y[i] = map(int, input().split())

p_min = min(P)
p_max = max(P)

ANS = [0] * M
for pivot in range(p_min, p_max + 1):
    if pivot not in P:
        continue
    indices = [i for i, p in enumerate(P) if p == pivot]
    extracted_y = [Y[i] for i in indices]
    extracted_y.sort()
    for i in indices:
        ANS[i] = extracted_y.index(Y[i])

for p, y in zip(P, ANS):
    print('{:06}{:06}'.format(p, y + 1))


Fixed submission:
N, M = map(int, input().split())
C = [tuple(map(int, input().split())) for _ in range(M)]
P = {c[0]: [] for c in C}
for c in C:
    P[c[0]].append(c[1])
for p in P:
    P[p].sort()
    P[p] = {P[p][i]: i + 1 for i in range(len(P[p]))}
for c in C:
    print('{:06}{:06}'.format(c[0], P[c[0]][c[1]]))

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
P = [0] * M
Y = [0] * M
for i in range(M):
    P[i], Y[i] = map(int, input().split())

X = [0] * M
for p in set(P):
    I = [i for i in range(M) if P[i] == p]
    Y = [Y[i] for i in I]
    earliest = min(Y)
    latest = max(Y)
    i = 0
    for y in range(earliest, latest + 1):
        if y in Y:
            X[I[i]] = Y.index(y) + 1
            i += 1

for i in range(M):
    print("{:06}{:06}".format(P[i], X[i]))


Fixed submission:
N, M = map(int, input().split())
C = [tuple(map(int, input().split())) for _ in range(M)]
P = {c[0]: [] for c in C}
for c in C:
    P[c[0]].append(c[1])
for p in P:
    P[p].sort()
    P[p] = {P[p][i]: i + 1 for i in range(len(P[p]))}
for c in C:
    print('{:06}{:06}'.format(c[0], P[c[0]][c[1]]))
Buggy python submission (verdict: Runtime Error):
S = input()
K = int(input())

i = 0
while S[i] == '1' and i < len(S):
    i += 1
if K < i:
    print(1)
else:
    print(S[i])


Fixed submission:
S = input()
K = int(input())

i = 0
while i < len(S) and S[i] == '1':
    i += 1
if K <= i or i == len(S):
    print(1)
else:
    print(S[i])

Buggy python submission (verdict: Runtime Error):
S = input()
K = int(input())

i = 0
while S[i] == '1':
    i += 1
if K < i:
    print(1)
else:
    print(S[i])


Fixed submission:
S = input()
K = int(input())

i = 0
while i < len(S) and S[i] == '1':
    i += 1
if K <= i or i == len(S):
    print(1)
else:
    print(S[i])