Buggy python submission (verdict: Time Limit Exceeded):
import sys
n,k=map(int,input().split())
hlist=list(map(int,input().split()))
 
mins=[0,abs(hlist[1]-hlist[0])]

if n == 2:
	print(abs(hlist[1]-hlist[0]))
	sys.exit()

for i in range(2,n):
	smallest=10**12
	tmp=hlist[i]
	for j in range(min(k,i)):
		smallest=min(smallest,mins[i-j-1]+abs(tmp-hlist[i-j-1]))
	mins.append(smallest)
	

print(mins[n-1])

Fixed submission:
n,k=map(int,input().split())
hlist=list(map(int,input().split()))
 
mins=[0]
 
for i in range(1,n):
	if i == 1:
		mins.append(abs(hlist[1]-hlist[0]))
		continue
	
	tmplist=[]
	tmp=hlist[i]
	for j in range(min(k,i)):
		tmplist.append(mins[i-j-1]+abs(tmp-hlist[i-j-1]))
	mins.append(min(tmplist))
 
print(mins[n-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
n,k=map(int,input().split())
hlist=list(map(int,input().split()))
 
mins=[0]

if n == 2:
	print(abs(hlist[1]-hlist[0]))
	sys.exit()

for i in range(1,n):
	tmplist=[]
	tmp=hlist[i]
	for j in range(min(k,i)):
		tmplist.append(mins[i-j-1]+abs(tmp-hlist[i-j-1]))
	mins.append(min(tmplist))
	

print(mins[n-1])

Fixed submission:
n,k=map(int,input().split())
hlist=list(map(int,input().split()))
 
mins=[0]
 
for i in range(1,n):
	if i == 1:
		mins.append(abs(hlist[1]-hlist[0]))
		continue
	
	tmplist=[]
	tmp=hlist[i]
	for j in range(min(k,i)):
		tmplist.append(mins[i-j-1]+abs(tmp-hlist[i-j-1]))
	mins.append(min(tmplist))
 
print(mins[n-1])

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
hlist=list(map(int,input().split()))

mins=[0]

if n == 2:
	print(abs(hlist[1]-hlist[0]))

for i in range(1,n):	
	smallest=1000000000001
	tmp=hlist[i]
	for j in range(min(k,i)):
		smallest=min(smallest,mins[i-j-1]+abs(tmp-hlist[i-j-1]))
	mins.append(min(tmplist))

print(mins[n-1])


Fixed submission:
n,k=map(int,input().split())
hlist=list(map(int,input().split()))
 
mins=[0]
 
for i in range(1,n):
	if i == 1:
		mins.append(abs(hlist[1]-hlist[0]))
		continue
	
	tmplist=[]
	tmp=hlist[i]
	for j in range(min(k,i)):
		tmplist.append(mins[i-j-1]+abs(tmp-hlist[i-j-1]))
	mins.append(min(tmplist))
 
print(mins[n-1])

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
hlist=list(map(int,input().split()))

mins=[0]

if n == 2:
	print(abs(hlist[1]-hlist[0]))

for i in range(1,n):	
	smallest=10001
	tmp=hlist[i]
	for j in range(min(k,i)):
		smallest=min(smallest,mins[i-j-1]+abs(tmp-hlist[i-j-1]))
	mins.append(min(tmplist))

print(mins[n-1])


Fixed submission:
n,k=map(int,input().split())
hlist=list(map(int,input().split()))
 
mins=[0]
 
for i in range(1,n):
	if i == 1:
		mins.append(abs(hlist[1]-hlist[0]))
		continue
	
	tmplist=[]
	tmp=hlist[i]
	for j in range(min(k,i)):
		tmplist.append(mins[i-j-1]+abs(tmp-hlist[i-j-1]))
	mins.append(min(tmplist))
 
print(mins[n-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
hlist=list(map(int,input().split()))

mins=[0]

for i in range(1,n):
	if i == 1:
		mins.append(abs(hlist[1]-hlist[0]))
		continue
	
	tmplist=[]
	tmp=hlist[i]
	for j in range(min(k,i)):
		tmplist.append(mins[i-j-1]+abs(tmp-hlist[i-j-1]))
	mins.append(min(tmplist))

print(mins[n-1])


Fixed submission:
n,k=map(int,input().split())
hlist=list(map(int,input().split()))
 
mins=[0]
 
for i in range(1,n):
	if i == 1:
		mins.append(abs(hlist[1]-hlist[0]))
		continue
	
	tmplist=[]
	tmp=hlist[i]
	for j in range(min(k,i)):
		tmplist.append(mins[i-j-1]+abs(tmp-hlist[i-j-1]))
	mins.append(min(tmplist))
 
print(mins[n-1])