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

Fixed submission:
def knapsack(nums, k):
    n = len(nums)

    # dp[i] is min cost when reaching stone i
    dp = [float('Inf')] * n
    dp[0] = 0
    for i in range(1, n):
        dp[i] = min([
            dp[i-j] + abs(nums[i] - nums[i-j])
            for j in range(1, k+1) if i - j >= 0]
        )
    return dp[-1]


if __name__ == "__main__":
    _, k = [int(x) for x in input().split()]
    nums = [int(x) for x in input().split()]
    print(knapsack(nums, k))

Buggy submission (verdict: Runtime Error):
def knapsack(nums, KLeap):
    n = len(nums)
    if n == 0 or n == 1:
        return 0
 
    if n < KLeap:
        return abs(nums[0] - nums[-1])
    # dp[i] is min cost when reaching stone i
    dp = [0] * n
    for i in range(1, KLeap):
        dp[i] = abs(nums[0] - nums[i])
 
    for i in range(K+1, n):
        dp[i] = min([dp[i - k] + abs(nums[i - k] - nums[i]) for k in range(1, KLeap)])
 
    return dp[-1]
 
 
if __name__ == "__main__":
    _, K = [int(x) for x in input().split()]
    nums = [int(x) for x in input().split()]
    print(knapsack(nums, K))

Buggy submission (verdict: Runtime Error):
ef knapsack(nums, KLeap):
    n = len(nums)
    if n == 0 or n == 1:
        return 0
 
    if n < KLeap:
        return abs(nums[0] - nums[-1])
    # dp[i] is min cost when reaching stone i
    dp = [0] * n
    for i in range(1, KLeap):
        dp[i] = abs(nums[0] - nums[i])
 
    for i in range(K+1, n):
        dp[i] = min([dp[i - k] + abs(nums[i - k] - nums[i]) for k in range(1, KLeap)])
 
    return dp[-1]
 
 
if __name__ == "__main__":
    _, K = [int(x) for x in input().split()]
    nums = [int(x) for x in input().split()]
    print(knapsack(nums, K))

Buggy submission (verdict: Runtime Error):
def knapsack(nums, KLeap):
    n = len(nums)
    if n == 0 or n == 1:
        return 0

    if n < KLeap:
        return abs(nums[0] - nums[-1])
    # dp[i] is min cost when reaching stone i
    dp = [0] * n
    for i in range(1, KLeap):
        dp[i] = abs(nums[0] - nums[i])

    for i in range(K+1, n):
        dp[i] = min([dp[i - k] + abs(nums[i - k] - nums[i]) for k in range(1, KLeap)])

    return dp[-1]


if __name__ == "__main__":
    _, K = [int(x) for x in input().split()]
    nums = [int(x) for x in input().split()]
    print(knapsack(nums, K))

Buggy submission (verdict: Runtime Error):
def knapsack(nums, KLeap):
    n = len(nums)
    if n == 0 or n == 1:
        return 0

    if n == 2:
        return abs(nums[0] - nums[1])

    # dp[i] is min cost when reaching stone i
    dp = [0] * n
    for i in range(1, KLeap):
        dp[i] = abs(nums[0] - nums[i])

    for i in range(K+1, n):
        dp[i] = min([dp[i - k] + abs(nums[i - k] - nums[i]) for k in range(1, KLeap)])

    return dp[-1]


if __name__ == "__main__":
    _, K = [int(x) for x in input().split()]
    nums = [int(x) for x in input().split()]
    print(knapsack(nums, K))
Problem p03163 (python)

Fixed submission:
def knapsack(sizes, vals, volume):
    n = len(sizes)

    dp = [[0] * (volume+1) for _ in range(n)] # j is 0...volume

    for i in range(n):
        for j in range(volume+1):
            dp[i][j] = max(dp[i][j], dp[i-1][j])
            if j - sizes[i] >= 0:
                dp[i][j] = max(dp[i][j], dp[i-1][j-sizes[i]] + vals[i])
            dp[i][j] = max(dp[i][j], dp[i-1][j])

    return dp[-1][-1]


