Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N = int(input())
h = [*map(lambda x: int(x), input().split())]

#bottom-up
def iterative_method(final):
    i = 0
    min_table = {0: 0}

    while (i < final):
        if i+1 in min_table:
            min_table[i+1] =  min(min_table[i+1], min_table[i] + abs(h[i+1] - h[i]))
        else:
            min_table[i+1] = min_table[i] + abs(h[i+1] - h[i])
        try:
            if i+2 in min_table:
                min_table[i+2] = min(min_table[i+2], min_table[i] + abs(h[i+2] - h[i]))
            else:
                min_table[i+2] = min_table[i] + abs(h[i+2] - h[i])
        except:
            break
        i += 1


    print(min_table[final])

#topdown
def recursive_method(n):
    memo = [-1]*n
    memo[0] = 0
    memo[1] = abs(h[1] - h[0])
    def recurse(i):
        if memo[i] != -1:
            return memo[i]
        else:
            memo[i] = min( recurse(i-1) + abs(h[i] - h[i-1]), recurse(i-2) + abs(h[i] - h[i-2]))
            return memo[i]
    return recurse(n-1)

    

print(recursive_method(N))

Fixed submission:
N = int(input())
h = [*map(lambda x: int(x), input().split())]

#bottom-up

def iterative_method(final):
    i = 0
    min_table = {0: 0}

    while (i < final):
        if i+1 in min_table:
            min_table[i+1] =  min(min_table[i+1], min_table[i] + abs(h[i+1] - h[i]))
        else:
            min_table[i+1] = min_table[i] + abs(h[i+1] - h[i])
        try:
            if i+2 in min_table:
                min_table[i+2] = min(min_table[i+2], min_table[i] + abs(h[i+2] - h[i]))
            else:
                min_table[i+2] = min_table[i] + abs(h[i+2] - h[i])
        except:
            break
        i += 1


    print(min_table[final])

iterative_method(N-1)
Buggy python submission (verdict: Runtime Error):
import numpy as np

N, W = [int(x) for x in input().split()]
weight = np.zeros((N,2))
for x in range(N):
    weight[x] = [int(y) for y in input().split()]
#topdown
memo = np.zeros((N+1,W+1))
for x in range(N+1):
    memo[x] = [-1]*(W+1)

def dp(n,w):
    if w < 0:
        return -float('inf')
    elif n == 0 or w == 0:
        return 0
    elif memo[n][w] != -1:
        return memo[n][w]
    else:
        memo[n][w] = max(dp(n-1,w), dp(n-1,w - int(weight[n-1][0])) + weight[n-1][1])
        return memo[n][w]

print(int(dp(N,W)))


Fixed submission:
import numpy as np

N = int(input())
a = np.zeros((N,3))
for i in range(N):
    a[i][0],a[i][1],a[i][2] = map(int,input().split())

memo = np.zeros((N,3))

memo[0][0], memo[0][1], memo[0][2] = a[0][0],a[0][1],a[0][2]
day = 1

while (day < N):
    memo[day] = [max(memo[day-1][(x+1)%3],memo[day-1][(x+2)%3]) + a[day][x] \
                   for x in [0,1,2]]
    day += 1

print(int(max(memo[day - 1])))
Buggy python submission (verdict: Runtime Error):
import numpy as np

N, W = [int(x) for x in input().split()]
weight = np.zeros((N,2))
for x in range(N):
    weight[x] = [int(y) for y in input().split()]
#topdown
memo = np.zeros((N+1,W+1))
for x in range(N+1):
    memo[x] = [-1]*(W+1)

def dp(n,w):
    if w < 0:
        return -float('inf')
    elif n == 0 or w == 0:
        return 0
    elif memo[n][w] != -1:
        return memo[n][w]
    else:
        memo[n][w] = max(dp(n-1,w), dp(n-1,w - int(weight[n-1][0])) + weight[n-1][1])
        return memo[n][w]

print(int(dp(N,W)))

Fixed submission:
import numpy as np

N, W = [int(x) for x in input().split()]
items = [tuple(map(int, input().split())) for _ in range(N)]

#topdown
memo = np.zeros(shape = W+1, dtype = np.int64)

for w,v in items:
    memo[w:] = np.maximum( memo[w:], memo[:-w] + v)

print(memo[-1])

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

N, W = [int(x) for x in input().split()]
weight = np.zeros((N,2))
for x in range(N):
    weight[x] = [int(y) for y in input().split()]
