Buggy python submission (verdict: Time Limit Exceeded):
n, k = [int(_) for _ in input().split()]
h = [int(_) for _ in input().split()]
inf = 1e9
dp = [inf] * n
dp[0] = 0
for i in range(1, n):
    cnt = 1
    while cnt <= k and i - cnt > -1:
        dp[i] = min(dp[i], dp[i - cnt] + abs(h[i] - h[i - cnt]))
        cnt += 1
print(dp[-1])

Fixed submission:
n, k = [int(_) for _ in input().split()]
h = [int(_) for _ in input().split()]
inf = 1e9
dp = [inf] * n
dp[0] = 0
for i in range(1, n):
    cnt = 1
    while cnt <= k and i - cnt > -1:
        dp[i] = min(dp[i], dp[i - cnt] + abs(h[i] - h[i - cnt]))
        cnt += 1
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
def compute(n, k, h):
    inf = 1e9
    if n == 1:
        return 0
    dp = [inf] * n
    dp[0] = 0
    for i in range(1, n):
        cnt = 1
        while cnt <= k and i - cnt > -1:
            dp[i] = min(dp[i], dp[i - cnt] + abs(h[i] - h[i - cnt]))

    return dp[-1]


if __name__ == '__main__':
    N, K = map(int, input().split())
    h = list(map(int, input().split()))
    print(compute(N, K, h))


Fixed submission:
n, k = [int(_) for _ in input().split()]
h = [int(_) for _ in input().split()]
inf = 1e9
dp = [inf] * n
dp[0] = 0
for i in range(1, n):
    cnt = 1
    while cnt <= k and i - cnt > -1:
        dp[i] = min(dp[i], dp[i - cnt] + abs(h[i] - h[i - cnt]))
        cnt += 1
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
def compute(n, k, h):
    inf = 1e9
    if n == 1:
        return 0
    dp = [inf] * n
    dp[0] = 0
    for i in range(1, n):
        cnt = 1
        while cnt <= k and i - cnt > -1:
            dp[i] = min(dp[i], dp[i - cnt] + abs(h[i] - h[i - cnt]))
            cnt += 1
    return dp[-1]


if __name__ == '__main__':
    N, K = map(int, input().split())
    h = list(map(int, input().split()))
    print(compute(N, K, h))

Fixed submission:
n, k = [int(_) for _ in input().split()]
h = [int(_) for _ in input().split()]
inf = 1e9
dp = [inf] * n
dp[0] = 0
for i in range(1, n):
    cnt = 1
    while cnt <= k and i - cnt > -1:
        dp[i] = min(dp[i], dp[i - cnt] + abs(h[i] - h[i - cnt]))
        cnt += 1
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
def compute(n, k, h):
    inf = 1e9
    if n == 1:
        return 0
    dp = [inf] * n
    dp[0] = 0
    for i in range(1, n):
        cnt = 1
        while cnt <= k and i - cnt > -1:
            dp[i] = min(dp[i], dp[i - cnt] + abs(h[i] - h[i - cnt]))
            cnt += 1
    return dp[-1]


if __name__ == '__main__':
    N, K = [int(_) for _ in input().split()]
    h = [int(_) for _ in input().split()]
    print(compute(N, K, h))


Fixed submission:
n, k = [int(_) for _ in input().split()]
h = [int(_) for _ in input().split()]
inf = 1e9
dp = [inf] * n
dp[0] = 0
for i in range(1, n):
    cnt = 1
    while cnt <= k and i - cnt > -1:
        dp[i] = min(dp[i], dp[i - cnt] + abs(h[i] - h[i - cnt]))
        cnt += 1
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
def compute(n, k, h):
    inf = 1e9
    if n == 1:
        return 0
    dp = [inf] * n
    dp[0] = 0
    for i in range(1, n):
        cnt = 1
        while cnt <= k and i - cnt > -1:
            dp[i] = min(dp[i], dp[i - cnt] + abs(h[i] - h[i - cnt]))
            cnt += 1
    return dp[-1]


if __name__ == '__main__':
    N, K = [int(_) for _ in input().split()]
    h = [int(_) for _ in input().split()]
    print(compute(N, K, h))


Fixed submission:
n, k = [int(_) for _ in input().split()]
h = [int(_) for _ in input().split()]
inf = 1e9
dp = [inf] * n
dp[0] = 0
for i in range(1, n):
    cnt = 1
    while cnt <= k and i - cnt > -1:
        dp[i] = min(dp[i], dp[i - cnt] + abs(h[i] - h[i - cnt]))
        cnt += 1
print(dp[-1])