Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
s = input()
t = input()
ss = s * (len(t))
ans = 0

if set(t) <= set(s):
    for i in range(len(t)):
        ans = ss.find(t[i], ans)
    print(ans + 1)
else:
    print(-1)

Fixed submission:
s = input()
t = input()
t_long = len(t)
position = [0] * t_long
rep = 0

if set(t) <= set(s):
    position[0] = s.find(t[0])
    for i in range(1, t_long):
        if s.find(t[i], position[i - 1] + 1) > -1:
            position[i] = s.find(t[i], position[i - 1] + 1)
        else:
            position[i] = s.find(t[i])
    for k in range(t_long - 1):
        if position[k + 1] <= position[k]:
            rep += 1
    print(rep * len(s) + position[t_long - 1] + 1)
else:
    print(-1)

Buggy python submission (verdict: Runtime Error):
s = input()
t = input()
ss = s * (len(t))
ans = 0

if set(t) <= set(s):
    for i in range(len(t)):
        ans = ss.find(t[i], ans)
    print(ans + 1)
else:
    print(-1)

Fixed submission:
s = input()
t = input()
t_long = len(t)
position = [0] * t_long
rep = 0

if set(t) <= set(s):
    position[0] = s.find(t[0])
    for i in range(1, t_long):
        if s.find(t[i], position[i - 1] + 1) > -1:
            position[i] = s.find(t[i], position[i - 1] + 1)
        else:
            position[i] = s.find(t[i])
    for k in range(t_long - 1):
        if position[k + 1] <= position[k]:
            rep += 1
    print(rep * len(s) + position[t_long - 1] + 1)
else:
    print(-1)
Buggy python submission (verdict: Runtime Error):
S = list(input())
l = [S.pop()]

while S:
    if S[-1] != l[-1]:
        l.append(S.pop())
    else:
        if len(S) == 1:
            break
        else:
            a = S.pop()
            b = S.pop()
            l.append(b + a)
    print(l)

print(len(l))

Fixed submission:
S = list(input())
l = [S.pop()]

while S:
    if S[-1] != l[-1]:
        l.append(S.pop())
    else:
        if len(S) == 1:
            break
        else:
            a = S.pop()
            b = S.pop()
            l.append(b + a)

print(len(l))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
s = [sorted(input()) for i in range(N)]
count = 0

for i in range(N):
    for k in range(i + 1, N):
        if s[i] == s[k]:
            count += 1
print(count)

Fixed submission:
import collections

N = int(input())
s = [''.join(sorted(input())) for i in range(N)]

count = collections.Counter(s)
ans = 0

for i in count.values():
    ans += i * (i - 1) / 2

print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
s = [input() for i in range(N)]
count = 0

for i in range(N):
    for k in range(i + 1, N):
        if sorted(s[i]) == sorted(s[k]):
            count += 1
print(count)

Fixed submission:
import collections

N = int(input())
s = [''.join(sorted(input())) for i in range(N)]

count = collections.Counter(s)
ans = 0

for i in count.values():
    ans += i * (i - 1) / 2

print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
s = [input() for i in range(N)]
count = 0

for i in range(N):
    for k in range(i + 1, N):
        if sorted(s[i]) == sorted(s[k]):
            count += 1
print(count)

Fixed submission:
import collections

N = int(input())
s = [''.join(sorted(input())) for i in range(N)]

count = collections.Counter(s)
ans = 0

for i in count.values():
    ans += i * (i - 1) / 2

print(int(ans))
Buggy python submission (verdict: Runtime Error):
import numpy as np

N = int(input())
A = np.array(list(map(float, input().split())))

print(np.reciprocal(np.sum(np.reciprocal(A))))

Fixed submission:
N = int(input())
number = len(str(N))
count = 0

if number % 2 == 0:
    for i in range(1, number, 2):
        count += 10 ** i - 10 ** (i - 1)
    print(count)
