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

Fixed submission:
import bisect

N = 5
ARR = [6, 9, 4, 2, 11]


N = 2
ARR = [100, 0]

N = int(input())
ARR = list(map(int, input().split()))


def calculate(n, arr):
    arr = sorted(arr)

    mid = arr[n - 1] / 2

    a1 = bisect.bisect_left(arr, mid)

    s1 = abs(arr[a1 - 1] - (arr[n - 1] / 2))
    s2 = abs(arr[a1] - (arr[n - 1] / 2))

    if s1 > s2:
        return arr[n - 1],arr[a1]
    else:
        return arr[n-1],arr[a1-1]


n, a = calculate(N, ARR)
print(n, a)

Buggy submission (verdict: Runtime Error):
import bisect
from scipy.special import comb

N = 5
ARR = [6, 9, 4, 2, 11]


N = 2
ARR = [100, 0]

N = int(input())
ARR = list(map(int, input().split()))


def calculate(n, arr):
    arr = sorted(arr)

    mid = arr[n - 1] / 2

    a1 = bisect.bisect_left(arr, mid)

    s1 = abs(arr[a1 - 1] - (arr[n - 1] / 2))
    s2 = abs(arr[a1] - (arr[n - 1] / 2))

    if s1 > s2:
        return arr[n - 1],arr[a1]
    else:
        return arr[n-1],arr[a1-1]


n, a = calculate(N, ARR)
print(n, a)
Problem p03436 (python)

Fixed submission:
from collections import deque

H, W = 10, 37
ARR = [
    ".....................................",
    "...#...####...####..###...###...###..",
    "..#.#..#...#.##....#...#.#...#.#...#.",
    "..#.#..#...#.#.....#...#.#...#.#...#.",
    ".#...#.#..##.#.....#...#.#.###.#.###.",
    ".#####.####..#.....#...#..##....##...",
    ".#...#.#...#.#.....#...#.#...#.#...#.",
    ".#...#.#...#.##....#...#.#...#.#...#.",
    ".#...#.####...####..###...###...###..",
    ".....................................",
]

H, W = map(int, input().split())
ARR = []

for i in range(H):
    ARR.append(input())


def calculate(h, w, arr):
    q = deque()

    q.append((0, 0))

    dx = [0, 1, 0, -1]
    dy = [-1, 0, 1, 0]

    distance = [[0 for i in range(w)] for j in range(h)]
    distance[0][0] = 1
    while q.__len__() > 0:
        y, x = q.popleft()
        for i in range(4):
            my = y + dy[i]
            mx = x + dx[i]
            if (my >= 0) and (mx >= 0) and (my <= (h - 1)) and (mx <= (w - 1)) and (distance[my][mx] == 0) and (
                    arr[my][mx] == "."):
                distance[my][mx] = distance[y][x] + 1
                q.append((my, mx))

    mmk = 0
    for j in range(h):
        mmk += arr[j].count("#")

    if distance[h - 1][w - 1] == 0:
        print(-1)
    else:
        print(h * w - distance[h - 1][w - 1] - mmk)


calculate(H, W, ARR)

Buggy submission (verdict: Runtime Error):

H, W = map(int,input().split())
ARR = []

for i in range(H):
    ARR.append(input())


def calculate(h, w, arr):
    total = h * w
    distance = h + w - 1
    alreadyPaiting = 0

    for s in arr:
        a = Counter(list(s))
        b = a.get("#")

        if b != None:
            alreadyPaiting += b

    return total - distance - alreadyPaiting


result = calculate(H, W, ARR)

print(result)
Problem p03611 (python)

Fixed submission:
N = int(input())
ARR = [int(s) for s in input().split(" ")]

def calculate(n,arr):

    dict = {}

    for ar in arr:
        a1 = ar - 1
        a2 = ar
        a3 = ar + 1

        if dict.get(a1) == None:
            dict.__setitem__(a1,1)
        else:
            dict.__setitem__(a1,dict.get(a1)+1)

        if dict.get(a2) == None:
            dict.__setitem__(a2, 1)
        else:
            dict.__setitem__(a2, dict.get(a2) + 1)

        if dict.get(a3) == None:
            dict.__setitem__(a3, 1)
        else:
            dict.__setitem__(a3, dict.get(a3) + 1)


    print(max(dict.values()))