if __name__ == "__main__":
    n, volume = [int(x) for x in input().split()]
    sizes, vals = [], []
    for _ in range(n):
        s, v = [int(x) for x in input().split()]
        sizes.append(s)
        vals.append(v)
    print(knapsack(sizes, vals, volume))

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

def knapsackGreedy(sizes, vals, volume):
    ids = np.argsort([val / size for val, size in zip(vals, sizes)])

    sumVal = 0
    for i in ids:
        if sizes[i] <= volume:
            volume -= sizes[i]
            sumVal += vals[i]
        if volume <= 0:
            break

    return sumVal


if __name__ == "__main__":
    n, volume = [int(x) for x in input().split()]
    sizes, vals = [], []
    for _ in range(n):
        s, v = [int(x) for x in input().split()]
        sizes.append(s)
        vals.append(v)
    print(knapsackGreedy(sizes, vals, volume))

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

def knapsackGreedy(sizes, vals, volume):
    ids = np.argsort([val / size for val, size in zip(vals, sizes)])

    sumVal = 0
    for i in ids:
        if sizes[i] <= volume:
            volume -= sizes[i]
            sumVal += vals[i]
        if volume <= 0:
            break

    return sumVal


if __name__ == "__main__":
    n, volume = [int(x) for x in input().split()]
    sizes, vals = [], []
    for _ in range(n):
        s, v = [int(x) for x in input().split()]
        sizes.append(s)
        vals.append(v)
    print(knapsackGreedy(sizes, vals, volume))
Problem p03166 (python)

Fixed submission:
N, M = map(int,raw_input().split())
gra = [set() for n in range(N)]
ins = [0] * N

start = set(range(N))
for m in range(M) :
  x, y = map(int,raw_input().split())
  gra[x-1].add(y-1)
  ins[y-1] += 1
  start.discard(y-1)

mem = [None for n in range(N)]
q = list(start)
for i in q : mem[i] = 0

longest = 0
while q :
  cur = q.pop(0)
  for nxt in gra[cur] :
    ins[nxt] -= 1
    if ins[nxt] == 0 :
      mem[nxt] = mem[cur] + 1
      longest = max(longest, mem[nxt])
      q.append(nxt)

print longest

Buggy submission (verdict: Runtime Error):
N, M = map(int,raw_input().split())
gra = [set() for n in range(N)]

start = set(range(N))
for m in range(M) :
  x, y = map(int,raw_input().split())
  gra[x-1].add(y-1)
  start.discard(y-1)

def dfs(cur, par=-1) : 
  
  d = [0]
  for nxt in gra[cur] :
    if nxt == par : continue
    d.append(dfs(nxt, cur))

  return max(d) + int(par!=-1)

res = []
while start :
  res.append(dfs(start.pop()))

print max(res)
Problem p03160 (python)

Fixed submission:
n = int(input())
heights = list(map(int, input().split()))
dp = [float('inf') for i in range(n)]
dp[0] = 0

for i in range(1, n):
    dp[i] = min(dp[i], dp[i - 1] + abs(heights[i] - heights[i - 1]))
    if i > 1:
        dp[i] = min(dp[i], dp[i - 2] + abs(heights[i] - heights[i - 2]))

print(dp[n - 1])

Buggy submission (verdict: Runtime Error):
n, K = map(int, input().split())
heights = list(map(int, input().split()))
dp = [float('inf') for i in range(n)]
dp[0] = 0
 
for i in range(1, n):
 
    dp[i] = min(dp[i], dp[i - 1] + abs(heights[i] - heights[i - 1]))
    if i > 1:
        for k in range(1, K + 1):
            dp[i] = min(dp[i], dp[i - k] + abs(heights[i] - heights[i - k]))
 
print(dp[n - 1])

Buggy submission (verdict: Runtime Error):
n, K = map(int, input().split())
heights = list(map(int, input().split()))
dp = [float('inf') for i in range(n)]
dp[0] = 0

