Buggy python submission (verdict: Time Limit Exceeded):
n,k,*h=map(int,open(0).read().split())
a=[0]*n
for i in range(1,n):
    j=max(0,i-k)
    a[i]=min(A+abs(h[i]-H) for A,H in zip(a[j:i],h[j:i]))
print(a[-1])

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

Buggy python submission (verdict: Time Limit Exceeded):
n,k,*h=map(int,open(0).read().split())
a=[0]*n
for i in range(1,n):
    a[i]=min(a[i-j]+abs(h[i]-h[i-j]) for j in range(1,k+1) if i-j>=0)
print(a[-1]) 

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

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
h=[int(i) for i in input().split()]
inf=pow(10,6)
dp=[inf]*(n)
dp[0]=0
dp[1]=abs(h[0]-h[1])
for i in range(n):
    for j in range(min(k+1):
        if i+j<n:
            dp[i+j]=min(dp[i+j],dp[i]+abs(h[i]-h[i+j]))
print(dp[-1])       

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

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n,k=map(int,input().split())
    a=[int(i) for i in input().split()]
    dp=[10**9]*n
    dp[0]=0
    dp[1]=abs(a[1]-a[0])
    for i in range(2,n):
        for j in range(max(0,i-k),i):
            dp[i]=min(dp[j]+abs(a[i]-a[j]),dp[i])
    print(dp[-1])
if __name__ == '__main__':
	main()

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

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
dp=[10**9]*n
dp[0]=0
dp[1]=abs(a[1]-a[0])
for i in range(2,n):
    for j in range(max(0,i-k),i):
        dp[i]=min(dp[j]+abs(a[i]-a[j]),dp[i])
print(dp[-1])

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

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
dp=[np.inf]*n
dp[0]=0
dp[1]=abs(a[1]-a[0])

for i in range(2,n):
    for j in range(max(0,i-k),i):
        dp[i]=min(dp[j]+abs(a[i]-a[j]),dp[i])
print(dp[-1])

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

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
dp=[np.inf]*n
dp[0]=0
dp[1]=abs(a[1]-a[0])
for i in range(2,n):
  for j in range(max(0,i-k),i):
    dp[i]=min(dp[j]+abs(a[i]-a[j]),dp[i])
print(dp[-1])

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

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import numpy as np
    n,k=map(int,input().split())
    a=[int(i) for i in input().split()]
    dp=[np.inf]*n
    dp[0]=0
    dp[1]=abs(a[1]-a[0])
    for i in range(2,n):
        for j in range(1,k+1):
            dp[i]=min(dp[i-j]+abs(a[i]-a[i-j]),dp[i])
    print(dp[-1])
if __name__ == '__main__':
	main()

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

Buggy python submission (verdict: Runtime Error):
def main():
  import numpy as np
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
dp=[np.inf]*n
dp[0]=0
dp[1]=abs(a[1]-a[0])
for i in range(2,n):
    for j in range(1,k+1):
        dp[i]=min(dp[i-j]+abs(a[i]-a[i-j]),dp[i])
print(dp[-1])
if __name__ == '__main__':
	main()

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

Buggy python submission (verdict: Runtime Error):
import numpy as np
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
dp=[np.inf]*n
dp[0]=0
dp[1]=abs(a[1]-a[0])
for i in range(2,n):
    for j in range(1,k+1):
        dp[i]=min(dp[i-j]+abs(a[i]-a[i-j]),dp[i])
print(dp[-1])

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

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
dp=[np.inf]*n
dp[0]=0
dp[1]=abs(a[1]-a[0])
for i in range(2,n):
    for j in range(1,k+1):
        dp[i]=min(dp[i-j]+abs(a[i]-a[i-j]),dp[i])
print(dp[-1])

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