calculate(N,ARR)

Buggy submission (verdict: Runtime Error):
N = int(input())
ArR = [int(s) for s in input().split(" ")]

def calculate(n,arr):

    dict = {}

    for ar in arr:
        a1 = ar - 1
        a2 = ar
        a3 = ar + 1

        if dict.get(a1) == None:
            dict.__setitem__(a1,1)
        else:
            dict.__setitem__(a1,dict.get(a1)+1)

        if dict.get(a2) == None:
            dict.__setitem__(a2, 1)
        else:
            dict.__setitem__(a2, dict.get(a2) + 1)

        if dict.get(a3) == None:
            dict.__setitem__(a3, 1)
        else:
            dict.__setitem__(a3, dict.get(a3) + 1)


    print(max(dict.values()))
calculate(N,ARR)
Problem p03846 (python)

Fixed submission:
import math

N = 5
ARR = [2, 4, 4, 0, 2]

N = 7
ARR = [6, 4, 0, 2, 4, 0, 2]
#
# N = 8
# ARR = [7, 5, 1, 1, 7, 3, 5, 3]
#
N = int(input())
ARR = list(map(int, input().split()))


def calculate(n, arr):
    if n % 2 == 0:
        n = n // 2
        start = 1
        finalResult = pow(2, n, 1000000000 + 7)
    else:
        n = n // 2 + 1
        start = 0
        finalResult = pow(2, (n - 1), 1000000000 + 7)

    result = {}
    for i in range(n):
        index = start + 2 * i
        if index == 0:
            result.__setitem__(0, 1)
        else:
            result.__setitem__(index, 2)

    isOk = True
    for i in range(len(arr)):
        if result.get(arr[i]) == None:
            isOk = False
            break

        if result.get(arr[i]) == 0:
            isOk = False
            break

        result.__setitem__(arr[i], result.get(arr[i])-1)

    if isOk == False:
        print(0)
        return

    if sum(result.values()) == 0:
        print(finalResult)
    else:
        print(0)


calculate(N, ARR)

Buggy submission (verdict: Runtime Error):
import math

N = 5
ARR = [2, 4, 4, 0, 2]

N = 7
ARR = [6, 4, 0, 2, 4, 0, 2]

N = 8
ARR = [7, 5, 1, 1, 7, 3, 5, 3]

N = int(input())
ARR = list(map(int, input().split()))


def calculate(n, arr):
    if n % 2 == 0:
        n = n // 2
        start = 1
        finalResult = pow(2, n, 1000000000 + 7)
    else:
        n = n // 2 + 1
        start = 0
        finalResult = pow(2, (n - 1), 1000000000 + 7)

    result = {}
    for i in range(n):
        index = start + 2 * i
        if index == 0:
            result.__setitem__(0, 1)
        else:
            result.__setitem__(index, 2)

    isOk = True
    for i in range(len(arr)):
        aa = result.get(arr[i])
        aa = aa - 1
        if aa < 0:
            isOk = False
            break
        result.__setitem__(arr[i], aa)

    if sum(result.values()) != 0:
        isOk = False

    if isOk:
        print(finalResult)
    else:
        print(0)


calculate(N, ARR)

Buggy submission (verdict: Runtime Error):
N = 5
ARR = [2, 4, 4, 0, 2]

N = 7
ARR = [6, 4, 0, 2, 4, 0, 2]

N = 8
ARR = [7, 5, 1, 1, 7, 3, 5, 3]

N = int(input())
ARR = list(map(int,input().split()))