for i in range(1, n):

    dp[i] = min(dp[i], dp[i - 1] + abs(heights[i] - heights[i - 1]))
    if i > 1:
        for k in range(1, K + 1):
            dp[i] = min(dp[i], dp[i - k] + abs(heights[i] - heights[i - k]))

print(dp[n - 1])
Problem p03160 (python)

Fixed submission:
N = int(input())

if N < 2:
    print(0)

heights = [int(x) for x in input().split()]

dp = [0] * N
dp[0] = 0
dp[1] = abs(heights[1] - heights[0])

for i in range(2, N):
    dp[i] = min(dp[i-1] + abs(heights[i] - heights[i-1]),
                dp[i - 2] + abs(heights[i] - heights[i - 2]))

print(dp[-1])

Buggy submission (verdict: Runtime Error):
N = int(input())

if N < 2:
    print(0)

heights = [int(x) for x in input().split()]

dp = [0] * N
dp[0] = 0
dp[1] = abs(heights[1] - heights[0])

for i in range(2, N):
    dp[i] = min(dp[i-1] + abs(heights[i] - heights[i-1]),
                dp[i - 2] + abs(heights[i] - heights[i - 2]))

print(dp[-1])

Buggy submission (verdict: Runtime Error):
if __name__ == "__main__":
    """
    N
    h1 h2 h3 .. hn
    """

    N = int(input())

    if N < 2:
        print(0)

    heights = [int(x) for x in input().split()]

    dp = [0] * N
    dp[0] = 0
    dp[1] = abs(heights[1] - heights[0])

    for i in range(2, N):
        dp[i] = min(dp[i-1] + abs(heights[i] - heights[i-1]),
                    dp[i - 2] + abs(heights[i] - heights[i - 2]))

    print(dp[-1])

Buggy submission (verdict: Runtime Error):
if __name__ == "__main__":
    """
    N
    h1 h2 h3 .. hn
    """

    N = int(input())
    print(N)
    heights = [int(x) for x in input().split()]

    dp = [0] * N
    dp[0] = 0
    dp[1] = abs(heights[1] - heights[0])

    for i in range(2, N):
        dp[i] = min(dp[i-1] + abs(heights[i] - heights[i-1]),
                    dp[i - 2] + abs(heights[i] - heights[i - 2]))

    print(dp[-1])
Problem p03160 (python)

Fixed submission:
size = int(input())
array =  list(map(int, input().split()))
dp = [0]* size
dp[1]=  dp[0] + abs(array[1] - array[0]) 
for i in range(2,size):
	dp[i] = min(
	dp[i-1] + abs(array[i] - array[i-1]),
	dp[i-2] + abs( array[i] - array[i-2] )
	)
print(dp[-1])

Buggy submission (verdict: Runtime Error):
size, jumps = map(int, input().split())
array =  list(map(int, input().split()))
dp = [0]* size
dp[1]=  dp[0] + abs(array[1] - array[0]) 
for i in range(1,size):
	for j in range(jumps):	
		if i+j < n :
			dp[i] = min(dp[j],abs(array[i] - array[j]))
print(dp[-1])

Buggy submission (verdict: Runtime Error):
size = int(input())
array =  list(map(int, input().split()))
dp = [0]* size
for i in range(1,size):
	dp[i] = min(
	dp[i-1] + abs(array[i] - array[i-1]),
	dp[i-2] ,abs( array[i] - array[i-2] )]
	)
print(dp[-1])

Buggy submission (verdict: Runtime Error):
size = int(input())
array =  list(map(int, input().split()))
dp = [0]* size
for i in range(1,size):
	z= [1,2]
	for i in range(len(z)):
		dp[i] = min(dp[i-1] ,abs( array[i] - array[j] )])
print(dp[-1])

Buggy submission (verdict: Runtime Error):
size = int(input())
array =  list(map(int, input().split()))
dp = [0]* size
for jump in range(1,size):
  z= [1,2]
  for i in range(len(z)):
    dp[jump] = min(dp[jump],dp[i] + dp[jump] )
return dp[-1]
Problem p03161 (python)

