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

Fixed submission:
from collections import defaultdict
from collections import deque
from collections import Counter
import itertools
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n = readInt()

d = Counter(readInts())

d = [i for i in sorted(d.items(), reverse=True) if i[1]>=2]

if len(d)==0:
	print(0)
	exit()
elif len(d)==1:
	if d[0][1]>=4:
		pass
	else:
		print(0)
		exit()
if d[0][1]>=4:
	print(int(d[0][0])**2)
else:
	print(int(d[0][0])*int(d[1][0]))

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
from collections import deque
import itertools
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

d = defaultdict(int)
n = readInt()
for i in readChars():
	d[i]+=1

d = [i for i in sorted(d.items(), reverse=True) if i[1]>=2]

if len(d)==0:
	print(0)
	exit()
elif len(d)==1:
	if d[0][1]>=4:
		pass
	else:
		print(0)
		exit()
if d[0][1]>=4:
	print(int(d[0][0])**2)
else:
	print(int(d[0][0])*int(d[1][0]))
	raise Exception

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
from collections import deque
import itertools
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

d = defaultdict(int)
n = readInt()
for i in readChars():
	d[i]+=1

d = [i for i in sorted(d.items(), reverse=True) if i[1]>1]

if len(d)==0:
	print(0)
	exit()
elif len(d)==1:
	if d[0][1]>=4:
		continue
	else:
		print(0)
		exit()

if d[0][1]>=4:
	print(int(d[0][0])**2)
else:
	print(int(d[0][0])*int(d[1][0]))
Problem p03695 (python)

Fixed submission:
from collections import defaultdict

def readInt():
  return int(input())
def readInts():
  return list(map(int, input().split()))
def readChar():
  return input()
def readChars():
  return input().split()

n = readInt()
a = readInts()
rate = [0]*9


