Buggy python submission (verdict: Time Limit Exceeded):
N, K = [int(i) for i in input().split()]
H = [int(i) for i in input().split()]
dp = [float('inf')] * N
dp[0] = 0

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

print(dp[N - 1])


Fixed submission:
n, k = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]

def frog(n, k, h):
    d = [float('inf')] * n
    d[0] = 0

    for i in range(1, n):
        d[i] = min(
            d[j] + abs(h[i] - h[j]) for j in range(max(i - k, 0), i)
        )
    return d[n - 1]


print(frog(n, k, h))

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

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

print(dp[N - 1])


Fixed submission:
n, k = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]

def frog(n, k, h):
    d = [float('inf')] * n
    d[0] = 0

    for i in range(1, n):
        d[i] = min(
            d[j] + abs(h[i] - h[j]) for j in range(max(i - k, 0), i)
        )
    return d[n - 1]


print(frog(n, k, h))

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

for i in range(N - 1):
  for k in range(1, K + 1):
    if i + k >= N: break
    dp[i + k] = min(dp[i + k], dp[i] + abs(H[i] - H[i + k]))

print(dp[N - 1])


Fixed submission:
n, k = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]

def frog(n, k, h):
    d = [float('inf')] * n
    d[0] = 0

    for i in range(1, n):
        d[i] = min(
            d[j] + abs(h[i] - h[j]) for j in range(max(i - k, 0), i)
        )
    return d[n - 1]


print(frog(n, k, h))

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

for i in range(N - 1):
  for k in range(1, K + 1):
    if i + k >= N: break
    dp[i + k] = min(dp[i + k], dp[i] + abs(H[i] - H[i + k]))

print(dp[-1])


Fixed submission:
n, k = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]

def frog(n, k, h):
    d = [float('inf')] * n
    d[0] = 0

    for i in range(1, n):
        d[i] = min(
            d[j] + abs(h[i] - h[j]) for j in range(max(i - k, 0), i)
        )
    return d[n - 1]


print(frog(n, k, h))

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

for i in range(N - 1):
  for k in range(1, K + 1):
    if i + k < N:
      dp[i + k] = min(dp[i + k], dp[i] + abs(H[i] - H[i + k]))

print(dp[-1])


Fixed submission:
n, k = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]

def frog(n, k, h):
    d = [float('inf')] * n
    d[0] = 0

    for i in range(1, n):
        d[i] = min(
            d[j] + abs(h[i] - h[j]) for j in range(max(i - k, 0), i)
        )
    return d[n - 1]


print(frog(n, k, h))

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

for i in range(N):
  for k in range(1, K + 1):
    if i + k < N:
      dp[i + k] = min(dp[i + k], dp[i] + abs(H[i] - H[i + k]))

print(dp[-1])


Fixed submission:
n, k = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]

def frog(n, k, h):
    d = [float('inf')] * n
    d[0] = 0

    for i in range(1, n):
        d[i] = min(
            d[j] + abs(h[i] - h[j]) for j in range(max(i - k, 0), i)
        )
    return d[n - 1]


print(frog(n, k, h))