#topdown
memo = np.zeros((N+1,W+1))
for x in range(N+1):
    memo[x] = [-1]*(W+1)

def dp(n,w):
    if w < 0:
        return -float('inf')
    elif n == 0 or w == 0:
        return 0
    elif memo[n][w] != -1:
        return memo[n][w]
    else:
        memo[n][w] = max(dp(n-1,w), dp(n-1,w - int(weight[n-1][0])) + weight[n-1][1])
        return memo[n][w]

print(int(dp(N,W)))


Fixed submission:
import numpy as np

N, W = [int(x) for x in input().split()]
items = [tuple(map(int, input().split())) for _ in range(N)]

#topdown
memo = np.zeros(shape = W+1, dtype = np.int64)

for w,v in items:
    memo[w:] = np.maximum( memo[w:], memo[:-w] + v)

print(memo[-1])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N, W = [int(x) for x in input().split()]
weight = np.zeros((N,2))
for x in range(N):
    weight[x] = [int(y) for y in input().split()]
#topdown
memo = np.zeros((N+1,W+1))
for x in range(N+1):
    memo[x] = [-1]*(W+1)

def dp(n,w):
    if w < 0:
        return -float('inf')
    elif n == 0 or w == 0:
        return 0
    elif memo[n][w] != -1:
        return memo[n][w]
    else:
        memo[n][w] = max(dp(n-1,w), dp(n-1,w - int(weight[n-1][0])) + weight[n-1][1])
        return memo[n][w]

print(int(dp(N,W)))

Fixed submission:
import numpy as np

N, W = [int(x) for x in input().split()]
items = [tuple(map(int, input().split())) for _ in range(N)]

#topdown
memo = np.zeros(shape = W+1, dtype = np.int64)

for w,v in items:
    memo[w:] = np.maximum( memo[w:], memo[:-w] + v)

print(memo[-1])
Buggy python submission (verdict: Time Limit Exceeded):

N, W = [int(x) for x in input().split()]
items = [tuple(map(int, input().split())) for _ in range(N)]

#bottomup
memo = [10**10]*(10**5+1)
memo[0] = 0

for weight, value in items:
    for i in reversed(range(len(memo)-value)):
            memo[i+value] = min(memo[i+value],memo[i] + weight)

ans = 0
for i in range(len(memo)):
    if memo[i] != 10**10 and memo[i] <= W:
        ans = i

print(ans)


Fixed submission:

N, W = [int(x) for x in input().split()]
items = [tuple(map(int, input().split())) for _ in range(N)]

#bottomup
memo = [10**10]*(10**5+1)
memo[0] = 0

for weight, value in items:
    for i in reversed(range(len(memo)-value)):
            memo[i+value] = min(memo[i+value],memo[i] + weight)

ans = 0
for i in range(len(memo)):
    if memo[i] != 10**10 and memo[i] <= W:
        ans = i

print(ans)

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

N, W = [int(x) for x in input().split()]
items = [tuple(map(int, input().split())) for _ in range(N)]

#topdown
memo = np.zeros(shape = W+1, dtype = np.int64)

for w,v in items:
    memo[w:] = np.maximum( memo[w:], memo[:-w] + v)

print(memo[-1])

Fixed submission:

N, W = [int(x) for x in input().split()]
items = [tuple(map(int, input().split())) for _ in range(N)]

#bottomup
memo = [10**10]*(10**5+1)
memo[0] = 0

for weight, value in items:
    for i in reversed(range(len(memo)-value)):
            memo[i+value] = min(memo[i+value],memo[i] + weight)

ans = 0
for i in range(len(memo)):
    if memo[i] != 10**10 and memo[i] <= W:
        ans = i

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
"""
https://atcoder.jp/contests/dp/tasks/dp_a
"""
from copy import deepcopy
N = int(input())
arr = [int(i) for i in input().split(" ")]

def getMinSteps():
    dp_2 = [0, ]
    dp_1 = [abs(arr[1] - arr[0]), ]
    
    total_cost = 0
    i = 2
    
    while i < N:
        diff1 = abs(arr[i] - arr[i-1])
        diff2 = abs(arr[i] - arr[i-2])
        temp = deepcopy(dp_2)
        dp_2 = deepcopy(dp_1)

        for j in range(len(dp_1)):
            dp_1[j] += diff1

        for j in range(len(temp)):
            dp_1.append(temp[j] + diff2)

        i += 1
    return min(dp_1)

        
print(getMinSteps())

