Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from fractions import math
n, x = tuple(map(int, input().split(' ')))
d = 0
l = list(map(int, input().split(' ')))
for i in range(n):
  s = l[i]
  if i == 0:
    d = abs(s - x)
  else:
    d = math.gcd(d, s-x)
print(d)


Fixed submission:
from fractions import gcd
n, x = tuple(map(int, input().split(' ')))
d = 0
l = list(map(int, input().split(' ')))
for i in range(n):
  s = l[i]
  if i == 0:
    d = abs(s - x)
  else:
    d = gcd(d, abs(s-x))
print(d)

Buggy python submission (verdict: Runtime Error):
import math
n, x = tuple(map(int, input().split(' ')))
d = 0
l = list(map(int, input().split(' ')))
for i in range(n):
  s = l[i]
  if i == 0:
    d = s - x
  else:
    d = math.gcd(d, s-x)
print(d)


Fixed submission:
from fractions import gcd
n, x = tuple(map(int, input().split(' ')))
d = 0
l = list(map(int, input().split(' ')))
for i in range(n):
  s = l[i]
  if i == 0:
    d = abs(s - x)
  else:
    d = gcd(d, abs(s-x))
print(d)

Buggy python submission (verdict: Runtime Error):
import math
n, x = tuple(map(int, input().split(' ')))
d = 0
for i in range(n):
  s = int(input())
  if i == 0:
    d = s - x
  else:
    d = math.gcd(d, s-x)
print(d)

Fixed submission:
from fractions import gcd
n, x = tuple(map(int, input().split(' ')))
d = 0
l = list(map(int, input().split(' ')))
for i in range(n):
  s = l[i]
  if i == 0:
    d = abs(s - x)
  else:
    d = gcd(d, abs(s-x))
print(d)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N = int(input())
    a = list(map(int, input().split()))

    for i in range(N-1):
        for j in range(i + 1, N):
            if a[i] == a[j]:
                print("NO")
                return
    
    print("YES")
    return


if __name__ == "__main__":
    main()

Fixed submission:
from collections import defaultdict

def main():
    N = int(input())
    a = list(map(int, input().split()))
    dct = defaultdict(int)

    for i in a:
        if dct[i] != 0:
            print("NO")
            return 
        else:
            dct[i] += 1
    
    print("YES")
    return


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
a = list(map(int, input().split()))
ans = None
s = None

for i in range(0, N - K + 1):
    s = 0

    for j in range(K):
        s += a[i+j] + 1

    if ans is None or ans < s:
        ans = s

print(ans/2)

Fixed submission:
N, K = map(int, input().split())
a = list(map(int, input().split()))
ans = None
s = None

for i in range(0, N - K + 1):
    s = sum(a[i:i+K]) + K if s is None else s - a[i - 1] + a[i + K - 1]

    if ans is None or ans < s:
        ans = s

print(ans/2)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
a = list(map(int, input().split()))
ans = None

for i in range(0, N - K + 1):
    s = sum(a[i:i+K]) + K

    if ans is None or ans < s:
        ans = s

print(ans/2)

Fixed submission:
N, K = map(int, input().split())
a = list(map(int, input().split()))
ans = None
s = None

for i in range(0, N - K + 1):
    s = sum(a[i:i+K]) + K if s is None else s - a[i - 1] + a[i + K - 1]

    if ans is None or ans < s:
        ans = s

print(ans/2)
Buggy python submission (verdict: Runtime Error):
N = int(input())
res = ""

for i in list(input()):
    ascii = ord(i)
    n = ascii - 65
    n = (n + N) % 26
    res += chr(n + 65)
print(res == input())

Fixed submission:
N = int(input())
res = ""

for i in list(input()):
    ascii = ord(i)
    n = ascii - 65
    n = (n + N) % 26
    res += chr(n + 65)
print(res)

Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
N = int(input())
res = ""

for i in list(input()):
    ascii = ord(i)
    n = ascii - 65
    n = (n + N) % 26
    res += chr(n + 65)
print(res == input())

Fixed submission:
N = int(input())
res = ""

for i in list(input()):
    ascii = ord(i)
    n = ascii - 65
    n = (n + N) % 26
    res += chr(n + 65)
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
s = S[:2]
ans = 'AC'
lst = []
for i in range(N-1):
    s = S[i] + S[i + 1]
    lst.append(s == ans)