Fixed submission:
import sys


def input():
    return sys.stdin.readline().strip()


def main():
    size, jumps = map(int, input().split())
    array = list(map(int, input().split()))
    dp = [999999999] * size
    dp[0]= 0
    dp[1] = abs(array[0]- array[1])
    for i in range(2,size):
        dp[i] = min(abs(array[i] - array[j]) + dp[j] for j in range(max(0, i - jumps), i))
    print(dp[size-1])

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys


def input():
    return sys.stdin.readline().strip()


def main():
    size, jumps = map(int, input().split())
    array = list(map(int, input().split()))
    dp = [999999999] * size
    dp[0]= 0
    #dp[1] = abs(array[0]- array[1])
    for i in range(size):
		for j in range(i+1,1+i+jumps):
			if j < size:
				dp[j] = min(dp[j], dp[i]+abs(array[i] - array[j]))
	print(dp[size-1])

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys


def input():
    return sys.stdin.readline().strip()


def main():
    size, jumps = map(int, input().split())
    array = list(map(int, input().split()))
    dp = [999999999] * size
    dp[0]= 0
    #dp[1] = abs(array[0]- array[1])
    for i in range(size):
		for j in range(i+1,1+i+jumps):
			if j < size:
				dp[j] = min(dp[j], dp[i]+abs(array[i] - array[j]))
print(dp[size-1])

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
size, jumps = map(int, input().split())
array =  list(map(int, input().split()))
dp = [0]* size
for i in range(1,size):
	for j in range(i,jumps):	
		
		dp[j] = min(dp[j],abs(array[i] - array[j]))
print(dp[-1])

Buggy submission (verdict: Runtime Error):



size, jumps = map(int, input().split())
array =  list(map(int, input().split()))
dp = [0]* size
for i in range(1,size):
	for j in range(i,jumps):	
			dp[j] = min(dp[j],abs(array[i] - array[j]))
print(dp[-1])

Buggy submission (verdict: Runtime Error):
size, jumps = map(int, input().split())
array =  list(map(int, input().split()))
dp = [0]* size
dp[1]=  dp[0] + abs(array[1] - array[0]) 
for i in range(1,size):
	for j in range(jumps):	
		if i+j < n :
			dp[i] = min(dp[j],abs(array[i] - array[j]))
print(dp[-1])

Buggy submission (verdict: Runtime Error):

size, jumps = map(int, input().split())
array =  list(map(int, input().split()))
dp = [0]* size
dp[1]=  dp[0] + abs(array[1] - array[0]) 
for i in range(1,size):
	for j in range(jumps):		
		dp[i] = min( 
		dp[j],abs(array[i] - array[j])
		
		)
print(dp[-1])
Problem p03162 (python)

Fixed submission:
import sys


def input():
    return sys.stdin.readline().strip()


def main():
    size = int(input())
    dp = [0] * 3
    for _ in range(size):
        z = (list(map(int, input().split())))
        newDp = [0] * 3
        for i in range(3):
            for j in range(3):
                if j != i:
                    # import pdb
                    # pdb.set_trace()
                    newDp[j] = max(newDp[j], dp[i] + z[j])
        dp = newDp
    print(max(dp[0],dp[1],dp[2]))


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys


def input():
    return sys.stdin.readline().strip()


def main():
    size = int(input())
    array = []
    dp = [0] * size
    for _ in range(size):
        z = (list(map(int, input().split())))
        newDp = [0] * size
        for i in range(3):
            for j in range(3):
                if j != i:
                    newDp[j] = max(newDp[j], dp[i] + z[j])
        dp = newDp
    print(max(dp[0],dp[1],dp[2]))


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

Fixed submission:
import sys


def input():
    return sys.stdin.readline().strip()

def main():

    # i have too make index as weight and value as value
    import numpy as np

    n, capacity = map(int, input().split())
    value_max = 10 ** 5
    dp = np.full(value_max + 1, capacity + 1)
    dp[0] = 0

    for i in range(n):
        w, v = map(int, input().split())
        np.minimum(dp[v:], dp[:-v] + w, out=dp[v:])

    print(np.where(dp <= capacity)[0][-1])


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys


def input():
    return sys.stdin.readline().strip()

def main():

    # i have too make index as weight and value as value
    import numpy as np
    N, W = map(int, input().split())

    dp = np.zeros(W + 1, int)

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


    print(dp[-1])


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

Fixed submission:
import sys

sys.setrecursionlimit(10**8)

INF = int(1e9)

memo = [-1 for i in range(100000)]

def dp(at):
  if at >= n-1: return 0
  if memo[at] != -1: return memo[at]
  memo[at] = min((dp(at+1)+abs(stones[at]-stones[at+1])), (dp(at+2)+abs(stones[at]-stones[at+2])))
  return memo[at]

n = int(sys.stdin.readline())

stones = map(int, sys.stdin.readline().split())
stones.append(INF)
stones.append(INF)
print dp(0)

Buggy submission (verdict: Runtime Error):
import sys

INF = int(1e9)

memo = [-1 for i in range(100000)]

def dp(at):
  if at >= n-1: return 0
  if memo[at] != -1: return memo[at]
  memo[at] = min((dp(at+1)+abs(stones[at]-stones[at+1])), (dp(at+2)+abs(stones[at]-stones[at+2])))
  return memo[at]

n = int(sys.stdin.readline())

stones = map(int, sys.stdin.readline().split())
stones.append(INF)
stones.append(INF)
print dp(0)
Problem p03164 (python)

Fixed submission:
def solve(w,v,tv,W):
    dp=[float('inf')]*(tv+1)
    dp[0]=0
    for i in range(len(w)):
        for j in range(tv-v[i],-1,-1):
            dp[j+v[i]]=min(dp[j+v[i]],dp[j]+w[i])
    maxx=0
    for i in range(tv+1):
        if dp[i]<=W:
            maxx=max(maxx,i)
    return maxx
if __name__=='__main__':
    n,W=map(int,input().split())
    w=[]
    v=[]
    for i in range(n):
        p,q=map(int,input().split())
        w.append(p)
        v.append(q)
    print(solve(w,v,sum(v),W))

Buggy submission (verdict: Runtime Error):
def solve(a,w,dp):
    if not a or w==0: return 0
    if (str(a),w) in dp: return dp[(str(a),w)]
    maxx=0
    for i in range(len(a)):
        if a[i][0]<=w:
            maxx=max(maxx,a[i][1]+solve(a[:i]+a[i+1:],w-a[i][0],dp))
    dp[(str(a),w)]=maxx
    return maxx
if __name__=='__main__':
    n,w=map(int,input().split())
    a=[]
    sw=0
    for i in range(n):
        p,q=map(int,input().split())
        a.append((p,q))
        sw+=a[-1][0]
    a.sort(key=lambda x: x[0])
    print(solve(a,w,{}))
Problem p03160 (python)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
b = [0]*n
b[1] = abs(a[1]-a[0])
for i in range(2,n):
    b[i]=min(b[i-2]+abs(a[i-2]-a[i]), b[i-1]+abs(a[i-1]-a[i]))
print(b[n-1])

Buggy submission (verdict: Runtime Error):
n = int(input())
a = []
d = []
for _ in range(n):
    a.append(list(map(int,input().split())))
    d.append([0,0,0])
d[0]=a[0]
for i in range(1,n):
    for j in range(3):
        d[i][j]=max(d[i-1][(j+1)%3],d[i-1][(j+2)%3])+a[i][j]
print(max(d[n-1]))
Problem p03161 (python)

Fixed submission:
n,k = map(int,input().split())
a = list(map(int,input().split()))
c = [10**9]*n
c[0]=0
c[1]=abs(a[0]-a[1])
for i in range(n-1):
    for j in range(i+1,min(n,i+k+1)):
        c[j] = min(c[j],c[i]+abs(a[i]-a[j]))