def calculate(n, arr):
    if n % 2 == 0:
        n = n // 2
        start = 1
        finalResult = 2 ** n
    else:
        n = n // 2 + 1
        start = 0
        finalResult = 2 ** (n - 1)

    result = {}
    for i in range(n):
        index = start + 2 * i
        if index == 0:
            result.__setitem__(0, 1)
        else:
            result.__setitem__(index, 2)

    isOk = True
    for i in range(len(arr)):
        aa = result.get(arr[i])
        aa = aa - 1
        if aa < 0:
            isOk = False
            break
        result.__setitem__(arr[i], aa)


    if sum(result.values()) != 0:
        isOk = False

    if isOk:
        print(finalResult)
    else:
        print(0)

calculate(N, ARR)
Problem p02553 (python)

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

print(max(a*c, a*d, b*c, b*d))

Buggy submission (verdict: Runtime Error):
if b > 0 and d > 0:
    print(max(b*d, a*c))
elif b > 0 and d < 0:
    print(a*d)
elif b < 0 and d > 0:
    print(b*c)
elif b <= 0 and d <= 0:
    print(a*c)
Problem p02642 (python)

Fixed submission:
N = int(input())
A = [int(n) for n in input().split()]
maxA = max(A)

C = {a:0 for a in A}
D = {a:0 for a in A}
for a in A:
    C[a] += 1
for a in A:
    if C[a] > 0:
        t = 2
        while a*t <= maxA:
            D[a*t] = 1
            t += 1
ans = 0
for a in A:
    if C[a] == 1 and D[a] == 0:
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [int(n) for n in input().split()]
ans = 1

A_set = set(A)
A_set = list(A_set)
if len(A_set) == 1:
    print(0)
else:
    for i in range(N):
        for j in range(i):
            if A_set[i] % A_set[j] == 0:
                break
            if j == i-1:
                ans += 1
    print(ans)
Problem p02705 (python)

Fixed submission:
import math
R = int(input())
pi = math.pi
print(2*R*pi)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = input().split()
for i in range(N):
  count = 0
  for j in range(N-1):
    if i+1 == int(A[j]):
      count += 1
  print(count)
Problem p02706 (python)

Fixed submission:
N, M = map(int, input().split())
A = []
A = input().split()
A = [int(n) for n in A]
for i in range(M):
  N -= A[i]
if N >= 0:
  print(N)
else:
  print("-1")

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = []
A = input().split()
A = [int(n) for n in A]
for i in range(M):
  N -= A[i]
print(N)
N, M = map(int, input().split())
A = []
A = input().split()
A = [int(n) for n in A]
for i in range(M):
  N -= A[i]
if N >= 0:
  print(N)
else:
  print("-1")
Problem p02713 (python)

Fixed submission:
def gcd(a, b):
  if a < b:
    a_init = a
    a = b
    b = a_init
  while b != 0:
    r = a % b
    a = b
    b = r
  return a
	
K = int(input())
count = 0
temp = []
for a in range(1, K+1):
	for b in range(1, a):
		temp.append(gcd(a, b))
for c in range(1, K+1):
	for j in range(len(temp)):
		count += gcd(c, temp[j]) * 2
	for k in range(1, K+1):
		count += gcd(c, k)
print(count)

Buggy submission (verdict: Runtime Error):
K = int(input())
gcd_sum = 0
for a in range(1,K+1):
  a_init = a
  for b in range(1, K+1):
	b_init = b
    for c in range(1, K+1):
      a = a_init
	  b = b_init						
	  m = min(a, b, c)
	  gcd = 1
	  for i in range(2, m+1):
	    if a%i == 0 and b%i == 0 and c%i == 0:
	      a /= i
          b /= i
          c /= i
		  gcd *= i
	  gcd_sum += gcd
print(gcd_sum)

Buggy submission (verdict: Runtime Error):
K = int(input())
gcd_sum = 0
for a in range(1,K+1):
  a_init = a
  for b in range(1, K+1):
	b_init = b
    for c in range(1, K+1):
      a = a_init
	  b = b_init						
	  m = min(a, b, c)
	  gcd = 1
	  for i in range(2, m+1):
	    if a%i == 0 and b%i == 0 and c%i == 0:
	      a /= i
		  b /= i
		  c /= i
		  gcd *= i
	  gcd_sum += gcd