else:
    for i in range(2, number, 2):
        count += 10 ** i - 10 ** (i - 1)
    print(N - count)
Buggy python submission (verdict: Runtime Error):
import sympy as sp

A, B = map(int, input().split())
K = sp.Symbol('K')

ans = sp.solve((A - K) **2 - (B - K) ** 2, K)

if isinstance(ans[0], int) == True:
    print(ans[0])
else:
    print('IMPOSSIBLE')

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

if (A + B) % 2 == 0:
    print(int((A + B) / 2))
else:
    print('IMPOSSIBLE')
Buggy python submission (verdict: Runtime Error):
S = int(input())


def prime_factorize(n):
    a = 1
    while n % 2 == 0:
        n //= 2
        a *= 2

    if n <= 10 ** 9:
        return n
    f = 3
    while f * f <= n:
        if S // a <= 10 ** 9:
            return a
        if n % f == 0:
            n //= f
            a *= f
        else:
            f += 2


if S <= 10 ** 9:
    print(0, 0, 1, 0, 0, S)
else:
    x = prime_factorize(S)
    y = S // x
    print(0, 0, x, 0, 0, y)

Fixed submission:
S = int(input())

if S != 10 ** 18:
    q = S // 10 ** 9 + 1
    r = 10 ** 9 * q - S
else:
    q = S // 10 ** 9
    r = 10 ** 9 * q - S

print(0, 0, q, r, 1, 10 ** 9)

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


def prime_factorize(n):
    a = 1
    if n <= 10 ** 9:
        return n

    while n % 2 == 0:
        n //= 2
        a *= 2

    if n <= 10 ** 9:
        return n
    f = 3
    while f * f <= n:
        if n // a <= 10 ** 9:
            return a
        if n % f == 0:
            n //= f
            a *= f
        else:
            f += 2


if S <= 10 ** 9:
    print(0, 0, 1, 0, 0, S)
else:
    x = prime_factorize(S)
    y = S // x
    print(0, 0, x, 0, 0, y)

Fixed submission:
S = int(input())

if S != 10 ** 18:
    q = S // 10 ** 9 + 1
    r = 10 ** 9 * q - S
else:
    q = S // 10 ** 9
    r = 10 ** 9 * q - S

print(0, 0, q, r, 1, 10 ** 9)

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


def prime_factorize(n):
    if n <= 10 ** 9:
        return n
    while n % 2 == 0:
        n //= 2
        if n <= 10 ** 9:
            return n
    f = 3
    while f * f <= n:
        if n <= 10 ** 9:
            return n
        if n % f == 0:
            n //= f
        else:
            f += 2


if S <= 10 ** 9:
    print(0, 0, 1, 0, 0, S)
else:
    x = prime_factorize(S)
    y = S // x
    print(0, 0, x, 0, 0, y)

Fixed submission:
S = int(input())

if S != 10 ** 18:
    q = S // 10 ** 9 + 1
    r = 10 ** 9 * q - S
else:
    q = S // 10 ** 9
    r = 10 ** 9 * q - S

print(0, 0, q, r, 1, 10 ** 9)

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


def prime_factorize(n):
    while n % 2 == 0:
        n //= 2
    if n <= 10 ** 9:
        return n
    f = 3
    while f * f <= n:
        if n <= 10 ** 9:
            return n
        if n % f == 0:
            n //= f
        else:
            f += 2


x = prime_factorize(S)
y = S // x
print(0, 0, x, 0, 0, y)

Fixed submission:
S = int(input())

if S != 10 ** 18:
    q = S // 10 ** 9 + 1
    r = 10 ** 9 * q - S
else:
    q = S // 10 ** 9
    r = 10 ** 9 * q - S

print(0, 0, q, r, 1, 10 ** 9)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [int(input()) for i in range(N)]
m1, m2 = sorted(A, reverse=True)[:2]

for i in range(N):
    if i == p:
        print(m2)
    else:
        print(m1)

