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

Fixed submission:
def main():
    N,K = map(int,input().split())
    h = list(map(int,input().split()))
    dp = [0]*N
    for i in range(1,N):
        dp[i]= min(abs(h[i]-h[j])+dp[j] for j in range(max(0,i-K),i))
    print(dp[-1])
main()

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
h = list(map(int,input().split()))
dp = [0]
for i in range(1,N):
  dp.append(min(abs(h[i]-h[j])+dp[j] for j in range(max(0,i-K),i)))
print(dp[-1])

Fixed submission:
def main():
    N,K = map(int,input().split())
    h = list(map(int,input().split()))
    dp = [0]*N
    for i in range(1,N):
        dp[i]= min(abs(h[i]-h[j])+dp[j] for j in range(max(0,i-K),i))
    print(dp[-1])
main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
N,K = map(int,sys.stdin.readline().split())
h = list(map(int,input().split()))
dp = [0]

for i in range(1,N):
  dp.append(min(abs(h[i]-h[j])+dp[j] for j in range(max(0,i-K),i)))
print(dp[-1])

Fixed submission:
def main():
    N,K = map(int,input().split())
    h = list(map(int,input().split()))
    dp = [0]*N
    for i in range(1,N):
        dp[i]= min(abs(h[i]-h[j])+dp[j] for j in range(max(0,i-K),i))
    print(dp[-1])
main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
N,K = map(int,sys.stdin.readline().split())
h = list(map(int,input().split()))
dp = [0]+[float('inf')]*(N-1)

for i in range(1,N):
  
  
    dp[i] = min(abs(h[i]-h[j])+dp[j] for j in range(max(0,i-K),i))
    

print(dp[-1])

Fixed submission:
def main():
    N,K = map(int,input().split())
    h = list(map(int,input().split()))
    dp = [0]*N
    for i in range(1,N):
        dp[i]= min(abs(h[i]-h[j])+dp[j] for j in range(max(0,i-K),i))
    print(dp[-1])
main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
N,K = map(int,sys.stdin.readline().split())
h = list(map(int,input().split()))
dp = [0]+[float('inf')]*(N-1)

for i in range(1,N):
  
  for j in range(max(0,i-K),i):
    dp[i] = min(dp[i],abs(h[i]-h[j])+dp[j])
    

print(dp[-1])

Fixed submission:
def main():
    N,K = map(int,input().split())
    h = list(map(int,input().split()))
    dp = [0]*N
    for i in range(1,N):
        dp[i]= min(abs(h[i]-h[j])+dp[j] for j in range(max(0,i-K),i))
    print(dp[-1])
main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
N,K = map(int,sys.stdin.readline().split())
h = list(map(int,input().split()))
dp = [0]+[float('inf') for a in range(N-1)]

for i in range(1,N):
  
  for j in range(max(0,i-K),i):
    dp[i] = min(dp[i],abs(h[i]-h[j])+dp[j])
    

print(dp[-1])

Fixed submission:
def main():
    N,K = map(int,input().split())
    h = list(map(int,input().split()))
    dp = [0]*N
    for i in range(1,N):
        dp[i]= min(abs(h[i]-h[j])+dp[j] for j in range(max(0,i-K),i))
    print(dp[-1])
main()

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
h = list(map(int,input().split()))
dp = [0]+[float('inf') for a in range(N-1)]

for i in range(1,N):
  
  for j in range(max(0,i-K),i):
    dp[i] = min(dp[i],abs(h[i]-h[j])+dp[j])
    

print(dp[-1])

Fixed submission:
def main():
    N,K = map(int,input().split())
    h = list(map(int,input().split()))
    dp = [0]*N
    for i in range(1,N):
        dp[i]= min(abs(h[i]-h[j])+dp[j] for j in range(max(0,i-K),i))
    print(dp[-1])
main()

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
h = list(map(int,input().split()))
dp = [0]

for i in range(1,N):
  dpx = float('inf')
  for j in range(max(0,i-K),i):
    dpx = min(dpx,abs(h[i]-h[j])+dp[j])
    
  dp.append(dpx)