print(c[n-1])

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
b = [0]*n
b[1] = abs(a[1]-a[0])
for i in range(2,n):
    b[i]=min(b[i-2]+abs(a[i-2]-a[i]), b[i-1]+abs(a[i-1]-a[i]))
print(b[n-1])
Problem p03162 (python)

Fixed submission:
n = int(input())
a = []
d = []
for _ in range(n):
    a.append(list(map(int,input().split())))
    d.append([0,0,0])
d[0]=a[0]
for i in range(1,n):
    for j in range(3):
        d[i][j]=max(d[i-1][(j+1)%3],d[i-1][(j+2)%3])+a[i][j]
print(max(d[-1]))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = []
b = []
for _ in range(n):
    a.append(list(map(int,input().split())))
    d.append([0,0,0])
d[0]=a[0]
for i in range(1,n):
    for j in range(3):
        d[i][j]=max(d[i-1][(j+1)%3],d[i-1][(j+2)%3])+a[i][j]
print(max(d[n-1]))
Problem p03162 (python)

Fixed submission:
n=int(input())
a=[0]*(n)
b=[0]*(n)
c=[0]*(n)
for _ in range(n):
    a[_],b[_],c[_]=map(int,input().split())

dp=[[0]*3 for _ in range(n)]

dp[0] = [a[0],b[0],c[0]]

for i in range(n-1):
    dp[i+1][0]=max(dp[i][1]+a[i+1], dp[i][2]+a[i+1])
    dp[i+1][1]=max(dp[i][0]+b[i+1], dp[i][2]+b[i+1])
    dp[i+1][2]=max(dp[i][0]+c[i+1], dp[i][1]+c[i+1])
print(max(dp[n-1]))

Buggy submission (verdict: Runtime Error):
n=int(input())
a=[0]*(n-1)
b=[0]*(n-1)
c=[0]*(n-1)
for _ in range(n-1):
    a,b,c=map(int,input().split())

dp=[[0]*3 for _ in range(n)]

dp[0] = [a[0],b[0],c[0]]

for i in range(n-1):
    dp[i+1][0]=max(dp[i][1]+a[i+1], dp[i][2]＋a[i＋1])
    dp[i+1][1]=max(dp[i][0]+b[i+1], dp[i][2]＋b[i＋1])
    dp[i+1][2]=max(dp[i][0]+c[i+1], dp[i][1]＋c[i＋1])
print(max(dp[n-1]))
Problem p03163 (python)

Fixed submission:
import numpy as np

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

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

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

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

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

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

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

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

N,W = list(map(int,input().split()))
w_l = []
v_l = []
dp = np.zeros(W+1,dtype = int)
for i in range(N):
    w,v = list(map(int,input().split()))
    w_l.append(w)
    v_l.append(v)
for i in range(N):
    dp[w_l[i]:] = np.maximum(dp[w_l[i]:],dp[:-w_l[i]] + v_l[i])
print(dp[W])
Problem p03164 (python)

Fixed submission:
import numpy as np
N,W = map(int,input().split())
V_sum = 0
w_l = []
v_l = []
for i in range(N):
    w,v = list(map(int,input().split()))
    V_sum+=v
    w_l.append(w)
    v_l.append(v)
dp = np.full(V_sum+1,W+1)
dp[0] = 0
for i in range(N):
    dp[v_l[i]:] = np.minimum(dp[v_l[i]:],dp[:-v_l[i]]+w_l[i])
for i in range(V_sum,-1,-1):
    if dp[i]<=W:
        print(i)
        break

Buggy submission (verdict: Runtime Error):
import numpy as np
N,W = list(map(int,input()).split())
V_sum = 0
w_l = []
v_l = []
for i in range(N):
    w,v = list(map(int,input().split()))
    V_sum+=v
    w_l.append(w)
    v_l.append(v)
dp = np.full((V_sum+1,1),10**6)
for i in range(N):
    dp[v_l[i]:] = np.minimum(dp[v_l[i]:],dp[:-v_l[i]]+w_l[i])
for i in range(V_sum+1,-1,-1):
    if dp[i]<=W:
        print(i)
        break