Fixed submission:
N = int(input())
A = [int(input()) for i in range(N)]
m = max(A)
p = A.index(m)
A.remove(m)
n = max(A)

for i in range(N):
    if i == p:
        print(n)
    else:
        print(m)
Buggy python submission (verdict: Runtime Error):
import sys
from itertools import combinations
from collections import Counter
read = sys.stdin.read

N, *xy = map(int, read().split())
pq = []
for (a1, b1), (a2, b2) in combinations(zip(*[iter(xy)] * 2), 2):
    p = a1 - a2
    q = b1 - b2
    pq.append((p, q))
    pq.append((-p, -q))

print(N - Counter(pq).most_common()[0][1])

Fixed submission:
import sys
from itertools import combinations
from collections import Counter
read = sys.stdin.read

N, *xy = map(int, read().split())

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

pq = []
for (a1, b1), (a2, b2) in combinations(zip(*[iter(xy)] * 2), 2):
    p = a1 - a2
    q = b1 - b2
    pq.append((p, q))
    pq.append((-p, -q))

print(N - Counter(pq).most_common()[0][1])
Buggy python submission (verdict: Runtime Error):
import numpy as np
import sys
buf = sys.stdin.buffer

H, W = map(int, buf.readline().split())
grid = np.zeros((H + 2, W + 2), np.int32)
grid[1:-1, 1:-1] = np.where(np.array(list(map(list, buf.read().decode('utf-8').split()))).reshape(H, W) == '.', 1, 0)
grid_v = grid.T

right = np.maximum.accumulate(np.where(grid < 1, np.arange(W + 2), 0), axis=1)
left = np.flip(np.minimum.accumulate(np.flip(np.where(grid < 1, np.arange(W + 2), 10 ** 10), axis=1), axis=1), axis=1)
down = np.maximum.accumulate(np.where(grid_v < 1, np.arange(H + 2), 0), axis=1).T
up = np.flip(np.minimum.accumulate(np.flip(np.where(grid_v < 1, np.arange(H + 2), 10 ** 10), axis=1), axis=1), axis=1).T

print(np.max((left - right) + (up - down)) - 3)

Fixed submission:
import numpy as np
import sys
buf = sys.stdin.buffer

H, W = map(int, buf.readline().split())
grid = np.zeros((H + 2, W + 2), np.int32)
grid[1:-1, 1:-1] = np.where(np.array(list(map(list, buf.read().decode('utf-8').split()))).reshape(H, W) == '.', 1, 0)
grid_v = grid.T

right = np.maximum.accumulate(np.where(grid < 1, np.arange(W + 2), 0), axis=1)
left = np.fliplr(np.minimum.accumulate(np.fliplr(np.where(grid < 1, np.arange(W + 2), 10 ** 10)).copy(), axis=1))
down = np.maximum.accumulate(np.where(grid_v < 1, np.arange(H + 2), 0), axis=1).T
up = np.fliplr(np.minimum.accumulate(np.fliplr(np.where(grid_v < 1, np.arange(H + 2), 10 ** 10)).copy(), axis=1)).T

print(np.max((left - right) + (up - down)) - 3)
Buggy python submission (verdict: Runtime Error):
A, P = map(int, input().split())