for _ in range(Q):
    a, b = map(int, input().split())
    res = 0
    for i in range(a - 1, b - 1):
        res += lst[i]
    print(res)


Fixed submission:
N, Q = map(int, input().split())
S = input()
s = S[:2]
ans = 'AC'
lst = [0]
count = 0
for i in range(N-1):
    s = S[i] + S[i + 1]
    count += (s == ans)
    lst.append(count)

for _ in range(Q):
    a, b = map(int, input().split())
    print(lst[b - 1] - lst[a - 1])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
s = S[:2]
ans = 'AC'
lst=[s == ans]
for i in range(1, N-1):
    s = s[1:] + S[i + 1]
    lst.append(s == ans)

for _ in range(Q):
    a, b = map(int, input().split())
    res = 0
    for i in range(a - 1, b - 1):
        res += lst[i]
    print(res)


Fixed submission:
N, Q = map(int, input().split())
S = input()
s = S[:2]
ans = 'AC'
lst = [0]
count = 0
for i in range(N-1):
    s = S[i] + S[i + 1]
    count += (s == ans)
    lst.append(count)

for _ in range(Q):
    a, b = map(int, input().split())
    print(lst[b - 1] - lst[a - 1])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()

for _ in range(Q):
    a, b = map(int, input().split())
    ans = S[a-1:b].count('AC')
    print(ans)


Fixed submission:
N, Q = map(int, input().split())
S = input()
s = S[:2]
ans = 'AC'
lst = [0]
count = 0
for i in range(N-1):
    s = S[i] + S[i + 1]
    count += (s == ans)
    lst.append(count)

for _ in range(Q):
    a, b = map(int, input().split())
    print(lst[b - 1] - lst[a - 1])
Buggy python submission (verdict: Runtime Error):
from math import *
N,D = map(int,input().split())
lst = [[int(kk) for kk in input().split()] for aa in range(N)]
tot = 0
c = 0
for a in range(1,N):
	for b in range(a):
      	c = 0
        for i in range(D):
			c += (lst[a][i]-lst[b][i])**2
        if sqrt(c) == int(sqrt(c)):
          	tot += 1
print(tot)

Fixed submission:
from math import *
N,D = map(int,input().split())
lst = [[int(kk) for kk in input().split()] for aa in range(N)]
tot = 0
c = 0

for a in range(1,N):
    for b in range(a):
        c = 0
        for i in range(D):
            c += (lst[a][i] - lst[b][i])**2
        if sqrt(c) == int(sqrt(c)):
            tot += 1
print(tot)

Buggy python submission (verdict: Runtime Error):
N,D = map(int,input().split())
lst = [[int(kk) for kk in input().split()] for aa in range(N)]
tot = 0
c = 0
for a in range(N):
	for b in range(a):
      	c = 0
        for i in range(D):
			c += (lst[a][i]-lst[b][i])**2
        if sqrt(c) == int(sqrt(c)):
          	tot += 1
print(tot)
    	 	 

Fixed submission:
from math import *
N,D = map(int,input().split())
lst = [[int(kk) for kk in input().split()] for aa in range(N)]
tot = 0
c = 0

for a in range(1,N):
    for b in range(a):
        c = 0
        for i in range(D):
            c += (lst[a][i] - lst[b][i])**2
        if sqrt(c) == int(sqrt(c)):
            tot += 1
print(tot)
Buggy python submission (verdict: Runtime Error):
sti = input()
up = False
down = False
for i in sti:
	if i == i.upper:
		up = True
    else:
		down = True
if up and down:
	print("Yes")
else:
  	print("No")

Fixed submission:
sti = input()
x = set()
for i in sti:
    x.add(i)
if len(x) == 2 and sti.count(sti[0]) == 2:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
lst = [int(i) for i in input().split()]
while len(lst) > 2:
    lst.remove(min(lst))
    lst.remove(max(lst))
print(max(lst)-min(lst))


Fixed submission:
N = int(input())
lst = [int(i) for i in input().split()]
lst.sort()
x = int(N/2)
print(lst[x]-lst[x-1])
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
N,L = map(int,input().split())
lst = [L]
for i in range(n-1):
  lst.append(lst[-1]+1)
arr = [abs(i) for i in lst]
del lst[arr.index(min(arr))]
print(sum(lst))


Fixed submission:
import sys
input = sys.stdin.readline
N,L = map(int,input().split())
lst = [L]
for i in range(N-1):
  lst.append(lst[-1]+1)