for i in a:
  rate[min(i//400,8)]+=1
base = 8-rate[:-1].count(0)
ma = base+rate[-1]
print(max(base,1),ma)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

rate = [0]*9
n = readInt()
a = readInts()

for i in a:
	rate[i//400]+=1

print(8-rate[:-1].count(0),end=" ")
print(min(9,(8-rate[:-1].count(0))+rate[-1]))
Problem p02536 (python)

Fixed submission:
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    def size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
    def group_count(self):
        return len(self.roots())
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


N, M = map(int, input().split())
uf = UnionFind(N)
ans = 0
for i in range(M):
    A, B = map(int, input().split())
    uf.union(A-1,B-1)
print(uf.group_count()-1)

Buggy submission (verdict: Runtime Error):
# https://note.nkmk.me/python-union-find/
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    def size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
    def group_count(self):
        return len(self.roots())
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


N, M = map(int, input().split())
uf = UnionFind(N)
ans = 0
for i in range(M):
    A, B = map(int, input().split())
    if not uf.same(A,B):
        ans += 1
    else:
        uf.union(A-1,B-1)
print(ans)
Problem p02555 (python)

Fixed submission:
MOD = 10**9 + 7
def comb(n, k):
    if n < k or n < 0 or k < 0:
        return 0
    if k == 0:
        return 1
    iinv = [1] * (k + 1)
    ans = n
    for i in range(2, k + 1):
        iinv[i] = MOD - iinv[MOD % i] * (MOD // i) % MOD
        ans *= (n + 1 - i) * iinv[i] % MOD
        ans %= MOD
    return ans
S = int(input())
ans = 0
for i in range(1,S+1):
    tmp = S
    tmp -= i*3
    if tmp < 0:
        continue
    ans += comb(i+tmp-1,tmp)
    ans %= MOD
print(ans)

Buggy submission (verdict: Runtime Error):
MOD = 10**9 + 7
S = int(input())
dp = [0]*(S+1)
dp[0] = 1
dp[3] = 1
for i in range(4,S+1):
    for k in range(i-2):
        dp[i] += dp[k]
print(dp[S]%MOD)
Problem p02691 (python)

Fixed submission:
from collections import defaultdict
d = defaultdict(int)
N = int(input())
arr = list(map(int, input().split()))
ans = 0
for i in range(N):
    ans += d[(i+1)-arr[i]]
    d[(i+1)+arr[i]] += 1
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
arr = list(map(int, input().split()))
memo = [0]*((10**9)*2)
ans = 0
for i in range(N):
    if (i+1)-arr[i] >= 0:
        ans += memo[(i+1)-arr[i]]
    if (i+1)+arr[i] > 0:
        memo[(i+1)+arr[i]] += 1
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
arr = list(map(int, input().split()))
memo = [0]*((max(arr)+N)*2)
ans = 0
for i in range(N):
    if (i+1)-arr[i] >= 0:
        ans += memo[(i+1)-arr[i]]
    if (i+1)+arr[i] > 0:
        memo[(i+1)+arr[i]] += 1
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
arr = list(map(int, input().split()))
memo = [0]*(max(arr)*2+1000)
ans = 0
for i in range(N):
    if (i+1)-arr[i] >= 0:
        ans += memo[(i+1)-arr[i]]
    if (i+1)+arr[i] > 0:
        memo[(i+1)+arr[i]] += 1
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
arr = list(map(int, input().split()))
memo = [0]*(max(arr)*2)
ans = 0
for i in range(N):
    if (i+1)-arr[i] >= 0:
        ans += memo[(i+1)-arr[i]]
    if (i+1)+arr[i] > 0:
        memo[(i+1)+arr[i]] += 1
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
arr = list(map(int, input().split()))
memo = [0]*(max(arr)+N+1)
ans = 0
for i in range(N):
    if (i+1)-arr[i] >= 0:
        ans += memo[(i+1)-arr[i]]
    if (i+1)+arr[i] > 0:
        memo[(i+1)+arr[i]] += 1
print(ans)
Problem p02743 (python)

Fixed submission:
from decimal import *
getcontext().prec = 50
a, b ,c = map(int, input().split())
if Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt():
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
from decimal import *
getcontext().prec = ２8
a, b ,c = map(int, input().split())
if Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt():
    print('Yes')
else:
    print('No')
Problem p02855 (python)

Fixed submission:
H, W, K = map(int, input().split())
grid = [input() for _ in range(H)]
ans = [[0]*W for _ in range(H)]
empty_index = [False]*H
first_flg = False
cnt = 0
for i in range(H):
    if '#' not in grid[i]:
        empty_index[i] = True
for i in range(H):
    if not empty_index[i] and not first_flg:
        first_flg = True
        first_index = i
    if not first_flg:
        continue
    if empty_index[i]:
        for k in range(W):
            ans[i][k] = ans[i-1][k]
    else:
        cnt += 1
        flg = False
        for k in range(W):
            if grid[i][k] == '#':
                if not flg:
                    flg = True
                else:
                    cnt += 1
            ans[i][k] = cnt
for i in range(H):
    if not empty_index[i]:
        break
    for k in range(W):
        ans[i][k] = ans[first_index][k]
for i in ans:
    print(*i)

Buggy submission (verdict: Runtime Error):
H, W, K = map(int, input().split())
cake = []
for _ in range(W):
    cake.append(input())
ans = []
count = 1
flg = False
for i in range(H):
    tmp = []
    for k in range(W):
        if flg and cake[i][k] == '#':
            count += 1
            tmp.append(count)
            flg = False
            continue
        if cake[i][k] == '#':
            flg = True
            tmp.append(count)
        else:
            tmp.append(count)
    flg = False
    count += 1
    ans.append(tmp)
for i in ans:
    for k in i:
        print(k,end=" ")
    print()
Problem p02861 (python)

Fixed submission:
import math
def calc(x_i,x_j,y_i,y_j):
    tmp = ((x_i)-(x_j))**2
    tmp += ((y_i)-(y_j))**2
    return math.sqrt(tmp)
N = int(input())
array = []
for _ in range(N):
    array.append(list(map(int, input().split())))
sum = 0
check = []
kai = 1
for i in range(1,N+1):
    kai *= i
    if i == N - 1:
        tmp = kai
for i in range(N):
    for k in range(N):
        if k == i:
            continue
        sum += calc(array[i][0],array[k][0],array[i][1],array[k][1])
sum *= tmp
print(sum/kai)

Buggy submission (verdict: Runtime Error):
import math
mod = 10**9 + 7
def P(n, r):
    return math.factorial(n)//math.factorial(n-r)
def C(n, r):
    return P(n, r)//math.factorial(r)
X, Y = map(int,input().split())
if (X+Y) % 3 != 0:
    print(0)
    exit()
n = (2*Y-X)//3
m = (2*X-Y)//3
print(C(n+m,m) % mod)
Problem p02866 (python)

Fixed submission:
N = int(input())
array = list(map(int, input().split()))
if array[0] != 0:
    print(0)
    exit()
array.sort()
if 1 in array and len(set(array[1:])) == 1:
    print(1)
    exit()
if not (2 in array):
    print(0)
    exit()
if 0 in array[1:]:
    print(0)
    exit()
index = array.index(2)
count = 1
count_old = array.count(1)
ans = 1
first = array[index]
for i in range(index,N-1):
    if first != array[i+1]:
        if first != array[i+1] - 1:
            print(0)
            exit()
        ans *= count_old ** count
        count_old = count
        count = 1
    else:
        count += 1
    first = array[i+1]
    ans %= 998244353
ans *= count_old ** count
ans %= 998244353
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
array = list(map(int, input().split()))
if array[0] == 1:
    print(0)
    exit()
array.sort()
index = array.index(2)
count = 1
count_old = array.count(1)
ans = 1
first = array[index]
for i in range(index,N-1):
    if first != array[i+1]:
        ans *= count_old ** count
        count_old = count
        count = 1
    else:
        count += 1
    first = array[i+1]
    ans %= 998244353
ans *= count_old ** count
ans %= 998244353
print(ans)
Problem p02936 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
N, Q = map(int, input().split())
graph = [[] for _ in range(N)]
point = [0]*N
for i in range(N-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)
for i in range(Q):
    p, x = map(int, input().split())
    point[p-1] += x
def dfs(s,parent):
    for i in graph[s]:
        if i == parent:
            continue
        point[i] += point[s]
        dfs(i,s)
dfs(0,-1)
print(*point)

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())
graph = [[] for _ in range(N)]
point = [0]*N
for i in range(N-1):
    a, b = map(int, input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
for i in range(Q):
    p, x = map(int, input().split())
    point[p-1] += x
def dfs(s,parent):
    for i in graph[s]:
        if i == parent:
            continue
        point[i] += point[s]
        dfs(i,s)
dfs(0,-1)
print(*point)
Problem p02947 (python)

Fixed submission:
import math

def P(n, r):
    return math.factorial(n)//math.factorial(n-r)

def C(n, r):
    return P(n, r)//math.factorial(r)

N = int(input())
arr = {}
ans = 0
for _ in range(N):
    S = input()
    tmp_arr = []
    for i in range(10):
        tmp_arr.append(S[i])
    tmp_arr.sort()
    moji_sorted = ''
    for i in tmp_arr:
        moji_sorted += i
    if moji_sorted in arr:
        arr[moji_sorted] += 1
    else:
        arr[moji_sorted] = 1
# print(arr)

for i in arr.values():
    if i-2 >= 0:
        ans += C(i,2)

print(ans)

Buggy submission (verdict: Runtime Error):
import math
def P(n, r):
    return math.factorial(n)//math.factorial(n-r)
def C(n, r):
    return P(n, r)//math.factorial(r)
def moji(s):
    tmp = []
    for i in range(10):
        tmp.append(s[i])
    tmp.sort()
    new_s = ''
    for i in range(10):
        new_s += tmp[i]
    return new_s

N = int(input())
dic = {}
ans = 0
for i in range(N):
    tmp = moji(input())
    if tmp in dic:
        dic[tmp] += 1
    else:
        dic[tmp] = 1
for i in dic.values():
    ans += C(i,2)
print(ans)

Buggy submission (verdict: Runtime Error):
import math

def P(n, r):
    return math.factorial(n)//math.factorial(n-r)

def C(n, r):
    return P(n, r)//math.factorial(r)

N = int(input())
arr = {}
ans = 0
for _ in range(N):
    S = input()
    tmp_arr = []
    for i in range(10):
        tmp_arr.append(S[i])
    tmp_arr.sort()
    moji_sorted = ''
    for i in tmp_arr:
        moji_sorted += i
    if moji_sorted in arr:
        arr[moji_sorted] += 1
    else:
        arr[moji_sorted] = 1
# print(arr)

for i in arr.values():
    ans += C(i,2)

print(ans)
Problem p02995 (python)

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

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

cd = lcm(c, d)

# cの倍数とdの倍数の個数を数える
# cの倍数dの倍数の個数を引く
ca = ((a-1) // c)
# print(ca)
cb = (b // c)
# print(cb)
tmp_c = cb - ca

da = (a // d)
# print(da)
db = (b // d)
# print(db)
tmp_d = db - da

cda = (a // cd)
# print(cda)
cdb = (b // cd)
# print(cdb)
tmp_cd = cdb - cda
ans = b - a + 1 - (tmp_c + tmp_d - tmp_cd)

print(ans)

Buggy submission (verdict: Runtime Error):
import math
a, b, c, d = map(int, input().split())
ans = 0

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

cd = lcm(c, d)

ca = (a // c)
cb = (b // c)
tmp_c = cb - ca

da = (a // d)
db = (b // d)
tmp_d = db - da

cda = (a // cd)
cdb = (b // cd)
tmp_cd = cdb - cda
ans = b - a - (tmp_c + tmp_d - tmp_cd) + 1

print(ans)

Buggy submission (verdict: Runtime Error):
import math
a, b, c, d = map(int, input().split())
ans = 0

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

cd = lcm(c, d)

# cの倍数とdの倍数の個数を数える
ca = a // c
# print(ca)
cb = b // c
# print(cb)
tmp_c = cb - ca

da = a // d
# print(da)
db = b // d
# print(db)
tmp_d = db - da

cda = a // cd
# print(cda)
cdb = b // cd
# print(cdb)
tmp_cd = cdb - cda
ans = b - a - (tmp_c + tmp_d - tmp_cd) + 1

print(ans)

Buggy submission (verdict: Runtime Error):
import math
a, b, c, d = map(int, input().split())
ans = 0

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

cd = lcm(c, d)

# cの倍数とdの倍数の個数を数える
ca = a // c
# print(ca)
cb = b // c
# print(cb)
tmp_c = cb - ca

da = a // d
# print(da)
db = b // d
# print(db)
tmp_d = db - da

cda = a // cd
# print(cda)
cdb = b // cd
# print(cdb)
tmp_cd = cdb - cda
ans = b - a - (tmp_c + tmp_d - tmp_cd) + 1

print(ans)
Problem p03006 (python)

Fixed submission:
n=int(input())
if n==1:
	print(1)
	exit()
xy = sorted([list(map(int,input().split())) for i in range(n)])
p=q=0
ans=0
dic={}
for i in range(n-1):
	for j in range(i+1,n):
		p = xy[i][0]-xy[j][0]
		q = xy[i][1]-xy[j][1]
		if (p,q) in dic:
			dic[(p,q)]+=1
		else:
			dic[(p,q)]=1
print(n-max(dic.values()))

Buggy submission (verdict: Runtime Error):
N = int(input())
ary = []
d2 = []
max = 0
sin_max = 0
for _ in range(N):
    ball = list(map(int, input().split()))
    ary.append(ball)


for i in range(N):
    for j in range(N):
        x = ary[i][0] - ary[j][0]
        y = ary[i][1] - ary[j][1]
        tmp = str(x) + str(y)
        d2.append(tmp)
        max = d2.count(d2[0])
        for i in range(1,N-1):
            if max < d2.count(d2[i]):
                max = d2.count(d2[i])
        sin_max = max
    d2 = []
    max = 0
    sin_max = 0

print(N - sin_max)

Buggy submission (verdict: Runtime Error):
N = int(input())
ary = []
d2 = []
max = 0
sin_max = 0
for _ in range(N):
  ball = list(map(int, input().split()))
  ary.append(ball)
for i in range(N):
    for j in range(N):
        x = ary[i][0] - ary[j][0]
        y = ary[i][1] - ary[j][1]
        tmp = str(x) + str(y)
        d2.append(tmp)
        max = d2.count(d2[0])
        for i in range(1,N-1):
            if max < d2.count(d2[i]):
                max = d2.count(d2[i])
        sin_max = max
    d2 = []
    max = 0
    sin_max = 0

print(N - sin_max)

Buggy submission (verdict: Runtime Error):
N = int(input())
ary = []
# d = []
d2 = []
for _ in range(N):
  ball = list(map(int, input().split()))
  ary.append(ball)

for i in range(N-1):
    x = ary[i][0] - ary[i+1][0]
    y = ary[i][1] - ary[i+1][1]
    # d.append(x)
    # d.append(y)
    tmp = str(x) + str(y)
    d2.append(tmp)
    # d = []
# print(ary)
# print(d2)

max = d2.count(d2[0])
for i in range(1,N-1):
    if max < d2.count(d2[i]):
        max = d2.count(d2[i])

print(len(d2) - max + 1)
Problem p03030 (python)

Fixed submission:
from operator import itemgetter

# a, b = map(int, input().split())
a = int(input())
array2 = {}
array99 = []
for i in range(a):
    array = input().split()
    array99.append((array[0], int(array[1]) * -1, i))

# print(array99)

b = sorted(array99, key=itemgetter(0, 1))

# print(b)

for i in range(a):
    print(b[i][2] + 1)

Buggy submission (verdict: Runtime Error):
# ABC128-B
# ソートが大事な問題
import itemgetter
a = int(input())
book = []
for i in range(a):
    array = input().split()
    book.append((array[0], int(array[1]) * -1, i))

ans = sorted(book, key=itemgetter(0, 1))

for i in range(a):
    print(ans[i][2] + 1)
Problem p03043 (python)

Fixed submission:
import sys
input = sys.stdin.readline
N,K = map(int, input().split())
ans = 0
for i in range(1,N+1):
	coin = 0
	point = i
	if K <= i:
		ans += 1/N
	else:
		while point < K:
			point *= 2
			coin += 1
		ans += (1/N) * (0.5)**coin

print(ans)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
sum = 0
coin_count = 0


for i in range(n):
    k = coin(i, k)
    sum += (1/n) * ((0.5) ** k)

print(sum)


def coin(j,k):
    point = j
    count = 0
    while k <= point:
        point = point * 2
        count += 1
    return count
Problem p03047 (python)

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

for i in range(1, a+1):
    if i + b - 1 <= a:
        ans = ans + 1

print(ans)

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
ans = 0

for i range(1, a+1):
    if i + b < a:
        ans = ans +1

print(ans)
Problem p03087 (python)

Fixed submission:
# import math
N, Q = map(int, input().split())
# line = list(map(int, input().split()))
# line = input()
S = input()
question = []
ac = [0] * N
ans = []
count = 0
for _ in range(Q):
    question.append(list(map(int, input().split())))

for i in range(N):
    if S[i] == 'C' and S[i-1] == 'A':
        count += 1
        ac[i] = count
    else:
        ac[i] = count

# print(ac)

for i in range(Q):
    start = question[i][0] - 1
    end = question[i][1] - 1
    tmp = ac[end] - ac[start]
    ans.append(tmp)

for i in range(len(ans)):
    print(ans[i])

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())
S = input()
cnt_array = [0] * (N+1)
ans = [0] * Q
for i in range(N):
    if S[i] == 'A' and S[i+1] == 'C':
        cnt_array[i+1] = 1 + cnt_array[i]
    else:
        cnt_array[i+1] = cnt_array[i]
for i in range(Q):
    l, r = map(int, input().split())
    ans[i] = cnt_array[r-1] - cnt_array[l-1]
# print(cnt_array)
# print(ans)
for i in ans:
    print(i)
Problem p03106 (python)

Fixed submission:
A, B, K = map(int, input().split())
ans = []
if max(A,B) == 1:
	print(1)
	exit()
for i in range(1,max(A,B)+1):
	if A % i == 0 and B % i == 0:
		ans.append(i)
ans.sort(reverse=True)
print(ans[K-1])

Buggy submission (verdict: Runtime Error):
A, B, K = map(int, input().split())
ans = []
if max(A,B) == 1:
	print(1)
	exit()
for i in range(1,max(A,B)):
	if A % i == 0 and B % i == 0:
		ans.append(i)
ans.sort(reverse=True)
print(ans[K-1])
Problem p03164 (python)

Fixed submission:
N, W = map(int, input().split())
w, v = [0]*N, [0]*N
for i in range(N):
    w[i], v[i] = map(int,input().split())
V = sum(v)
dp = [[float('inf')] * (V + 1) for _ in range(N+1)]
dp[0][0] = 0
for i in range(N):
    for value in range(V+1):
        if 0 <= value - v[i]:
            dp[i+1][value] = min(dp[i][value-v[i]]+w[i],dp[i][value])
        else:
            dp[i+1][value] = dp[i][value]
ans = 0
for i in range(V+1):
    if dp[N][i] <= W:
        ans = i
print(ans)

Buggy submission (verdict: Runtime Error):
N, W = map(int, input().split())
dp = [[0] * (W+1) for _ in range(N+1)]
w, v = [0]*N, [0]*N
for i in range(N):
    w[i], v[i] = map(int,input().split())
for i in range(N):
    for weight in range(W+1):
        if 0 <= weight - w[i]:
            dp[i+1][weight] = max(dp[i][weight-w[i]]+v[i],dp[i][weight])
        else:
            dp[i+1][weight] = dp[i][w[i]]
print(dp[N][W])
Problem p03166 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
def f(v):
    if dp[v] != 0:
        return dp[v]
    res = 0
    for i in graph[v]:
        res = max(res,f(i)+1)
    dp[v] = res
    return res
N, M = map(int, input().split())
graph = [[] for _ in range(N)]
for i in range(M):
    x, y = map(int, input().split())
    graph[x-1].append(y-1)
dp = [0]*N
ans = 0
for i in range(N):
    ans = max(ans,f(i))
print(ans)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
edge = [[] for _ in range(N)]
for _ in range(M):
    x, y = map(int, input().split())
    edge[x-1].append(y-1)
dp = [0]*N
def f(v):
    if dp[v] != 0:
        return dp[v]
    res = 0
    for i in edge[v]:
        res = max(res, f(i)+1)
    dp[v] = res
    return res
for i in range(N):
    f(i)
print(max(dp))

Buggy submission (verdict: Runtime Error):
def f(v):
    if dp[v] != 0:
        return dp[v]
    res = 0
    for i in graph[v]:
        res = max(res,f(i)+1)
    dp[v] = res
    return res
N, M = map(int, input().split())
graph = [[] for _ in range(N)]
for i in range(M):
    x, y = map(int, input().split())
    graph[x-1].append(y-1)
dp = [0]*N
ans = 0
for i in range(N):
    ans = max(ans,f(i))
print(ans)