print(dp[-1])

Fixed submission:
def main():
    N,K = map(int,input().split())
    h = list(map(int,input().split()))
    dp = [0]*N
    for i in range(1,N):
        dp[i]= min(abs(h[i]-h[j])+dp[j] for j in range(max(0,i-K),i))
    print(dp[-1])
main()

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
h = list(map(int,input().split()))
dp = [0 for a in range(N)]

for i in range(1,N):
  dpx = float('inf')
  for j in range(max(0,i-K),i):
    dpx = min(dpx,abs(h[i]-h[j])+dp[j])
    
  dp[i] = dpx


print(dp[-1])

Fixed submission:
def main():
    N,K = map(int,input().split())
    h = list(map(int,input().split()))
    dp = [0]*N
    for i in range(1,N):
        dp[i]= min(abs(h[i]-h[j])+dp[j] for j in range(max(0,i-K),i))
    print(dp[-1])
main()

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
h = list(map(int,input().split()))
dp = [0 for a in range(N)]

for i in range(1,N):
  dpa = []
  for j in range(max(0,i-K),i):
      dpx = abs(h[i]-h[j])+dp[j]
      dpa.append(dpx)
  dp[i] = min(dpa)


print(dp[-1])

Fixed submission:
def main():
    N,K = map(int,input().split())
    h = list(map(int,input().split()))
    dp = [0]*N
    for i in range(1,N):
        dp[i]= min(abs(h[i]-h[j])+dp[j] for j in range(max(0,i-K),i))
    print(dp[-1])
main()

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
h = list(map(int,input().split()))
dp = [0 for i in range(N)]

for j in range(1,N):
    a = []
    for k in range(max(0,j-K),j):
        a.append(abs(h[j]-h[k])+dp[k])
    dp[j] = min(a)

print(dp[-1])





Fixed submission:
def main():
    N,K = map(int,input().split())
    h = list(map(int,input().split()))
    dp = [0]*N
    for i in range(1,N):
        dp[i]= min(abs(h[i]-h[j])+dp[j] for j in range(max(0,i-K),i))
    print(dp[-1])
main()

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
h = list(map(int,input().split()))
dp = [0 for i in range(N)]

for j in range(1,N):
    a = float('inf')
    for k in range(max(0,j-K),j):
        a = min(a, abs(h[j]-h[k])+dp[k])
    dp[j] = a

print(dp[-1])

Fixed submission:
def main():
    N,K = map(int,input().split())
    h = list(map(int,input().split()))
    dp = [0]*N
    for i in range(1,N):
        dp[i]= min(abs(h[i]-h[j])+dp[j] for j in range(max(0,i-K),i))
    print(dp[-1])
main()

Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
h = list(map(int,input().split()))
dp = [0]

for i in range(1,K):
  for j in range(0,i):
    dpa = 10**4+1
    if dpa > abs(h[i]-h[i-j-1])+dp[i-j-1]:
      dpa = abs(h[i]-h[i-j-1])+dp[i-j-1]
  dp.append(dpa)


for k in range(K,N):
  for l in range(K):
    dpa = 10**4+1
    if dpa > abs(h[k]-h[k-l-1])+dp[k-l-1]:
      dpa = abs(h[k]-h[k-l-1])+dp[k-l-1]
  dp.append(dpa)

print(dp[-1])

Fixed submission:
def main():
    N,K = map(int,input().split())
    h = list(map(int,input().split()))
    dp = [0]*N
    for i in range(1,N):
        dp[i]= min(abs(h[i]-h[j])+dp[j] for j in range(max(0,i-K),i))
    print(dp[-1])
main()

Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
h = list(map(int,input().split()))
dp = [0]
dpx = 10**4+1
for i in range(1,K+1):
  for j in range(1,i):
      dpx = min(dpx, abs(h[i]-h[i-j])+dp[i-j])
  dp.append(dpx)