print(gcd_sum)
Problem p02642 (python)

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

a.sort()

#print(a)
import numpy as np
U=10**6 + 5
is_prime = np.zeros(U,np.bool)
#is_prime[2] = 1
is_prime[1::] = 1
M = int(U**.5)+1
for ai in a:#range(3,M,2):
    if is_prime[ai]:
        is_prime[ai*2::ai] = 0
    #print(is_prime.nonzero()[0])

ans = 0

import collections
cnt = collections.Counter(a)
for ai in a:
    if is_prime[ai] and cnt[ai] == 1:
        ans += 1

print(ans)

"""
sa = set()
for ai in a:
    if ai in sa:
        sa.discard(ai)
        continue
    sa.add(ai)
"""

"""
p = list(range(10**6+10))

a = list(sa)
a.sort()

print(a)

import fractions
def lcm(a, b):
    return a * b // fractions.gcd(a, b)

ans = 1
l = 1
for i in range(n):
    if lcm(a[i], l) < a[i] * l:
        continue
    l = lcm(a[i], l)
    ans += 1
print(ans)

"""

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int , input().split()))
sa = set()
for ai in a:
    if ai in sa:
        sa.discard(ai)
        continue
    sa.add(ai)

if len(sa) == 0:
    print(0)
    exit()

a = list(sa)
a.sort()

#print(a)

import fractions
def lcm(a, b):
    return a * b // fractions.gcd(a, b)

ans = 1
l = 1
for i in range(n):
    if lcm(a[i], l) < a[i] * l:
        continue
    l = lcm(a[i], l)
    ans += 1
print(ans, l)
Problem p02744 (python)

Fixed submission:
n = int(input())

ans = []
def dfs(x):
    if len(x) == n:
        ans.append(x)
        return
    for i in range(0, max(x)+1):
        y = x.copy()
        y.append(i+1)
        dfs(y)
dfs([1])
#print(ans)

r = ['a','b','c','d','e','f','g','h','i','j']
for ai in ans:
    print(''.join(map(lambda x: str(r[x-1]), ai)))

Buggy submission (verdict: Runtime Error):
n = int(input())
ans = [[] for _ in range(2**(n-1))]

ans[0].append([1])
ans[1].append([1,1])
ans[1].append([1,2])
#ans[2].append([1,1,1])
#ans[2].append([1,1,2])
#ans[2].append([1,2,2])
#ans[2].append([1,2,3])
import numpy as np

for i in range(2, n):
    for j in range(2):
        for ai in ans[i-1]:
            x = np.array(ai)
            y = list(x+j)
            ans[i].append([1] + y)

r = ['a','b','c','d','e','f','g','h','i','j','k']
for ai in ans[n-1]:
    print(''.join(map(lambda x: str(r[x-1]), ai)))
Problem p02761 (python)

Fixed submission:
n, m = map(int, input().split())
sc = [tuple(map(int, input().split())) for _ in range(m)]
sc = sorted(sc, key=lambda x:x[0])

if m != 0 and n != 1 and sc[0][0] == 1 and sc[0][1] == 0:
    print(-1)
    exit()
if m == 0 and n == 1:
    print(0)
    exit()

ans = [0] * n
ans[0] = 1
prev = (0, 0)
if m != 0:
    prev = sc[0]
for i in range(m):
    if prev[0] == sc[i][0] and prev[1] != sc[i][1]:
        print(-1)
        exit()
    ans[sc[i][0]-1] = sc[i][1]
    prev = sc[i]
print(''.join(map(lambda x: str(x), ans)))

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
sc = [tuple(map(int, input().split())) for _ in range(m)]
sc = sorted(sc, reverse=True, key=lambda x:x[0])
if sc[0][0] != n:
    print(-1)
    exit()

ans = [0] * n
ans[0] = 1
prev = sc[0]