print(A * 3 // P)

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

print((A * 3 + P) // 2)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
L = [0] * M
R = [0] * M
ID = [0] * N
N = {i for i in range(1, N + 1)}
for i in range(M):
    L[i], R[i] = map(int, input().split())
    ID[i] = {j for j in range(L[i], R[i] + 1)}

for i in range(M):
    N = N & ID[i]

print(len(N))

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

for i in range(M):
    L[i], R[i] = map(int, input().split())
LL = max(L)
RR = min(R)
ans = 0
for i in range(N):
    if LL <= i + 1 <= RR:
        ans += 1
    else:
        pass
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
L = [0] * M
R = [0] * M
ID = [0] * N
N = {i for i in range(1, N + 1)}
for i in range(M):
    L[i], R[i] = map(int, input().split())
    N = N.intersection({j for j in range(L[i], R[i] + 1)})

print(len(N))

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

for i in range(M):
    L[i], R[i] = map(int, input().split())
LL = max(L)
RR = min(R)
ans = 0
for i in range(N):
    if LL <= i + 1 <= RR:
        ans += 1
    else:
        pass
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heapify, heappush, heappop
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
A = list(map(int, input().split()))
a = heapify(A)
B = [0] * M
C = [0] * M
for i in range(M):
    B[i], C[i] = map(int, input().split())

cb = sorted(zip(C, B), reverse=True)

for c, b in cb:
    for _ in range(b):
        m = heappop(A)
        heappush(A, max(m, c))
        if m > c:
            break

print(sum(A))

Fixed submission:
from heapq import heapify, heappush, heappop
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
B = [0] * M
C = [0] * M
for i in range(M):
    B[i], C[i] = map(int, input().split())

cb = sorted(zip(C, B), reverse=True)

cnt = 0
exchange = []
for c, b in cb:
    exchange.extend([c] * b)
    cnt += b
    if cnt >= N:
        break

exchange.sort()

for _ in range(len(exchange)):
    m = heappop(A)
    heappush(A, max(m, exchange.pop()))

print(sum(A))

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heapify, heappush, heappop
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
A = list(map(int, input().split()))
a = heapify(A)

for _ in range(M):
    B, C = map(int, input().split())
    for _ in range(B):
        m = heappop(A)
        heappush(A, max(m, C))
        if m > C:
            break

print(sum(A))

Fixed submission:
from heapq import heapify, heappush, heappop
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
B = [0] * M
C = [0] * M
for i in range(M):
    B[i], C[i] = map(int, input().split())

cb = sorted(zip(C, B), reverse=True)

cnt = 0
exchange = []
for c, b in cb:
    exchange.extend([c] * b)
    cnt += b
    if cnt >= N:
        break

exchange.sort()

for _ in range(len(exchange)):
    m = heappop(A)
    heappush(A, max(m, exchange.pop()))

print(sum(A))
Buggy python submission (verdict: Time Limit Exceeded):
from scipy.sparse.csgraph import floyd_warshall
import sys
input = sys.stdin.readline

N = int(input())
INF = float('inf')
graph = [[INF] * N for _ in range(N)]

for i in range(N):
    graph[i][i] = 0

for _ in range(N - 1):
    u, v, w = map(int, input().split())
    u, v = u - 1, v - 1
    w = w % 2 + 2
    graph[u][v] = w
    graph[v][u] = w

distance = floyd_warshall(graph, directed=False)

print(0)
for i in range(1, N):
    if int(distance[0][i]) % 2 == 0:
        print(0)
    else:
        print(1)

Fixed submission:
import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
read = sys.stdin.read


N = int(readline())
graph = [[] for _ in range(N + 1)]

for i in readlines():
    u, v, w = map(int, i.split())
    graph[u].append((v, w))
    graph[v].append((u, w))

stack = [1]
parent = [0] * (N + 1)
color = [0] * (N + 1)

while stack:
    here = stack.pop()
    for x, w in graph[here]:
        if x == parent[here]:
            continue
        parent[x] = here
        color[x] = color[here] ^ (w % 2)
        stack.append(x)

for i in color[1:]:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
from scipy.sparse.csgraph import floyd_warshall
import sys
input = sys.stdin.readline

N = int(input())
INF = float('inf')
graph = [[INF] * N for _ in range(N)]

for i in range(N):
    graph[i][i] = 0

for _ in range(N - 1):
    u, v, w = map(int, input().split())
    u, v = u - 1, v - 1
    graph[u][v] = w
    graph[v][u] = w

distance = floyd_warshall(graph, directed=False)

print(0)
for i in range(1, N):
    if int(distance[0][i]) % 2 == 0:
        print(0)
    else:
        print(1)

Fixed submission:
import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
read = sys.stdin.read


N = int(readline())
graph = [[] for _ in range(N + 1)]

for i in readlines():
    u, v, w = map(int, i.split())
    graph[u].append((v, w))
    graph[v].append((u, w))

stack = [1]
parent = [0] * (N + 1)
color = [0] * (N + 1)

while stack:
    here = stack.pop()
    for x, w in graph[here]:
        if x == parent[here]:
            continue
        parent[x] = here
        color[x] = color[here] ^ (w % 2)
        stack.append(x)

for i in color[1:]:
    print(i)
Buggy python submission (verdict: Runtime Error):
M, K = map(int, input().split())

if K >= 2 ** M:
    print(-1)
    exit()

if M == 0:
    print(0)
    exit()

if M == 1:
    if K == 0:
        print(0, 0, 1, 1)
    else:
        print(-1)
    exit()

k = str(K)
seq = list(map(str, range(2 ** M)))
seq.remove(K)
answer = seq + [k] + seq[::-1] + [k]

print(' '.join(answer))


Fixed submission:
M, K = map(int, input().split())
m = 1 << M

if K >= m:
    print(-1)
    exit()

if M == 0:
    print(0, 0)
    exit()

if M == 1:
    if K == 0:
        print(0, 0, 1, 1)
    else:
        print(-1)
    exit()

k = str(K)
seq = list(map(str, range(m)))
seq.remove(k)
answer = seq + [k] + seq[::-1] + [k]

print(' '.join(answer))
Buggy python submission (verdict: Runtime Error):
N = int(input())


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


n = make_divisors(N)
answer = 0
for i in n[::-1]:
    q, r = divmod(N, i - 1)
    if q == r:
        answer += i - 1
    else:
        break

print(answer)

Fixed submission:
N = int(input())


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


n = make_divisors(N)
answer = 0
for i in n[::-1]:
    if i == 1:
        continue
    q, r = divmod(N, i - 1)
    if q == r:
        answer += i - 1
    else:
        break

print(answer)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())

ans = 0

for i in range(N):
    t = 0
    p = i + 1
    while K > p:
        t += 1
        p *= 2
    ans += (0.5 ** t) / N
print(ans)

Fixed submission:
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = 0

for i in range(N):
    d = V[i] - C[i]
    if d > 0:
        ans += d

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
dcg_list = [0] * N

# 最大公約数
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a

for i in range(N):
    if i != 0:
        temp_dcg = A[0]
    else:
        temp_dcg = A[1]
    for j in range(i):
        temp_dcg = gcd(temp_dcg, A[j])
    for k in range(i + 1, N):
        temp_dcg = gcd(temp_dcg, A[k])
    dcg_list[i] = temp_dcg

print(max(dcg_list))

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
gcd_list = [0] * N

# 最大公約数
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a

#i-1番目までの最大公約数リスト
b = [0] * (N - 1)
b[0] = A[0]
for i in range(1, N - 1):
    b[i] = gcd(b[i - 1], A[i])
#i+1以降の最大公約数リスト
a = [0] * (N - 1)
a[N - 2] = A[N - 1]
for i in reversed(range(0, N - 2)):
    a[i] = gcd(a[i + 1], A[i + 1])

gcd_list[0] = a[0]
gcd_list[N-1] = b[N - 2]
for i in range(1, N - 1):
    gcd_list[i] = gcd(b[i - 1], a[i])

print(max(gcd_list))
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import groupby
N, K = map(int, input().split())
S = groupby(list(input()))
state = []
number = []
for i, j in S:
    state.append(i)
    number.append(len(list(j)))

answer = 0

if len(state) == 1:
    print(number[0])
    exit()

if state[0] == '0':
    answer = sum(number[0:2 * K])

start = state.index('1')
for i in range(start, len(number), 2):
    answer = max(answer, sum(number[i:2 * K + i + 1]))

print(answer)

Fixed submission:
from itertools import groupby, accumulate
N, K = map(int, input().split())
S = groupby(list(input()))
state = []
number = []
for i, j in S:
    state.append(i)
    number.append(len(list(j)))

answer = 0

if len(state) == 1:
    print(number[0])
    exit()

number = list(accumulate([0] + number))
l = len(number) - 1

if state[0] == '0':
    answer = number[min(l, 2 * K)] - number[0]

start = state.index('1') + 1
for i in range(start, l + 1, 2):
    answer = max(answer, number[min(2 * K + i, l)] - number[i - 1])

print(answer)
Buggy python submission (verdict: Runtime Error):
b = input()

if b == 'A':
    b = 'T'
elif b == 'C':
    b = 'G'
elif b == 'T':
    b = 'A'
elif b == G:
    b = 'C'

print(b)

Fixed submission:
b = input()

if b == 'A':
    b = 'T'
elif b == 'C':
    b = 'G'
elif b == 'T':
    b = 'A'
elif b == 'G':
    b = 'C'

print(b)
Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
l = [0] * Q
r = [0] * Q
for i in range(Q):
    l[i], r[i] = map(int, input().split())
for i in range(Q):
    print(S[l[i] - 1:r[i]].count('AC'))

Fixed submission:
N, Q = map(int, input().split())
S = input()
t = [0] * N
for i in range(N - 1):
    t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)