for k in range(K+1,N+1):
  for l in range(1,K+1):
    dpx = min(dpx, abs(h[k]-h[k-l])+dp[k-l])
  dp.append(dpx)
print(dp[-1])

Fixed submission:
def main():
    N,K = map(int,input().split())
    h = list(map(int,input().split()))
    dp = [0]*N
    for i in range(1,N):
        dp[i]= min(abs(h[i]-h[j])+dp[j] for j in range(max(0,i-K),i))
    print(dp[-1])
main()

Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
h = list(map(int,input().split()))
dp = [0]
dpx = 10**4+1
for i in range(1,K+1):
  for j in range(1,i):
      dpx = min(dpx, abs(h[i]-h[i-j])+dp[i-j])
  dp.append(dpx)
for k in range(K+1,N+1):
  for l in range(1,K+1):
    dpx = min(dpx, abs(h[i]-h[i-j])+dp[i-j])
  dp.append(dpx)
print(dp[-1])

Fixed submission:
def main():
    N,K = map(int,input().split())
    h = list(map(int,input().split()))
    dp = [0]*N
    for i in range(1,N):
        dp[i]= min(abs(h[i]-h[j])+dp[j] for j in range(max(0,i-K),i))
    print(dp[-1])
main()

Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
h = list(map(int,input().split()))
dp = [0]
dpx = 10**4+1
for i in range(1,N):
  for j in range(i):
      dpx = min(dpx, abs(h[i]-h[i-j])+dp[i-j])
  dp.append(dpx)
print(dp[-1])

Fixed submission:
def main():
    N,K = map(int,input().split())
    h = list(map(int,input().split()))
    dp = [0]*N
    for i in range(1,N):
        dp[i]= min(abs(h[i]-h[j])+dp[j] for j in range(max(0,i-K),i))
    print(dp[-1])
main()

Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
h = list(map(int,input().split()))
dp = [0]
dpx = 10**4+1
for i in range(1,N):
  for j in range(1,K+1):
      dpx = min(dpx, abs(h[i]-h[N-j])+dp[N-j])
  dp.append(dpx)
print(dp[-1])

Fixed submission:
def main():
    N,K = map(int,input().split())
    h = list(map(int,input().split()))
    dp = [0]*N
    for i in range(1,N):
        dp[i]= min(abs(h[i]-h[j])+dp[j] for j in range(max(0,i-K),i))
    print(dp[-1])
main()

Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
h = list(map(int,input().split()))
dp = [0]
dpx = 10**4+1
for i in range(1,K):
  for j in range(0,i):
      dpx = min(dpx, abs(h[i]-h[j])+dp[j])
  dp.append(dpx)
print(dp[-1])

Fixed submission:
def main():
    N,K = map(int,input().split())
    h = list(map(int,input().split()))
    dp = [0]*N
    for i in range(1,N):
        dp[i]= min(abs(h[i]-h[j])+dp[j] for j in range(max(0,i-K),i))
    print(dp[-1])
main()

Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
h = list(map(int,input().split()))
dp = [0]
dpx = 10**4+1
for i in range(1,K+1):
  for j in range(0,i):
      dpx = min(dpx, abs(h[i]-h[j])+dp[j])
  dp.append(dpx)
print(dp[-1])

Fixed submission:
def main():
    N,K = map(int,input().split())
    h = list(map(int,input().split()))
    dp = [0]*N
    for i in range(1,N):
        dp[i]= min(abs(h[i]-h[j])+dp[j] for j in range(max(0,i-K),i))
    print(dp[-1])
main()

Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
h = list(map(int,input().split()))
dp = [0]
dpx = 10**4+1
for i in range(1,K+1):
  for j in range(0,i):
      dpx = min(dpx, abs(h[i]-h[j]))
  dp.append(dpx)
print(dp[-1])

Fixed submission:
def main():
    N,K = map(int,input().split())
    h = list(map(int,input().split()))
    dp = [0]*N
    for i in range(1,N):
        dp[i]= min(abs(h[i]-h[j])+dp[j] for j in range(max(0,i-K),i))
    print(dp[-1])
main()