for i in range(1, m):
    if prev[0] == sc[i][0] and prev[1] != sc[i][1]:
        print(-1)
        exit()
    ans[sc[i][0]-1] = sc[i][1]
    prev = sc[i]
print(ans)
print(''.join(map(lambda x: str(x), ans)))
Problem p02803 (python)

Fixed submission:
from collections import deque
#import numpy as np

h, w = map(int, input().split())
S = [input() for _ in range(h)] # #.のグリッドの場合

starts = []
for i in range(h):
    for j in range(w):
        if S[i][j] == '.':
            starts.append((i,j))

step = [(1, 0), (-1, 0), (0, 1), (0, -1)]
ans = 0
for si in starts:
    maxlen = 0
    seen = [[0] * w for _ in range(h)]
    que = deque()
    que.append(si)
    #seen[si[0]][si[1]] = 1
    while len(que) > 0:
        x, y = que.popleft()
        for xs, ys in step:
            xi, yi = x + xs, y + ys
            if xi < 0 or yi < 0 or xi >= h or yi >= w:
                continue
            if xi == si[0] and yi == si[1]:
                continue
            if S[xi][yi] == '#':
                continue
            if seen[xi][yi] != 0:
                continue
            else:
                seen[xi][yi] = seen[x][y] + 1
                que.append((xi, yi))
                maxlen = max(maxlen, seen[xi][yi])
    #print(np.array(seen))
    ans = max(ans, maxlen)
print(ans)

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

h, w = map(int, input().split())
S = [input() for _ in range(h)] # #.のグリッドの場合

starts = []
for i in range(h):
    for j in range(w):
        if S[i][j] == '.':
            starts.append((i,j))

step = [(1, 0), (-1, 0), (0, 1), (0, -1)]
ans = 0
for si in starts:
    maxlen = 0
    seen = [[0] * w for _ in range(h)]
    que = deque()
    que.append(si)
    while len(que) > 0:
        x, y = que.popleft()
        for xs, ys in step:
            xi, yi = x + xs, y + ys
            if xi < 0 or yi < 0 or xi >= h or yi >= w:
                continue
            if S[xi][yi] == '#':
                continue
            if seen[xi][yi] != 0:
                continue
            else:
                seen[xi][yi] = seen[x][y] + 1
                que.append((xi, yi))
                maxlen = max(maxlen, seen[xi][yi])
    #print(np.array(seen))
    ans = max(ans, maxlen)
print(ans)
Problem p02837 (python)

Fixed submission:
import itertools
n = int(input())
xy = [0 for _ in range(n)]
for i in range(n):
    ai = int(input())
    xy[i] = [list(map(int , input().split())) for _ in range(ai)]

#print(xy)
#print(xy[0])
#print(xy[0][0])
ans = 0
for i in itertools.product([0, 1], repeat=n):
    ok = True
    cnt = sum(i)
    for j in range(n):
        xyj = xy[j]
        if i[j] == 1:
            for xyk in xyj:
                if xyk[1] == 1:
                    if i[xyk[0]-1] == 0:
                        ok = False
                elif xyk[1] == 0:
                    if i[xyk[0]-1] == 1:
                        ok = False
    #print(ok, i)
    if ok:
        ans = max(ans, cnt)

print(ans)

Buggy submission (verdict: Runtime Error):
import itertools
n = int(input())
xy = [0 for _ in range(n)]
for i in range(n):
    ai = int(input())
    xy[i] = [list(map(int , input().split())) for _ in range(ai)]

#print(xy)
#print(xy[0])
#print(xy[0][0])
ans = 0
for i in itertools.product([0, 1], repeat=n):
    ok = True
    cnt = sum(i)
    for j in range(n):
        xyj = xy[j]
        for xyk in xyj:
            if xyk[1] == 0:
                if i[xyk[0]] == 1:
                    ok = False
            elif xyk[1] == 1:
                if i[xyk[0]] == 0:
                    ok = False
    if ok:
        ans = max(ans, cnt)

print(ans)
Problem p02924 (python)