Buggy submission (verdict: Runtime Error):
n,w=list(map(int,input().split()))
a=[]
for i in range(n):
    a.append(list(map(int,input().split())))
a.sort()
b=[]
for i in range(n):
    b.append([0]*(w+1))
for i in range(1,w+1):
    if i>=a[0][0]:
        b[0][i]=a[0][1]
 
for i in range(1,n):
    for j in range(1,w+1):
        if j>=a[i][0]:
            b[i][j]=max(b[i-1][j],b[i-1][j-a[i][0]]+a[i][1])
        else:
            b[i][j]=b[i-1][j]
print(b[n-1][w])
Problem p03161 (python)

Fixed submission:
import sys
N,k=map(int,input().split())
l=[int(x) for x in input().split()]
l1=[sys.maxsize]*(N)
l1[0]=0
for i in range(N):
    for j in range(i+1,i+k+1):
        if j<N:
            l1[j]=min(l1[j],l1[i]+abs(l[j]-l[i]))
print(l1[N-1])

Buggy submission (verdict: Runtime Error):
import sys
N,k=map(int,input())
l=[int(x) for x in input().split()]
l1=[sys.maxsize]*(N)
l1[0]=0
for i in range(N):
    for j in range(i+1,i+k+1):
        if j<N:
            l1[j]=min(l1[j],l1[i]+abs(l[j]-l[i]))
print(l1[N-1])

Buggy submission (verdict: Runtime Error):
import sys
N,k=map(int,input())
l=[int(x) for x in input().split()]
l1=[sys.maxsize]*(N)
l1[0]=0
for i in range(N):
    for j in range(i+1,i+k+1):
        if j<N:
            l1[j]=min(l1[j],l1[i]+abs(l[j]-l[i]))
print(l1[N-1])

Buggy submission (verdict: Runtime Error):
import sys
N=int(input())
l=[int(x) for x in input().split()]
l1=[sys.maxsize]*(N+1)
l1[0]=0
for i in range(N):
    for j in range(i+1,i+k+1):
        if j<N:
            l1[j]=min(l1[j],l1[i]+abs(l[j]-l[i]))
print(l1[N-1])
Problem p03160 (python)

Fixed submission:
def solve(h):
	best_p = abs(h[0] - h[1])
	best_pp = 0
	n = 2
	while n < len(h):
		cost1 = best_p + abs(h[n] - h[n-1])
		cost2 = best_pp + abs(h[n] - h[n-2])
		best = min(cost1, cost2)
		best_pp, best_p = best_p, best
		n = n + 1
	return best_p


def main():
	N = int(input())
	heights = list(map(int, input().split()))
	assert len(heights) == N
	assert N >= 2
	res = solve(heights)
	print(res)


if __name__ == '__main__':
	main()

Buggy submission (verdict: Runtime Error):
def solve(N, K, h):
	INF = 10000 * N * K + 10000
	cost = [INF for x in range(N)]
	cost[0] = 0
	for i in range(N):
		for j in range(min(N, i + 1), min(N, i + K + 1)):
			cost_ij = abs(h[i] - h[j]) + cost[i]
			cost[j] = min(cost[j], cost_ij)
	return cost[N - 1]


def main():
	N , K = list(map(int, input().split()))
	h = list(map(int, input().split()))
	assert len(h) == N
	assert N >= 2
	res = solve(N, K, h)
	print(res)


if __name__ == '__main__':
	main()

Buggy submission (verdict: Runtime Error):
def solve(N, K, h):
	INF = 10000 * N * K + 10000
	cost = [INF for _ in range(N)]
	cost[0] = 0
	for i in range(N):
		for j in range(min(N, i + 1), min(N, i + K + 1)):
			cost_ij = abs(h[i] - h[j]) + cost[i]
			cost[j] = min(cost[j], cost_ij)
	return cost[N - 1]


def main():
	N , K = list(map(int, input().split()))
	h = list(map(int, input().split()))
	assert len(h) == N
	assert N >= 2
	res = solve(N, K, h)
	print(res)


if __name__ == '__main__':
	main()