arr = [abs(i) for i in lst]
del lst[arr.index(min(arr))]
print(sum(lst))

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
N,L = map(int,input().split())
lst = [L]
for i in range(n-1):
  lst.append(lst[-1]-1)
arr = [abs(i) for i in lst]
del lst[arr.index(min(arr))]
print(sum(lst))


Fixed submission:
import sys
input = sys.stdin.readline
N,L = map(int,input().split())
lst = [L]
for i in range(N-1):
  lst.append(lst[-1]+1)
arr = [abs(i) for i in lst]
del lst[arr.index(min(arr))]
print(sum(lst))
Buggy python submission (verdict: Time Limit Exceeded):
N,W = map(int,input().split())
wvs = [[int(kk) for kk in input().split()] for i in range(N)]

dp = [0]*(W+1)

for w,v in  wvs:
    for i in reversed(range(W+1)):
        #print(i)
        dp[i] = max(dp[i-w]+v,dp[i])
        if i == w:
            break

print(max(dp))



Fixed submission:
N,W = map(int,input().split())
wvs = [[int(kk) for kk in input().split()] for i in range(N)]

dp = [0]*(W+1)

for w,v in  wvs:
    for i in reversed(range(W+1)):
        #print(i)
        dp[i] = max(dp[i-w]+v,dp[i])
        if i == w:
            break

print(max(dp))
Buggy python submission (verdict: Runtime Error):
S = coffee
if S is coffee-like
    return("Yes")
    else
    print("No")
  
  


Fixed submission:
def get_count(text):
    if text[2] == text[3] and text[4] == text[5]:
        return 'Yes'
    else:
        return 'No'
 
 
if __name__ == '__main__':
    string = input().strip()
 
    result = get_count(string)
    print(result)
Buggy python submission (verdict: Runtime Error):
h = int(input())
w = int(input())
n = int(input())

num1 = n/h
num2 = n/w

if not num1.is_integer():
  num1 = int(num1) + 1
  
if not num2.is_integer():
  num2 = int(num2) + 1
  
return min(num1, num2)

Fixed submission:
h = int(input())
w = int(input())
n = int(input())

num1 = n/h
num2 = n/w

if not num1.is_integer():
  num1 = int(num1) + 1
  
if not num2.is_integer():
  num2 = int(num2) + 1
  
num1 = int(num1)
num2 = int(num2)
print(min(num1, num2))
Buggy python submission (verdict: Time Limit Exceeded):
N,X,Y = map(int, input().split())
X = X-1
Y = Y-1
kyori  = []
for i in range(N):
    for j in range(i,N):
        l = min(abs(i-j), abs(i-X)+1+abs(j-Y), abs(i-Y)+1+abs(j-X))
        kyori.append(l)
for k in range(1,N):
    print(kyori.count(k))

Fixed submission:
N,X,Y = map(int, input().split())
X = X-1
Y = Y-1
kyori  = [0]*N
for i in range(N):
    for j in range(i+1,N):
        l = min(abs(i-j), abs(i-X)+1+abs(j-Y), abs(i-Y)+1+abs(j-X))
        kyori[l] += 1
for k in range(1,N):
    print(kyori[k])

Buggy python submission (verdict: Time Limit Exceeded):
N,X,Y = map(int, input().split())
X = X-1
Y = Y-1
kyori  = []
for i in range(N):
    for j in range(i,N):
        l = min(abs(i-j), abs(i-X)+1+abs(j-Y), abs(i-Y)+1+abs(j-X))
        kyori.append(l)
for k in range(1,N):
    print(kyori.count(k))

Fixed submission:
N,X,Y = map(int, input().split())
X = X-1
Y = Y-1
kyori  = [0]*N
for i in range(N):
    for j in range(i+1,N):
        l = min(abs(i-j), abs(i-X)+1+abs(j-Y), abs(i-Y)+1+abs(j-X))
        kyori[l] += 1
for k in range(1,N):
    print(kyori[k])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(x) for x in input().split()]
kosuu = [0]*(N+1)
num = []
for i in range(N):
    kosuu[A[i]] += 1
for i in range(N):
    if kosuu[A[i]] >= 2:
        num.append(i)

base = 0
for i in kosuu:
    base += i*(i-1)//2