Fixed submission:
"""
https://atcoder.jp/contests/dp/tasks/dp_a
"""
from copy import deepcopy
N = int(input())
arr = [int(i) for i in input().split(" ")]

def getMinSteps():
    dp_2 = [0, ]
    dp_1 = [abs(arr[1] - arr[0]), ]
    
    total_cost = 0
    i = 2
    
    while i < N:
        diff1 = abs(arr[i] - arr[i-1])
        diff2 = abs(arr[i] - arr[i-2])
        temp = deepcopy(dp_2)
        dp_2 = deepcopy(dp_1)

        for j in range(len(dp_1)):
            dp_1[j] += diff1

        for j in range(len(temp)):
            dp_1.append(temp[j] + diff2)
            
        dp_1 = sorted(dp_1)[0:2]
        
        i += 1
    return min(dp_1)

        
print(getMinSteps())
Buggy python submission (verdict: Runtime Error):
def frogOne(N, arr):
    dparr= [-1 for i in range(N)]
    dparr[0] = 0
    dparr[1] = abs(arr[0]-arr[1])
    for num in range(2,N):
        dparr[num] = min(dparr[num-2]+ abs(arr[num]-arr[num-2]), dparr[num-1]+ abs(arr[num]-arr[num-1]))
    return dparr[-1]


 if __name__ == '__main__':
   N = int(input())
   arr = list(map(int,input().rstrip().split()))
   print(frogOne(N, arr))

Fixed submission:
N = int(input())
arr = list(map(int,input().rstrip().split()))
dparr= [-1 for i in range(N)]
dparr[0] = 0
dparr[1] = abs(arr[0]-arr[1])
for num in range(2,N):
  dparr[num] = min(dparr[num-2]+ abs(arr[num]-arr[num-2]), dparr[num-1]+ abs(arr[num]-arr[num-1]))
print(dparr[-1])
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
t = input()

n = len(t) + 1
m = len(s) + 1

data = [[0 for _ in range(n)] for _ in range (m)]

ans = ''
for i in range(1,m) :
  for j in range(1,n) :
    if s[i-1] == t[j-1] :
      data[i][j] = data[i-1][j-1] + 1
    else :
      data[i][j] = max(data[i-1][j] , data[i][j-1])

i = len(s)
j = len(t)

while i>0 and j>0 :
  if data[i][j] == data[i][j-1] :
    j -= 1
  elif data[i][j] == data[i-1][j] :
    i -= 1
  else :
    ans = s[i-1] + ans
    i -= 1
    j -= 1
    
print(ans)

Fixed submission:
s = input()
t = input()

n = len(t) + 1
m = len(s) + 1

data = [[0 for _ in range(n)] for _ in range (m)]

ans = ''
for i in range(1,m) :
  for j in range(1,n) :
    if s[i-1] == t[j-1] :
      data[i][j] = data[i-1][j-1] + 1
    else :
      data[i][j] = max(data[i-1][j] , data[i][j-1])

i = len(s)
j = len(t)

while i>0 and j>0 :
  if data[i][j] == data[i][j-1] :
    j -= 1
  elif data[i][j] == data[i-1][j] :
    i -= 1
  else :
    ans = s[i-1] + ans
    i -= 1
    j -= 1
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
t = input()

data = [[0 for _ in range(len(t)+1)] for _ in range (len(s)+1)]

ans = ''
for i in range(1,len(s)+1) :
  for j in range(1,len(t)+1) :
    if s[i-1] == t[j-1] :
      data[i][j] = data[i-1][j-1] + 1
    else :
      data[i][j] = max(data[i-1][j] , data[i][j-1])

i = len(s)
j = len(t)

while i>0 and j>0 :
  if data[i][j] == data[i][j-1] :
    j -= 1
  elif data[i][j] == data[i-1][j] :
    i -= 1
  else :
    ans = s[i-1] + ans
    i -= 1
    j -= 1
   
print(ans)

Fixed submission:
s = input()
t = input()

n = len(t) + 1
m = len(s) + 1

data = [[0 for _ in range(n)] for _ in range (m)]

ans = ''
for i in range(1,m) :
  for j in range(1,n) :
    if s[i-1] == t[j-1] :
      data[i][j] = data[i-1][j-1] + 1
    else :
      data[i][j] = max(data[i-1][j] , data[i][j-1])

i = len(s)
j = len(t)