for i in range(Q):
    l, r = map(int, input().split())
    print(t[r - 1] - t[l - 1])
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
X = sorted(list(map(int, input().split())))
d = [0] * (M - 1)

if N >= M:
    print(ans)
else:
    for i in range(M - 1):
        d[i] = abs(X[i + 1] - X[i])
    d.sort(reverse=True)
    print(sum(d[N - 1:]))

Fixed submission:
N, M = map(int, input().split())
X = sorted(list(map(int, input().split())))
d = [0] * (M - 1)
ans = 0

if N >= M:
    print(ans)
else:
    for i in range(M - 1):
        d[i] = abs(X[i + 1] - X[i])
    d.sort(reverse=True)
    b = d[:N - 1]
    for i in range(M - 1):
        if d[i] in b:
            b.remove(d[i])
        else:
            ans += d[i]
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

N, W = map(int, readline().split())
tmp = map(int, read().split())
wv = tuple(zip(tmp, tmp))

dp = [[0] * (W + 1) for _ in range(N + 1)]

for i in range(N):
    for w in range(W + 1):
        if wv[i][0] <= w:
            dp[i + 1][w] = max(dp[i][w - wv[i][0]] + wv[i][1], dp[i][w])
        else:
            dp[i + 1][w] = dp[i][w]

print(max(dp[-1]))

Fixed submission:
import sys
import numpy as np
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

N, W = map(int, readline().split())
wv = map(int, read().split())
dp = np.zeros(W + 1, np.int64)

for w, v in zip(wv, wv):
    np.maximum(dp[w:], dp[:-w] + v, out=dp[w:])

print(dp.max())
Buggy python submission (verdict: Runtime Error):
import sys
import numpy as np
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines


def main():
    N, W = map(int, readline().split())
    wv = map(int, read().split())
    dp = np.zeros(W + 1, np.int64)

    for w, v in zip(wv, wv):
        np.maximum(dp[w:], dp[:-w] + v, out=dp[w:])

    print(dp.max())


if __name__ == '__main__':
    main()

Fixed submission:
import sys
import numpy as np
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines


def main():
    N, W = map(int, readline().split())
    wv = map(int, read().split())
    dp = np.full(10 ** 5 + 1, W + 1, np.int64)
    dp[0] = 0

    for w, v in zip(wv, wv):
        np.minimum(dp[v:], dp[:-v] + w, out=dp[v:])

    print(np.where(dp <= W)[0].max())


if __name__ == '__main__':
    main()