for i in range(N):
    if i not in num:
        print(base)
    else:
        print(base - (kosuu[A[i]]-1))

Fixed submission:
N = int(input())
A = [int(x) for x in input().split()]
kosuu = [0]*(N+1)
for i in range(N):
    kosuu[A[i]] += 1

base = 0
for i in kosuu:
    base += i*(i-1)//2
for i in range(N):
    print(base-(kosuu[A[i]]-1))
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
P = [int(x) for x in input().split()]
ans = 0
for i in range(N-K+1):
    l = sum(P[i:i+K])
    if l > ans:
        ans = l
ans = ans + K
print(ans/2)

Fixed submission:
N,K = map(int,input().split())
P = [int(x) for x in input().split()]
L = []
l = 0
for i in range(N):
    l += P[i]
    L.append(l)
ANS = []
ANS.append(L[K-1])
for i in range(N-K):
    ANS.append(L[i+K] - L[i])
ans = max(ANS) + K
print(ans/2)
Buggy python submission (verdict: Runtime Error):
N,M = map(int, input().split())
ac = [0]*(N+1)
wa = 0
for i in range(M):
    p,s = input().split()
    p = int(p)
    if s == 'AC':
        if ac[p] != -1:
            ac[p] = -1
    else:
        if ac[p] != -1:
            wa +=1
print(ac.count(-1),wa)

Fixed submission:
alp = "abcdefghijklmnopqrstuvwxyz"
C = input()
n = 0
while alp[n] != C:
    n += 1
print(alp[n+1])
Buggy python submission (verdict: Runtime Error):
import fractions
from functools import reduce
N,M= map(int,input().split())
A=[int(x) for x in input().split()]
def lcmpair(a,b):
    return (a*b)// fractions.gcd(a,b)
def lcm(List):
    return reduce(lcmpair,List,1)
lcmB = lcm(A) //2

crit = 0
pena = 0
num = A[0]
while num%2 == 0:
    crit +=1
    num = num//2
count = 0
for i in A:
    count = 0
    while i%2 == 0 :
        count +=1
        i = i//2
    if count != crit:
        pena = 1

if lcmB > M:
    print(0)
elif pena ==1:
    print(0)