Fixed submission:
n = int(input())
ans = n * (n-1) // 2
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(range(1, n))
print(sum(a))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(range(1, n))
print(sum(map(lambda n: n % (n+1), a)))
Problem p02995 (python)

Fixed submission:
import fractions

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

def func(n, x, y):
    lcm = x * y // fractions.gcd(x, y)
    return n - (n // x + n // y - n // lcm)

print(func(b, c, d) - func(a - 1, c, d))

Buggy submission (verdict: Runtime Error):
import math

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

def func(n, x, y):
    lcm = x * y // math.gcd(x, y)
    return n - (n // x + n // y - n // lcm)

print(func(b, c, d) - func(a - 1, c, d))
Problem p03136 (python)

Fixed submission:
n = int(input())
l = list(map(int , input().split()))
l.sort(reverse=True)
#print(l[0], sum(l[1:]))
if l[0] < sum(l[1:]):
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
x = input().split()
#x = "3 5 0 4 3 6 2 7 2 5 3 3 4 0 5 3 7 5 3 7 2 7 5 7 0 7 2 9 3 2 9 1 3 6 2 0 2 4 6 4 2 3 3 5 7 4 0 6 9 7 6 7 9 8 5 2 2 0 4 7 6 5 5 4 6 3 2 3 0 5 4 3 3 6 2 3 4 2 4 0 8 9 4 6 5 4 3 5 3 2 0 8 2 1 3 4 5 7 8 6 4 0 3 5 2 6 1 2 5 3 2 1 6 9 2 5 6".split()
#x = "2 4 0 9 9 9 9 9 9 9 9 9 9 0 9 9 9 9 9 9 9 9 9 9 0 9 9 9 9 9 9 9 9 9 9 0 9 9 9 9 9 9 9 9 9 9 0 9 9 9 9 2 9 9 9 9 9 0 9 9 9 9 9 9 9 9 9 9 0 9 9 9 9 9 9 9 9 9 9 0 9 9 9 9 9 9 2 9 9 9 0 9 9 2 9 9 9 9 9 9 9 0 -1 -1 -1 -1 8 1 1 8".split()
h = int(x[0])
w = int(x[1])
d = []
for i in range(10):
    d.append(
        list(map(int, x[2 + i * 10 : 2 + i * 10 + 10]))
    )
a = []
for i in range(h):
    a.append(
        list(map(int, x[102 + i * w: 102 + i * w + w]))
    )
#d = [[0] * 10] * 10
for k in range(10):
    for i in range(10):
        for j in range(10):
            if d[i][j] > d[i][k] + d[k][j]:
                d[i][j] = d[i][k] + d[k][j]

#for k in range(0, 10):
#    print(c[k])
#for k in range(0, 10):
#    print(d[k])
#print(d[8][1])

ans = 0
for i in range(h):
    for j in range(w):
        if a[i][j] != 1 or a[i][j] != -1:
            ans += d[a[i][j]][1]
print(ans)
Problem p03146 (python)

Fixed submission:
s = int(input())
a = [s]
z = set([s])
idx = 1
for i in range(10**8):
    idx += 1
    if a[i] % 2 == 0:
        ai = a[i] // 2
    else:
        ai = 3 * a[i] + 1
    if ai in z:
        print(idx)
        exit()
    a.append(ai)
    z.add(ai)

Buggy submission (verdict: Runtime Error):
s = int(input())
a = [s]
z = set(s)
idx = 1
for i in range(10**8):
    idx += 1
    if a[i] % 2 == 0:
        ai = a[i] // 2
    else:
        ai = 3 * a[i] + 1
    if ai in z:
        print(idx)
        exit()
    a.append(ai)
    z.add(ai)
Problem p03163 (python)

Fixed submission:
import numpy as np

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

dp = np.zeros((n+1, w+1), np.int64)

for i, (wi, vi) in enumerate(wv):
    dp[i+1] = dp[i]
    np.maximum(dp[i][wi:], dp[i][:-wi] + vi, out=dp[i+1][wi:])
"""
for i in range(n):
    for sum_w in range(w+1):
        wi = wv[i][0]
        vi = wv[i][1]
        if sum_w - wi >= 0:
            dp[i+1][sum_w] = dp[i][sum_w - wi] + vi
        dp[i+1][sum_w] = max(dp[i][sum_w], dp[i+1][sum_w])
"""
#print(dp)
print(dp[n][w])

Buggy submission (verdict: Runtime Error):
import numpy as np
n, w = map(int, input().split())
wv = [tuple(map(int, input().split())) for _ in range(n)]

dp = np.zeros((n+1, w+1), np.int64)

for i in range(n):
    for sum_w in range(w+1):
        wi = wv[i][0]
        vi = wv[i][1]
        if sum_w - wi >= 0:
            #dp[i+1][sum_w] = max(dp[i][sum_w - wi] + vi, dp[i+1][sum_w])
            dp[i+1][sum_w] = dp[i][sum_w - wi] + vi
        dp[i+1][sum_w] = max(dp[i][sum_w], dp[i+1][sum_w])

print(dp[n][w])
Problem p03164 (python)

Fixed submission:
import numpy as np
n, w = map(int, input().split())
wv = [tuple(map(int, input().split())) for _ in range(n)]

INF = 10**9 + 100
MAX_V = 10 ** 6

dp = np.full((n+1, MAX_V), INF, np.int64)
dp[0][0] = 0

for i, (wi, vi) in enumerate(wv):
    dp[i+1] = dp[i]
    np.minimum(dp[i][vi:], dp[i][:-vi] + wi, out=dp[i+1][vi:])

ans = np.where(dp[n] <= w)[0][-1]
print(ans)

Buggy submission (verdict: Runtime Error):
n, w = map(int, input().split())
wv = [tuple(map(int, input().split())) for _ in range(n)]

INF = 10**9 + 100
MAX_V = 10**5 + 100
dp = [INF] * (MAX_V + 1)
dp[0] = 0

for wi, vi in wv:
	for sum_v in reversed(range(vi, MAX_V+1)):
        dp[sum_v] = min(dp[sum_v - vi] + wi, dp[sum_v])
#print(dp)
ans = 0
for i in range(MAX_V, -1, -1):
    if dp[i] <= w:
        print(i)
        exit()
#print(ans)
Problem p03165 (python)

Fixed submission:
s = input()
t = input()
ls = len(s)
lt = len(t)
dp = [[0] * (lt+1) for _ in range(ls+1)]

for i in range(ls):
    for j in range(lt):
        if s[i] == t[j]:
            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j]+1)
        dp[i+1][j+1] = max(dp[i+1][j+1], dp[i+1][j])
        dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j+1])