while i>0 and j>0 :
  if data[i][j] == data[i][j-1] :
    j -= 1
  elif data[i][j] == data[i-1][j] :
    i -= 1
  else :
    ans = s[i-1] + ans
    i -= 1
    j -= 1
    
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
c = [0]*n
dp = [0]*n
for i in range(n):
    c = list(map(int, input().split()))
    new_dp = [0]*3
    for j in range(3):
        for k in range(3):
            if j != k:
                new_dp[k] = max(new_dp[k], dp[j] + c[k])
    dp = new_dp[:]
print(max(dp))


Fixed submission:
n = int(input())
c = []
dp = [0]*3
# for i in range(n):
#     c.append(list(map(int, input().split())))
for i in range(n):
    c = list(map(int, input().split()))
    new_dp = [0]*3
    for j in range(3):
        for k in range(3):
            if j != k:
                new_dp[k] = max(new_dp[k], dp[j] + c[k])
    dp = new_dp[:]
print(max(dp))
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n, maxW, weight, value = getInputs()

    maxCount = {}
    for w in range(n):
        if str(w) in maxCount:
            maxCount[str(w)] += 1
        else:
            maxCount[str(w)] = 1

    accumulatedValue = [0] * (maxW + 1)
    possible = [False] * (maxW + 1)
    possible[0] = True

    used = []
    for i in range(maxW + 1):
        used.append({})

    for x in range(min(weight), maxW + 1):
        for w in range(n):
            if (x - weight[w] >= 0) and possible[x - weight[w]] \
                and (str(w) not in used[x - weight[w]] or used[x - weight[w]][str(w)] < maxCount[str(w)]):

                if accumulatedValue[x - weight[w]] + value[w] > accumulatedValue[x]:
                    accumulatedValue[x] = accumulatedValue[x - weight[w]] + value[w]
                    used[x] = used[x - weight[w]].copy()
                    if str(w) in used[x]:
                        used[x][str(w)] += 1
                    else:
                        used[x][str(w)] = 1

                    possible[x] = True

    print(max(accumulatedValue))

def getInputs():
    n, maxW = map(lambda x: int(x), input().split())

    weight, value = [], []
    for i in range(n):
        w, v = map(lambda x: int(x), input().split())
        weight.append(w)
        value.append(v)

    return n, maxW, weight, value

main()


Fixed submission:
def main():
    n, maxW, weight, value = getInputs()

    accumulatedValue = [0] * (maxW + 1)

    possible = [False] * (maxW + 1)
    possible[0] = True

    used = []
    for i in range(maxW + 1):
        used.append([0] * n)

    for x in range(min(weight), maxW + 1):
        for w in range(n):
            weightW = weight[w]

            if (x - weightW >= 0) and possible[x - weightW] and used[x - weightW][w] == 0:
                newValue = accumulatedValue[x - weightW] + value[w]

                if newValue > accumulatedValue[x]:
                    accumulatedValue[x] = newValue
                    used[x] = used[x - weightW].copy()
                    used[x][w] = 1
                    possible[x] = True

    print(max(accumulatedValue))

def getInputs():
    n, maxW = map(lambda x: int(x), input().split())

    weight, value = [], []
    for i in range(n):
        w, v = map(lambda x: int(x), input().split())
        weight.append(w)
        value.append(v)

    return n, maxW, weight, value

main()
Buggy python submission (verdict: Time Limit Exceeded):
######################################################
############Created by Devesh Kumar###################
#############devesh1102@gmail.com####################
##########For CodeForces(Devesh1102)#################
#####################2020#############################
######################################################
import sys
input = sys.stdin.readline

# import sys
import heapq 
import copy
import math
import decimal
# import sys.stdout.flush as flush
# from decimal import *
#heapq.heapify(li) 
#
#heapq.heappush(li,4) 
#
#heapq.heappop(li)
#
# &	Bitwise AND Operator	10 & 7 = 2
# |	Bitwise OR Operator	10 | 7 = 15
# ^	Bitwise XOR Operator	10 ^ 7 = 13
 
# <<	Bitwise Left Shift operator	10<<2 = 40
# >>	Bitwise Right Shift Operator
# '''############ ---- Input Functions ---- #######Start#####'''
 

def inp():
	return(int(input()))
def inlt(): 
	return(list(map(int,input().split())))
def insr():
	s = input()
	return(list(s[:len(s) - 1]))
def insr2():
	s = input()
	return((s[:len(s) - 1]))
def invr():
	return(map(int,input().split()))
 ############ ---- Input Functions ---- #######End
 # #####   

