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

Fixed submission:
N, K = map(int, input().split())
h = [int(i) for i in input().split()]
INF = 10**9

c = [INF] * N
c[0] = 0

for i in range(N):
  tmp = []
  for j in range(1, min(K, i)+1):
    c[i] = min(c[i-j] + abs(h[i] - h[i-j]), c[i])
print(c[-1])

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


Fixed submission:
N, K = map(int, input().split())
h = [int(i) for i in input().split()]
INF = 10**9

c = [INF] * N
c[0] = 0

for i in range(N):
  tmp = []
  for j in range(1, min(K, i)+1):
    c[i] = min(c[i-j] + abs(h[i] - h[i-j]), c[i])
print(c[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = [int(i) for i in input().split()]
INF = 10**9

c = [INF] * N
c[0] = 0

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

Fixed submission:
N, K = map(int, input().split())
h = [int(i) for i in input().split()]
INF = 10**9

c = [INF] * N
c[0] = 0

for i in range(N):
  tmp = []
  for j in range(1, min(K, i)+1):
    c[i] = min(c[i-j] + abs(h[i] - h[i-j]), c[i])
print(c[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = [int(i) for i in input().split()]
INF = 10**9

c = [INF] * N
c[0] = 0

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

Fixed submission:
N, K = map(int, input().split())
h = [int(i) for i in input().split()]
INF = 10**9

c = [INF] * N
c[0] = 0

for i in range(N):
  tmp = []
  for j in range(1, min(K, i)+1):
    c[i] = min(c[i-j] + abs(h[i] - h[i-j]), c[i])
print(c[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = [int(i) for i in input().split()]
INF = 10**9

c = [INF] * N
c[0] = 0

for i in range(N):
  tmp = []
  for j in range(1, min(K, i)+1):
    c[i] = min(c[i-j] + abs(h[i] - h[i-j]), c[i])
print(c[-1])

Fixed submission:
N, K = map(int, input().split())
h = [int(i) for i in input().split()]
INF = 10**9

c = [INF] * N
c[0] = 0

for i in range(N):
  tmp = []
  for j in range(1, min(K, i)+1):
    c[i] = min(c[i-j] + abs(h[i] - h[i-j]), c[i])
print(c[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = list(map(int, input().split()))
INF = 10**9+10

c = [INF] * N
c[0] = 0

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

Fixed submission:
N, K = map(int, input().split())
h = [int(i) for i in input().split()]
INF = 10**9

c = [INF] * N
c[0] = 0

for i in range(N):
  tmp = []
  for j in range(1, min(K, i)+1):
    c[i] = min(c[i-j] + abs(h[i] - h[i-j]), c[i])
print(c[-1])

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

dp = [10**9+10] * N
dp[0] = 0
dp[1] = abs(h[1]-h[0])

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

Fixed submission:
N, K = map(int, input().split())
h = [int(i) for i in input().split()]
INF = 10**9

c = [INF] * N
c[0] = 0

for i in range(N):
  tmp = []
  for j in range(1, min(K, i)+1):
    c[i] = min(c[i-j] + abs(h[i] - h[i-j]), c[i])
print(c[-1])

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

dp = [10**9+10] * N
dp[0] = 0
dp[1] = abs(h[1]-h[0])

for i in range(2, N):
  dp[i] = 10**9+10
  for j in range(1,min(i+1,K+1)):
    tmp = dp[i-j]+abs(h[i]-h[i-j])
    dp[i] = min(dp[i], tmp)
print(dp[N-1])

Fixed submission:
N, K = map(int, input().split())
h = [int(i) for i in input().split()]
INF = 10**9

c = [INF] * N
c[0] = 0

for i in range(N):
  tmp = []
  for j in range(1, min(K, i)+1):
    c[i] = min(c[i-j] + abs(h[i] - h[i-j]), c[i])
print(c[-1])

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

dp = [10**9+10] * N
dp[0] = 0
dp[1] = abs(h[1]-h[0])

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

Fixed submission:
N, K = map(int, input().split())
h = [int(i) for i in input().split()]
INF = 10**9

c = [INF] * N
c[0] = 0

for i in range(N):
  tmp = []
  for j in range(1, min(K, i)+1):
    c[i] = min(c[i-j] + abs(h[i] - h[i-j]), c[i])
print(c[-1])