Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02795 (python)

Fixed submission:
# A - Painting
import sys

debug = lambda message: print("DEBUG:", message, file=sys.stderr)


def main():
    H, W, N = map(int, open(0))
    debug(max(H, W))
    print((N + max(H, W) - 1) // max(H, W))


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# A - Painting
import sys

debug = lambda message: sys.stderr.write(message)


def main():
    H, W, N = map(int, open(0))
    debug(max(H, W))
    print((N + max(H, W) - 1) // max(H, W))


if __name__ == "__main__":
    main()
Problem p02813 (python)

Fixed submission:
# ABC150C - Count Order
from itertools import permutations


def main():
    N, *PQ = map(int, open(0).read().split())
    P, Q = PQ[:N], PQ[N:]
    a, b = 0, 0
    for i, perm in enumerate(permutations(range(1, N + 1), N), 1):
        perm = list(perm)
        if perm == P:
            a = i
        if perm == Q:
            b = i
    ans = abs(a - b)
    print(ans)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# ABC150C - Count Order
from itertools import permutations


def main():
    N, *PQ = map(int, open(0).read().split())
    P, Q = PQ[:N], PQ[N:]
    perms = list(permutations(range(1, N + 1)))
    ans = abs(perms.index(P) - perms.index(Q))
    print(ans)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# ABC150C - Count Order
from itertools import permutations


def main():
    N, *PQ = map(int, open(0).read().split())
    P, Q = PQ[:N], PQ[N:]
    perms = tuple(permutations(range(1, N + 1)))
    ans = abs(perms.index(P) - perms.index(Q))
    print(ans)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# ABC150C - Count Order
from itertools import permutations


def main():
    N, *PQ = map(int, open(0).read().split())
    P, Q = PQ[:N], PQ[N:]
    perms = list(permutations(range(1, N + 1), N))
    ans = abs(perms.index(P) - perms.index(Q))
    print(ans)


if __name__ == "__main__":
    main()
Problem p02837 (python)

Fixed submission:
# ABC147C - HonestOrUnkind2
from itertools import combinations


def main():
    N = int(input())
    testimonies = {i: {} for i in range(1, N + 1)}
    for i in range(1, N + 1):
        A = int(input())
        for _ in range(A):
            x, y = map(int, input().split())
            testimonies[i][x] = y

    for cnt_honest in range(N, 0, -1):
        for honest_people in combinations(range(1, N + 1), cnt_honest):
            honest_people = set(honest_people)
            is_consistent = True
            for i in honest_people:
                for x, y in testimonies[i].items():
                    if (x in honest_people and not y) or (x not in honest_people and y):
                        is_consistent = False
                        break
                if not is_consistent:
                    break
            if is_consistent:
                print(cnt_honest)
                return
    print(0)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# ABC147C - HonestOrUnkind2
from itertools import combinations


def main():
    N = int(input())
    testimonies = [[] for _ in range(N + 1)]
    for i in range(1, N + 1):
        A = int(input())
        for _ in range(A):
            testimonies[i].append(map(int, input().split()))

    for cnt_honest in range(N, 0, -1):
        for honest_people in combinations(range(1, N + 1), cnt_honest):
            is_consistent = True
            for i in honest_people:
                for x, y in testimonies[i]:
                    if (x in honest_people and not y) or (x not in honest_people and y):
                        is_consistent = False
                        break
                if not is_consistent:
                    break
            if is_consistent:
                print(cnt_honest)
                return
    print(0)


if __name__ == "__main__":
    main()
Problem p02888 (python)

Fixed submission:
# ABC143D - Triangles
def main():
    # fix the longest edge -> binary search
    N, *L = map(int, open(0).read().split())
    L.sort()
    ans = 0
    for i in range(N - 1, 1, -1):
        x, ng, ok = L[i], 0, i - 1
        while ng < ok:
            if L[ng] + L[ok] > x:
                ans += ok - ng
                ok -= 1
            else:
                ng += 1
    print(ans)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# ABC143D - Triangles
def binary_search(cur: int, upper_bound: int = 1 << 60, lower_bound: int = -1) -> int:
    ok, ng, ret = upper_bound, lower_bound, 0
    while abs(ok - ng) > 1:
        if L[ok] + L[ng] > cur:
            ret += ok - ng
            ok -= 1
        else:
            ng += 1
    return ret


def main():
    # fix the longest edge -> binary search
    N, *L = map(int, open(0).read().split())
    L.sort()
    ans = sum(binary_search(L[i], i - 1, 0) for i in range(N - 1, 1, -1))
    print(ans)


if __name__ == "__main__":
    main()
Problem p02889 (python)

Fixed submission:
# ABC143E - Travel by Car
import numpy as np

from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall


def main():
    # FW -> once more FW to edges <= L
    global L, G, dist, ancestors
    N, M, L, *X = map(int, open(0).read().split())
    ABC, ST = X[: 3 * M], X[3 * M + 1 :]
    A, B, C, S, T = ABC[::3], ABC[1::3], ABC[2::3], ST[::2], ST[1::2]

    G = csr_matrix((C, (A, B)), (N + 1, N + 1))
    dist = floyd_warshall(G, directed=0)

    modified_G = np.full((N + 1, N + 1), np.inf)
    np.fill_diagonal(modified_G, 0)
    modified_G[dist <= L] = 1
    modified_dist = floyd_warshall(modified_G, directed=0)
    modified_dist[modified_dist == np.inf] = 0
    modified_dist = (modified_dist).astype(int)
    
    ans = modified_dist[S, T] - 1
    print("\n".join(ans.astype(str)))


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# ABC143E - Travel by Car
def floyd_warshall(dist):
    """
    Compute the shortest paths of all pairs and modify dist.
    """
    for i in range(N):  # intermediate point
        for j, c2 in enumerate(dist[j][i] for j in range(N)):  #  source
            for k, (c1, c3) in enumerate(zip(dist[j], dist[i])):  # target
                if c2 + c3 < c1:
                    dist[j][k] = c2 + c3
                    

def main():
    # FW -> once more FW to edges <= L
    global N
    N, M, L, *X = map(int, open(0).read().split())
    ABC, ST = X[: 3 * M], X[3 * M + 1 :]
    INF = float("inf")
    dist = [[INF] * (N + 1) for _ in range(N + 1)]
    for i in range(N + 1):
        dist[i][i] = 0
    for v, u, cost in zip(*[iter(ABC)] * 3):
        dist[v][u] = dist[u][v] = cost
    dist = floyd_warshall(dist)

    # assume distance within L as 1 and compute the number of fueling
    modified_dist = [[1 if x <= L else INF for x in d] for d in dist]
    modified_dist = floyd_warshall(modified_dist)
    ans = [
        modified_dist[s][t] - 1 if modified_dist[s][t] != INF else -1
        for s, t in zip(*[iter(ST)] * 2)
    ]
    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main()
Problem p02903 (python)

Fixed submission:
# AGC038A - 01 Matrix
def main():
    H, W, A, B = tuple(map(int, input().split()))
    for i in range(H):
        if i < B:
            x = [0] * A + [1] * (W - A)
        else:
            x = [1] * A + [0] * (W - A)
        print(*x, sep="")


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# AGC038A - 01 Matrix
def main():
    """
    00111
    00111
    11000
    11000
    """
    H, W, A, B = map(int, input().split())
    x = "0" * A + "1" * (W - A)
    y = "1" * A + "0" * (W - A)
    ans = [x] * B + [y] * [H - B]
    print("\n".join(ans))


if __name__ == "__main__":
    main()
Problem p02913 (python)

Fixed submission:
# ABC141E - Who Says a Pun?
def main():
    N = int(input())
    S = input().rstrip()
    ok, ng = 0, N // 2 + 1
    while ng - ok > 1:
        mid = (ok + ng) // 2
        flg, checked = 0, set()
        for i in range(N - 2 * mid + 1):
            checked.add(hash(S[i : i + mid]))
            if hash(S[i + mid : i + 2 * mid]) in checked:
                flg = 1
                break
        if flg:
            ok = mid  # next mid will be longer
        else:
            ng = mid  # next mid will be shorter
    print(ok)  # max length of substrings appeared twice or more


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
from typing import List


class RollingHash:
    __slots__ = ["source", "length", "base", "mod", "hash", "power"]

    def __init__(self, source: str, base: int = 1007, mod: int = 10 ** 9 + 7):
        self.source = source
        self.length = len(source)
        self.base = base
        self.mod = mod
        self.hash = self._get_hash_from_zero()
        self.power = self._get_base_pow()

    def _get_hash_from_zero(self) -> List[int]:
        """Compute hash of interval [0, right)."""
        hash_from_zero = [0] * self.length
        cur = 0
        for i, c in enumerate(self.source):
            cur = (cur * self.base + ord(c)) % self.mod
            hash_from_zero[i] = cur
        return hash_from_zero

    def _get_base_pow(self) -> List[int]:
        """Compute mod of power of base."""
        power = [1] * self.length
        cur = 1
        for i in range(self.length):
            cur *= self.base % self.mod
            power[i] = cur
        return power

    def get_hash(self, left: int, right: int):
        """Compute hash of interval [left, right)."""
        return (
            self.hash[right] - self.hash[left] * self.power[right - left]
        ) % self.mod


def abc141_e():
    # https://atcoder.jp/contests/abc141/tasks/abc141_e
    N = int(input())
    S = input().rstrip()
    rh = RollingHash(S)
    ok, ng = 0, N // 2 + 1
    while ng - ok > 1:
        mid = (ok + ng) // 2
        flg = False
        memo = set()
        for i in range(N - 2 * mid + 1):
            memo.add(rh.get_hash(i, i + mid))
            if rh.get_hash(i + mid, i + 2 * mid) in memo:
                flg = True
                break
        if flg:
            ok = mid  # next mid will be longer
        else:
            ng = mid  # next mid will be shorter
    print(ok)  # max length of substrings appeared twice or more


if __name__ == "__main__":
    abc141_e()
Problem p02923 (python)

Fixed submission:
# ABC139
def main():
    N, *H = map(int, open(0).read().split())
    ans, cur, cnt = 0, H[0], 0
    for i in H[1:]:
        if i <= cur:
            cnt += 1
        else:
            ans = max(ans, cnt)
            cnt = 0
        cur = i
    ans = max(ans, cnt)
    print(ans)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# ABC139
from math import ceil
def main():
    A, B = tuple(map(int, input().split()))
    if A >= B:
        print(1)
    else:
        ans = 1 + ceil((B - A) / (A - 1))
        print(ans)


if __name__ == "__main__":
    main()
Problem p02947 (python)

Fixed submission:
# ABC137C - Green Bin
from collections import Counter


def main():
    N = int(input())
    A = Counter("".join(sorted(input())) for _ in range(N))
    ans = sum(i * (i - 1) // 2 for i in A.values())
    print(ans)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# ABC137C - Green Bin
from collections import Counter


def main():
    _, *S = open(0)
    cnt = Counter(sorted(s) for s in S).values()
    ans = sum(i * (i - 1) // 2 for i in cnt)
    print(ans)


if __name__ == "__main__":
    main()
Problem p02971 (python)

Fixed submission:
# ABC134
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    A = list(map(int, [input() for _ in range(n)]))
    SA = sorted(A)
    ma, ma2 = SA[-1], SA[-2]
    ans = []
    for i in A:
        if i != ma:
            ans += [ma]
        else:
            ans += [ma2]
    print(*ans, sep="\n")


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# ABC134
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    A = list(map(int, [input() for _ in range(n)]))
    SA = sorted(set(A))
    ma, ma2 = SA[-1], SA[-2]
    ans = [ma if i != ma else ma2 for i in A]
    print(*ans, sep="\n")


if __name__ == "__main__":
    main()
Problem p02985 (python)

Fixed submission:
# ABC133E - Virus Tree 2
from collections import deque


def main():
    N, K, *AB = map(int, open(0).read().split())
    MOD = 10 ** 9 + 7
    G = [[] for _ in range(N + 1)]
    for v, u in zip(*[iter(AB)] * 2):
        G[v].append(u), G[u].append(v)
    queue = deque([1])
    seen = [0] * (N + 1)
    seen[1] = 1
    ans, cand = K, K - 1
    while queue:
        v = queue.popleft()
        for u in G[v]:
            if not seen[u]:
                seen[u] = 1
                ans = (ans * cand) % MOD
                cand -= 1
                queue.append(u)
        cand = K - 2
    print(ans)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# ABC133E - Virus Tree 2
from collections import deque


def dfs() -> int:
    cand, ret, MOD = K - 1, K, 10 ** 9 + 7
    queue, seen = deque([1]), [0] * (N + 1)
    seen[1] = 1
    while queue:
        v = queue.popleft()
        for u in G[v]:
            if not seen[u]:
                seen[u] = 1
                ret = (ret * cand) % MOD
                cand -= 1
                queue.append(u)
        cand = K - 2
    return ret


def main():
    N, K, *AB = map(int, open(0).read().split())
    G = [[] for _ in range(N + 1)]
    for v, u in zip(*[iter(AB)] * 2):
        G[v].append(u), G[u].append(v)
    ans = dfs()
    print(ans)


if __name__ == "__main__":
    main()
Problem p03006 (python)

Fixed submission:
import sys
input = sys.stdin.readline

n = int(input())
arr = sorted([list(map(int, input().rstrip().split())) for _ in range(n)])
cnt = {}
for i in range(n):
    for j in range(i + 1, n):
        dif = (arr[j][0] - arr[i][0], arr[j][1] - arr[i][1])
        cnt.setdefault(dif, 0)
        cnt[dif] += 1
print(1 if cnt == {} else n - max(cnt.values()))

Buggy submission (verdict: Runtime Error):
# div2019-2B - Picking Up
from collections import defaultdict

n = int(input())
arr = sorted([list(map(int, input().rstrip().split())) for _ in range(n)])
cnt = defaultdict(0)
for i in range(n):
    for j in range(i + 1, n):
        dif = (arr[j][0] - arr[i][0], arr[j][1] - arr[i][1])
        cnt[dif] += 1
print(cnt)
print(n - max(cnt.values(), default=0))

Buggy submission (verdict: Runtime Error):
# div2019-2B - Picking Up
import collections
import sys
input = sys.stdin.readline

n = int(input())
arr = sorted([list(map(int, input().rstrip().split())) for _ in range(n)])
dif = []
for i in range(1, n):
    x = arr[i][0] - arr[i - 1][0]
    y = arr[i][1] - arr[i - 1][1]
    dif += [(x, y)]

x_min, x_max = min(dif, key=lambda i: i[0])[0], max(dif, key=lambda i: i[0])[0]
y_min, y_max = min(dif, key=lambda i: i[1])[1], max(dif, key=lambda i: i[1])[1]
ans = float("inf")
for p in range(x_min, x_max + 1):
    for q in range(y_min, y_max + 1):
        cnt = 1
        for i in range(1, n):
            if (arr[i - 1][0], arr[i - 1][1]) != (arr[i][0] - p, arr[i][1] - q):
                cnt += 1
        ans = min(ans, cnt)
print(ans)

Buggy submission (verdict: Runtime Error):
# div2019-2B - Picking Up
import collections
import sys
input = sys.stdin.readline

n = int(input())
arr = sorted([list(map(int, input().rstrip().split())) for _ in range(n)])
dic_x, dic_y = {}, {}
for i in range(1, n):
    x = arr[i][0] - arr[i - 1][0]
    y = arr[i][1] - arr[i - 1][1]
    if x in dic_x:
        dic_x[x] += 1
    else:
        dic_x[x] = 1
    if y in dic_y:
        dic_y[y] += 1
    else:
        dic_y[y] = 1

p = collections.Counter(dic_x).most_common()[0][0]
q = collections.Counter(dic_y).most_common()[0][0]
ans = 1
for i in range(1, n):
    if (arr[i - 1][0], arr[i - 1][1]) != (arr[i][0] - p, arr[i][1] - q):
        ans += 1
print(ans)
Problem p03044 (python)

Fixed submission:
# ABC126D - Even Relation
import sys

sys.setrecursionlimit(10 ** 9)


def dfs(v: int, p: int) -> None:
    for u, w in T[v]:
        if u != p:
            D[u] = D[v] + w
            dfs(u, v)


def main():
    global T, D
    N, *A = map(int, open(0).read().split())
    T = [[] for _ in range(N + 1)]
    for i in range(0, (N - 1) * 3, 3):
        v, u, w = A[i : i + 3]
        T[v] += [(u, w)]
        T[u] += [(v, w)]
    D = [0] * (N + 1)  # D[i] := distance from vertex 1 (root)
    dfs(1, -1)
    ans = [i % 2 for i in D[1:]]  # same parity of distance -> same group
    print(*ans, sep="\n")


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# ABC126D - Even Relation
def dfs(v: int, p: int) -> None:
    for u, w in T[v]:
        if u != p:
            D[u] = D[v] + w
            dfs(u, v)


def main():
    global T, D
    N, *A = map(int, open(0).read().split())
    T = [[] for _ in range(N + 1)]
    for i in range(0, (N - 1) * 3, 3):
        v, u, w = A[i : i + 3]
        T[v] += [(u, w)]
        T[u] += [(v, w)]
    D = [0] * (N + 1)  # D[i] := distance from vertex 1 (root)
    dfs(1, -1)
    ans = [i % 2 for i in D[1:]]  # same parity of distance -> same group
    print(*ans, sep="\n")


if __name__ == "__main__":
    main()
Problem p03050 (python)

Fixed submission:
# div2019D - DivRem Number
# cf. ARC026B - 完全数
def divisors(n: int) -> set:
    """
    Compute divisors of a number.
    
    Args: n (int): an integer to be evaluated.
    Returns: div (set): set of divisors
    """
    div = set()
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            div.add(i)
            div.add(n // i)
    return div


def main():
    N = int(input())
    divs = divisors(N)
    divs.discard(1)
    ans = 0
    for m in divs:
        m -= 1
        if N // m == N % m:
            ans += m
    print(ans)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# div2019D - DivRem Number
def divisors(n: int) -> set:
    # Compute divisors of a number.
    divs = set()
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            div.add(i)
            div.add(n // i)
    return divs


def main():
    N = int(input())
    divs = divisors(N)
    ans = 0
    for m in divs:
        if m == 1:
            continue
        m -= 1
        if N // m == N % m:
            ans += m
    print(ans)


if __name__ == "__main__":
    main()
Problem p03068 (python)

Fixed submission:
# TPBC201B - *e**** ********e* *e****e* ****e**
n = int(input())
s = list(input())
k = int(input())

for i in range(n):
    if s[i] != s[k - 1]:
        s[i] = "*"
print("".join(s))

Buggy submission (verdict: Runtime Error):
# TPBC201B - *e**** ********e* *e****e* ****e**
n = int(input())
s = list(input())
k = int(input())

for i in range(n):
    if s[i] != s[k]:
        s[i] = '*'
print(''.join(s))
Problem p03069 (python)

Fixed submission:
# TPBC201C - Stones
n = int(input())
s = input()
ans = 0
blk = 0
for i in s:
    if i == "#":
        blk += 1
    else:
        if blk > 0:
            ans += 1
            blk -= 1
print(ans)

Buggy submission (verdict: Runtime Error):
# TPBC201C - Stones
n = int(input())
s = list(input())
ans = 0
if len(set(s)) == 1:
    print(ans)
else:
    while s[0] == ".":
        s.pop(0)
    while s[-1] == "#":
        s.pop()
    lst = "".join(s).split(".#")
    for i in range(len(lst)):
        if i == 0:
            ans += min(lst[i].count("#"), lst[i].count(".") + 1)
        elif i == len(lst) - 1:
            ans += min(lst[i].count("#") + 1, lst[i].count("."))
        else:
            ans += min(lst[i].count("#") + 1, lst[i].count(".") + 1)
    print(ans)
Problem p03085 (python)

Fixed submission:
# ABC122A - Double Helix
# a-t, c-g
data = {"A": "T", "T": "A", "C": "G", "G": "C"}

print(data[input()])

Buggy submission (verdict: Runtime Error):
# ABC122A - Double Helix
# a-t, c-g
data = {'a': 't', 't': 'a', 'c': 'g', 'g': 'c'}

print(data[input()])
Problem p03110 (python)

Fixed submission:
# ABC119B - Digital Gifts
n = int(input())
lst = [input().rstrip().split() for _ in range(n)]
total = 0

for i in range(n):
    if lst[i][1] == 'JPY':
        total += int(lst[i][0])
    else:
        total += 380000 * float(lst[i][0])
        
print(total)

Buggy submission (verdict: Runtime Error):
# ABC119B - Digital Gifts
def main():
    _, XU = open(0).read().split()
    ans, RATE = 0, 380000
    for x, u in zip(*[iter(XU)] * 2):
        x = float(x)
        ans += x if u == "JPY" else x * RATE
    print(ans)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# ABC119B - Digital Gifts
def main():
    _, XU = open(0).read().split()
    ans, RATE = 0, 380000
    for x, u in zip(*[iter(XU)] * 2):
        x = float(x)
        total += x if u == "JPY" else x * RATE
    print(total)


if __name__ == "__main__":
    main()
Problem p03131 (python)

Fixed submission:
# yahoo-procon2019-qualC - When I hit my pocket...
def main():
    k, a, b = list(map(int, input().rstrip().split()))
    if b - a <= 2 or k < a - 1:
        print(k + 1)
        return

    ans, k = a, k - (a - 1)
    if k % 2 == 1:
        k -= 1
        ans += 1
    ans += (b - a) * k // 2
    print(ans)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# yahoo-procon2019-qualC - When I hit my pocket...
import sys
sys.setrecursionlimit(10 ** 9)


def hit(k, c, m):
    if k == 0:
        return c
    ret = []
    ret += [hit(k - 1, c + 1, m)]
    if c >= A:
        ret += [hit(k - 1, c - A, m + 1)]
    if m > 0:
        ret += [hit(k - 1, c + B, 0)]
    return max(ret)


K, A, B = list(map(int, input().rstrip().split()))
print(hit(K, 1, 0))
Problem p03151 (python)

Fixed submission:
# keyence2019C - Exam and Wizard
def main():
    N = int(input())
    A = tuple(map(int, input().split()))
    B = tuple(map(int, input().split()))
    dif = sorted(i - j for i, j in zip(A, B))
    ans, shortage = 0, 0
    for i in dif:
        if i < 0:
            ans += 1
            shortage += i
        else:
            break
    for i in dif[::-1]:
        if shortage >= 0:
            print(ans)
            return
        ans += 1
        shortage += i
    print(-1)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# keyence2019C - Exam and Wizard
def main():
    N, *AB = map(int, open(0).read().split())
    ans, shortage, pos = 0, 0, []
    for i, j in zip(AB[:N], B[N:]):
        x = i - j
        if x >= 0:
            pos.append(x)
        else:
            ans += 1
            shortage += x
    for i in sorted(pos, reverse=1):
        if shortage >= 0:
            break
        ans += 1
        shortage += i
    flg = shortage >= 0
    print(ans if flg else -1)  # -1: shoratage still remains


if __name__ == "__main__":
    main()
Problem p03163 (python)

Fixed submission:
# EduDPD - Knapsack 1
import sys
input = sys.stdin.readline

n, w = list(map(int, input().rstrip().split()))
arr = [tuple(map(int, input().rstrip().split())) for _ in range(n)]
dp = [0] * (w + 1)
for i in range(n):
    for j in range(w, arr[i][0] - 1, -1):
        dp[j] = max(dp[j], dp[j - arr[i][0]] + arr[i][1])
print(max(dp))

Buggy submission (verdict: Runtime Error):
import numpy as np

N, W = map(int, input().split())
dp = np.zeros(W + 1, dtype=np.int64)
for i in range(N):
    w, v = map(int, input().split())
    np.maximum(dp[: W - w + 1] + v, dp[w:], out=dp[w:])
print(dp[-1])