def pr_list(a):
	print(*a, sep=" ")
def main():
	# tests =  inp()
	tests = 1
	mod = 998244353
	limit = 10**18
	ans = 0
	for test in range(tests):
		[n,k] = inlt()
		h = inlt()
		dp = [sys.maxsize for i in range(n+3)]
		dp[0] = 0
		for i in range(0,n):
			for j in range(1,k+1):
				if i+j <n:
					dp[i+j] = min(dp[i+j],dp[i] + abs(h[i+j] - h[i]))
		# print(dp)
		print(dp[n-1])

if __name__== "__main__":
	main()

Fixed submission:
######################################################
############Created by Devesh Kumar###################
#############devesh1102@gmail.com####################
##########For CodeForces(Devesh1102)#################
#####################2020#############################
######################################################
import sys
input = sys.stdin.readline

# import sys
import heapq 
import copy
import math
import decimal
# import sys.stdout.flush as flush
# from decimal import *
#heapq.heapify(li) 
#
#heapq.heappush(li,4) 
#
#heapq.heappop(li)
#
# &	Bitwise AND Operator	10 & 7 = 2
# |	Bitwise OR Operator	10 | 7 = 15
# ^	Bitwise XOR Operator	10 ^ 7 = 13
 
# <<	Bitwise Left Shift operator	10<<2 = 40
# >>	Bitwise Right Shift Operator
# '''############ ---- Input Functions ---- #######Start#####'''
 

def inp():
	return(int(input()))
def inlt(): 
	return(list(map(int,input().split())))
def insr():
	s = input()
	return(list(s[:len(s) - 1]))
def insr2():
	s = input()
	return((s[:len(s) - 1]))
def invr():
	return(map(int,input().split()))
 ############ ---- Input Functions ---- #######End
 # #####   

def pr_list(a):
	print(*a, sep=" ")
def main():
	# tests =  inp()
	tests = 1
	mod = 998244353
	limit = 10**18
	ans = 0
	for test in range(tests):
		[n,k] = inlt()
		h = inlt()
		dp = [sys.maxsize for i in range(n+3)]
		dp[0] = 0
		for i in range(0,n):
			for j in range(1,k+1):
				if i+j <n:
					dp[i+j] = min(dp[i+j],dp[i] + abs(h[i+j] - h[i]))
		# print(dp)
		print(dp[n-1])

if __name__== "__main__":
	main()
Buggy python submission (verdict: Runtime Error):
import math
n=int(input())
infy=math.inf
arr=[int(x) for x in input().split()]
arr.append(0)
val=[infy]*(n+1)
val[0]=0
for i in range(0,n-1):
    val[i+1]=min(val[i+1],abs(arr[i+1]-arr[i])+val[i])
    val[i+2]=min(val[i+2],abs(arr[i+2]-arr[i])+val[i])

print(val[n-1])




Fixed submission:
n=int(input())
infy=float('inf')
arr=[int(x) for x in input().split()]
arr.append(0)
val=[infy]*(n+1)
val[0]=0
for i in range(0,n-1):
    val[i+1]=min(val[i+1],abs(arr[i+1]-arr[i])+val[i])
    val[i+2]=min(val[i+2],abs(arr[i+2]-arr[i])+val[i])

print(val[n-1])

Buggy python submission (verdict: Runtime Error):
import math
n=int(input())
infy=math.inf
arr=[int(x) for x in input().split()]
arr.append(0)
val=[infy]*(n+1)
val[0]=0
for i in range(0,n-1):
    val[i+1]=min(val[i+1],abs(arr[i+1]-arr[i])+val[i])
    val[i+2]=min(val[i+2],abs(arr[i+2]-arr[i])+val[i])

print(val[n-1])


Fixed submission:
n=int(input())
infy=float('inf')
arr=[int(x) for x in input().split()]
arr.append(0)
val=[infy]*(n+1)
val[0]=0
for i in range(0,n-1):
    val[i+1]=min(val[i+1],abs(arr[i+1]-arr[i])+val[i])
    val[i+2]=min(val[i+2],abs(arr[i+2]-arr[i])+val[i])

print(val[n-1])
Buggy python submission (verdict: Time Limit Exceeded):
n,k=[int(x) for x in input().split()]
infy=float('inf')
arr=[int(x) for x in input().split()]

val=[infy]*(n)
val[0]=0
for i in range(0,n-1):
    for j in range(1,k+1):
        if i+j < n:
            val[i+j]=min(val[i+j],abs(arr[i+j]-arr[i])+val[i])