else:
    print(((M//lcmB)+1)//2)   

Fixed submission:
K,X = map(int,input().split())
if 500*K >= X:
    print('Yes')
else:
    print('No')

Buggy python submission (verdict: Runtime Error):
K,X = map(int,input().split())
if 500*K >= X:
    print(Yes)
else:
    print(No)

Fixed submission:
K,X = map(int,input().split())
if 500*K >= X:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
import itertools
N = int(input())
P = [int(x) for x in input().split()]
Q = [int(x) for x in input().split()]
R = [itertools.permutations(range(1,N+1))]
print(abs(r.idex(P)-r.index(Q)))

Fixed submission:
from itertools import permutations
N = int(input())
P = tuple(int(x) for x in input().split())
Q = tuple(int(x) for x in input().split())
L = list(range(1,N+1))
R = list(permutations(L))
print(abs(R.index(P)-R.index(Q)))
Buggy python submission (verdict: Runtime Error):
A = [map(int, input().split())]
if sum(A) >= 22:
    print(bust)
else:
    print(win)

Fixed submission:
A = [int(x) for x in input().split()]
if sum(A) >= 22:
    print("bust")
else:
    print("win")
Buggy python submission (verdict: Runtime Error):
cal = {"SUN":0,"MON":1,"TUE":2,"WEN":3,"THU":4,"FRI":5,"SAT":6}
S = input()
print(7-cal[S])

Fixed submission:
cal = {"SUN":0,"MON":1,"TUE":2,"WED":3,"THU":4,"FRI":5,"SAT":6}
S = input()
print(7-cal[S])
Buggy python submission (verdict: Runtime Error):
A,B = map(int, input().split())
if A-2*B <= 0:
    print(o)
else:
    print(A-2*B)

Fixed submission:
A,B = map(int, input().split())
if A-2*B <= 0:
    print(0)
else:
    print(A-2*B)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = [list(input()) for _ in range(N)]
ans = 0
for i in range(N):
    S[i].sort()
print
for i in range(N):
    for j in range(i+1,N):
        if S[i] == S[j]:
            ans += 1
print(ans)

Fixed submission:
N = int(input())
S = [input() for _ in range(N)]
mydict = {}
ans = 0
for i in range(N):
    T = [str(x) for x in S[i]]
    T.sort()
    S[i] = ''.join(T)
for j in range(N):
    if S[j] in mydict.keys():
        ans += mydict[S[j]]
        mydict[S[j]] += 1
    else:
        mydict.setdefault(S[j],1)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N =int(input())
H = [int(x) for x in input().split()]
memo = 0
for i in range(N):
    if i==N-1:
        break
    elif H[i]-min(H[i+1:])>=2:
        memo+=1
if memo>=1:
    print('No')
else:
    print('Yes')  

Fixed submission:
N =int(input())
H = [int(x) for x in input().split()]
h=0
l=0
memo = 0
for i in range(N):
    if H[i]>=h:
        h=H[i]
    elif H[i]<h and H[i]>=l:
        l=H[i]
    else:
        memo+=1
for i in range(N):
    if i==N-1:
        break
    elif H[i]-H[i+1]>=2:
        memo+=1

if memo>=1:
    print('No')
else:
    print('Yes')
Buggy python submission (verdict: Time Limit Exceeded):
L,R = map(int,input().split())
S = set()
T = set()
if (R-L)>=673:
    print(0)
else:
    l = L%2019
    for i in range(R-L+1):
        S = S | {l+i}
    for i in S:
        for j in S:
            if i != j:
                T = T | {(i*j)%2019}
    print(min(T))

Fixed submission:
L,R = map(int,input().split())
S = list()
n = R-L
if n >= 673:
    print(0)
else:
    for i in range(n+1):
        for j in range(i+1,n+1):
            l = L+i
            r = L+j
            S.append((l*r)%2019)
    print(min(S))

Buggy python submission (verdict: Time Limit Exceeded):
L,R = map(int,input().split())
S = set()
if (R-L)>=673:
    print(0)
else:
    for i in range(R-L+1):
        for j in range(R-L+1):
            if i != j:
                S = S | {((L+i)*(L+j))%2019}
    print(min(S))

Fixed submission:
L,R = map(int,input().split())
S = list()
n = R-L
if n >= 673:
    print(0)
else:
    for i in range(n+1):
        for j in range(i+1,n+1):
            l = L+i
            r = L+j
            S.append((l*r)%2019)
    print(min(S))
Buggy python submission (verdict: Runtime Error):
S = input()
for i in S:
    if S.count(a[i]) == 2:
        ans += 1
if ans == 4:
    print('Yes')
else:
    print('No')

Fixed submission:
S = input()
ans = 0
for i in range(4):
    if S.count(S[i]) == 2:
        ans += 1
if ans == 4:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
import math
A,B,C,D = map(int, input().split())
x = abs(A-B)//C + 1
y = abs(A-B)//D + 1
if abs(A-B)//((C*D)//math.gcd(C,D)) == 0:
    z = 0
else:
    z = abs(A-B)//((C*D)//math.gcd(C,D)) + 1
print(B-A+1-x-y+z)

Fixed submission:
import fractions
A,B,C,D = map(int, input().split())
BC = B//C
if A%C == 0:
    AC = A//C-1
else:    
    AC = A//C
BD = B//D
if A%D == 0:
    AD = A//D - 1
else:
    AD = A//D
GCD = C*D//fractions.gcd(C,D)
BB = B//GCD
if A%GCD == 0:
    AA = A//GCD - 1
else:
    AA = A//GCD
print((B-A+1)-(BC-AC)-(BD-AD)+(BB-AA))
Buggy python submission (verdict: Runtime Error):
N,W=map(int,input().split())
dp=[0]*(W+1)
L = sorted([list(map(int,input().split())) for i in range(N)])
s=0
 
for w, v in L:
    s+=w
    for j in range(min(W,s),w-1,-1):
        if dp[j-w]+v > dp[j]: dp[j]=dp[j-w]+v
    
print(max(dp))

Fixed submission:
N = int(input())
H = [int(x) for x in input().split()]
dp = [0]*N
dp[0] = 0
dp[1] = abs(H[1]-H[0])
for i in range(2,N):
    dp[i] = min(dp[i-1]+abs(H[i]-H[i-1]),dp[i-2]+abs(H[i]-H[i-2]))
    
print(dp[N-1])

Buggy python submission (verdict: Runtime Error):
N,W=map(int,input().split())
dp=[0]*(W+1)
L = sorted([list(map(int,input().split())) for i in range(N)])
s=0
 
for w, v in L:
    s+=w
    for j in range(min(W,s),w-1,-1):
        if dp[j-w]+v > dp[j]: dp[j]=dp[j-w]+v
    
print(max(dp))

Fixed submission:
N = int(input())
H = [int(x) for x in input().split()]
dp = [0]*N
dp[0] = 0
dp[1] = abs(H[1]-H[0])
for i in range(2,N):
    dp[i] = min(dp[i-1]+abs(H[i]-H[i-1]),dp[i-2]+abs(H[i]-H[i-2]))
    
print(dp[N-1])
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
H = [int(x) for x in input().split()]
dp = [0]*N
dp[0] = 0
dp[1] = abs(H[1]-H[0])
for i in range(2,N):
    L = [dp[j]+abs(H[i]-H[j]) for j in range(max(0,i-K),i)]
    dp[i] = min(L)
print(dp[N-1])

Fixed submission:
N,K = map(int,input().split())
H = [int(x) for x in input().split()]

def main(N,K,H):
    dp = [0]*N
    for i in range(1,N):
        L = [dp[j]+abs(H[i]-H[j]) for j in range(max(0,i-K),i)]
        dp[i] = min(L)
    print(dp[-1])
main(N,K,H)
Buggy python submission (verdict: Time Limit Exceeded):
N,W = map(int, input().split())
dp = [0]*(W+1)

for i in range(1,N+1):
    w,v = map(int,input().split())
    dp[w:W+1] = [max(dp[i+w],dp[i]+v) for i in range(W-w+1)]

print(dp[-1])

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

Buggy python submission (verdict: Time Limit Exceeded):
N,W = map(int, input().split())
V = [[int(x) for x in input().split()] for _ in range(N)]


def knapsack(N,W,V):
    dp = [[0]*(W+1) for _ in range(N+1)]

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

print(knapsack(N,W,V))

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

Buggy python submission (verdict: Time Limit Exceeded):
N,W = map(int, input().split())
V = [[int(x) for x in input().split()] for _ in range(N)]
dp = [[0]*(W+1) for _ in range(N+1)]

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

print(dp[N][W])

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

Buggy python submission (verdict: Runtime Error):
N,W=map(int,input().split())
dp=[0]*(W+1)
L = sorted([list(map(int,input().split())) for i in range(N)])
s=0
 
for w, v in L:
    s+=w
    for j in range(min(W,s),w-1,-1):
        if dp[j-w]+v > dp[j]: dp[j]=dp[j-w]+v
    
print(max(dp)

Fixed submission:
N, W = map(int, input().split())
 
import numpy as np
dp = np.zeros(W + 1, dtype='int64')
 
for i in range(1, N + 1):
    w, v = map(int, input().split())
    dp[w:W+1] = np.maximum(dp[w:W+1], dp[:W-w+1] + v)
 
print(dp[-1])
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N,M = map(int, input().split())
G = [[] for _ in range(N)]
for i in range(N):
    x, y = map(int, input().split())
    x, y = x-1, y-1
    G[x].append(y)
#G[i]は頂点iから辺でつながっている頂点のlist
def topological_sort(g):
    topological_list = []
    visited = list()

    def dfs(n):
        for e in g[n]:
            if e not in visited:
                dfs(e)
        topological_list.append(n)
        visited.append(n)
    
    for i in range(len(g)):
        if i not in visited:
            dfs(i)
        
    return topological_list[::-1]

T = topological_sort(G)
dist = [0]*N
for n in T:
    for v in G[n]:
        dist[v] = max(dist[v],dist[n]+1)       
        
print(max(dist),T)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N,M = map(int, input().split())
G = [[] for _ in range(N)]
for i in range(M):
    x, y = map(int, input().split())
    x, y = x-1, y-1
    G[x].append(y)
#G[i]は頂点iから辺でつながっている頂点のlist
def topological_sort(g):
    topological_list = []
    visited = set()

    def dfs(n):
        for e in g[n]:
            if e not in visited:
                dfs(e)
        topological_list.append(n)
        visited.add(n)
    
    for i in range(len(g)):
        if i not in visited:
            dfs(i)
        
    return topological_list[::-1]

T = topological_sort(G)
dist = [0]*N
for n in T:
    for v in G[n]:
        dist[v] = max(dist[v],dist[n]+1)       
        
print(max(dist))