#import numpy as np
#print(np.array(dp))

#from collections import deque
#ans = deque()

ans = ''
i, j = ls, lt
while i > 0 and j > 0:
    if dp[i][j] == dp[i-1][j]:
        i -= 1
    elif dp[i][j] == dp[i][j-1]:
        j -= 1
    else:
        i -= 1
        j -= 1
        #ans.appendleft(s[i])
        ans = s[i] + ans
#print(''.join(ans))
print(ans)

Buggy submission (verdict: Runtime Error):
s = input()
t = input()
ls = len(s)
lt = len(t)
dp = [[0] * (lt+1) for _ in range(ls+1)]

for i in range(ls):
    for j in range(lt):
        if s[i] == t[j]:
            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j]+1)
        dp[i+1][j+1] = max(dp[i+1][j+1], dp[i+1][j])
        dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j+1])

#import numpy as np
#print(np.array(dp))

#from collections import deque
#ans = deque()

ans = []
i, j = ls, lt
while i > 0 and j > 0:
    if dp[i][j] == dp[i-1][j]:
        i -= 1
    elif dp[i][j] == dp[i][j-1]:
        j -= 1
    else:
        i -= 1
        j -= 1
        #ans.appendleft(s[i])
        ans = s[i] + ans
#print(''.join(ans))
print(ans)