print(val[n-1])




Fixed submission:
n,k=[int(x) for x in input().split()]
infy=float('inf')
arr=[int(x) for x in input().split()]

val=[infy]*(n)
val[0]=0
for i in range(0,n-1):
    for j in range(1,k+1):
        if i+j < n:
            val[i+j]=min(val[i+j],abs(arr[i+j]-arr[i])+val[i])


print(val[n-1])
Buggy python submission (verdict: Runtime Error):
n,w=[int(x) for x in input().split()]
dp=[0]*(w+1)
lw=w
for test in range(n):
    cw, v = [int(x) for x in input().split()]
    temp=[0]*(w+1)
    for i in range(1,w+1):
        if cw <= i :
            temp[i]=max(dp[i],v+dp[i-cw])
        else:
            temp[i]=max(dp[i],temp[i-1])
    dp=temp[:]
    #print(dp)
print(dp[w])

Fixed submission:
n,w=[int(x) for x in input().split()]

lw=w
totval=0
wei=[]
val=[]
for test in range(n):
    cw, v = [int(x) for x in input().split()]
    wei.append(cw)
    val.append(v)
    totval+=v

dp=[float('inf')]*(totval+1)
dp[0]=0
for item in range(n):
    for j in range(totval,val[item]-1,-1):
        dp[j]=min(dp[j-val[item]]+wei[item],dp[j])
    #print(dp)
ans=0
for i in range(totval+1):
    if dp[i] <=w:
        ans=i
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
def frog2(N,h,k):
    dp=[sys.maxsize-1]*N
    dp[0]=0
    for i in range(N):
        for j in range(i+1,i+k+1):
            if j<N:
                dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]))
    return dp[N-1]

N,k=map(int,input().split())
h=list(map(int,input().split()))
print(frog2(N,h,k))

Fixed submission:
import sys
def frog2(N,h,k):
    dp=[sys.maxsize-1]*N
    dp[0]=0
    for i in range(N):
        for j in range(i+1,i+k+1):
            if j<N:
                dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]))
    return dp[N-1]

N,k=map(int,input().split())
h=list(map(int,input().split()))
print(frog2(N,h,k))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
def frog2(N,h,k):
    dp=[sys.maxsize-1]*N
    dp[0]=0
    for i in range(N):
        for j in range(i+1,i+k+1):
            if j<N:
                dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]))
    return dp[N-1]

N,k=map(int,input().split())
h=list(map(int,input().split()))
print(frog2(N,h,k))

Fixed submission:
import sys
def frog2(N,h,k):
    dp=[sys.maxsize-1]*N
    dp[0]=0
    for i in range(N):
        for j in range(i+1,i+k+1):
            if j<N:
                dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]))
    return dp[N-1]

N,k=map(int,input().split())
h=list(map(int,input().split()))
print(frog2(N,h,k))

Buggy python submission (verdict: Runtime Error):
def frog2(N,h,k):
    dp=[sys.maxsize-1]*N
    dp[0]=0
    for i in range(N):
        for j in range(i+1,i+k+1):
            if j<N:
                dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]))
    return dp[N-1]

N,k=map(int,input().split())
h=list(map(int,input().split()))
print(frog2(N,h,k))

Fixed submission:
import sys
def frog2(N,h,k):
    dp=[sys.maxsize-1]*N
    dp[0]=0
    for i in range(N):
        for j in range(i+1,i+k+1):
            if j<N:
                dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]))
    return dp[N-1]

N,k=map(int,input().split())
h=list(map(int,input().split()))
print(frog2(N,h,k))

Buggy python submission (verdict: Time Limit Exceeded):
def frog2(N,h,k):
    dp=[0]*(N)
    dp[0]=0

    for i in range(1,N):
        mn=float('inf')
        for j in range(1,k+1):
            if i-j>=0:
                mn=min(mn,abs(h[i]-h[i-j])+dp[i-j])
        dp[i]=mn
    return dp[N-1]



N,k=map(int,input().split())
h=list(map(int,input().split()))
print(frog2(N,h,k))

Fixed submission:
import sys
def frog2(N,h,k):
    dp=[sys.maxsize-1]*N
    dp[0]=0
    for i in range(N):
        for j in range(i+1,i+k+1):
            if j<N:
                dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]))
    return dp[N-1]

N,k=map(int,input().split())
h=list(map(int,input().split()))
print(frog2(N,h,k))