Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n, k = map(int, input().split())
    stones = tuple(map(int, input().split()))
    inf = 10**9
    dp = [inf]*n
    dp[0] = 0
    for i in range(n-1):
        for t in range(1, k+1):
            step = i+t
            if step < n:
                v = dp[i]+abs(stones[i]-stones[step])
                if v < dp[step]:
                    dp[step] = v
    print(dp[-1])


if __name__ == '__main__':    
    main()


Fixed submission:
def main():
    n, k = map(int, input().split())
    stones = tuple(map(int, input().split()))
    inf = 10**9
    dp = [inf]*n
    dp[0] = 0
    for i in range(n):
        for t in range(1, k+1):
            step = i+t
            if step < n:
                v = dp[i]+abs(stones[i]-stones[step])
                if v < dp[step]:
                    dp[step] = v
    print(dp[-1])


if __name__ == '__main__':    
    main()

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = tuple(map(int, input().split()))
d = dict()
for i in range(n):
    d[i] = h[i]

inf = 10**9
dp = [inf]*n
dp[0] = 0
for i in range(n):
    for j in range(1, k+1):
        step = i+j
        if step < n:
            dp[step] = min(dp[step], dp[i]+abs(d[step]-d[i]))
print(dp[-1])


Fixed submission:
def main():
    n, k = map(int, input().split())
    stones = tuple(map(int, input().split()))
    inf = 10**9
    dp = [inf]*n
    dp[0] = 0
    for i in range(n):
        for t in range(1, k+1):
            step = i+t
            if step < n:
                v = dp[i]+abs(stones[i]-stones[step])
                if v < dp[step]:
                    dp[step] = v
    print(dp[-1])


if __name__ == '__main__':    
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n, k = map(int, input().split())
    h = tuple(map(int, input().split()))
    inf = 10**9
    dp = [inf]*n
    dp[0] = 0
    for i in range(n):
        for j in range(1, k+1):
            step = i+j
            if step < n:
                dp[step] = min(dp[step], dp[i]+abs(h[step]-h[i]))
    print(dp[-1])

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    n, k = map(int, input().split())
    stones = tuple(map(int, input().split()))
    inf = 10**9
    dp = [inf]*n
    dp[0] = 0
    for i in range(n):
        for t in range(1, k+1):
            step = i+t
            if step < n:
                v = dp[i]+abs(stones[i]-stones[step])
                if v < dp[step]:
                    dp[step] = v
    print(dp[-1])


if __name__ == '__main__':    
    main()

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


Fixed submission:
def main():
    n, k = map(int, input().split())
    stones = tuple(map(int, input().split()))
    inf = 10**9
    dp = [inf]*n
    dp[0] = 0
    for i in range(n):
        for t in range(1, k+1):
            step = i+t
            if step < n:
                v = dp[i]+abs(stones[i]-stones[step])
                if v < dp[step]:
                    dp[step] = v
    print(dp[-1])


if __name__ == '__main__':    
    main()

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = tuple(map(int, input().split()))
inf = 10**9
dp = [inf]*n
dp[0] = 0
for i in range(n):
    for j in range(1, k+1):
        step = i+j
        if step >= n:
            break
        dp[step] = min(dp[step], dp[i]+abs(h[step]-h[i]))
print(dp[-1])


Fixed submission:
def main():
    n, k = map(int, input().split())
    stones = tuple(map(int, input().split()))
    inf = 10**9
    dp = [inf]*n
    dp[0] = 0
    for i in range(n):
        for t in range(1, k+1):
            step = i+t
            if step < n:
                v = dp[i]+abs(stones[i]-stones[step])
                if v < dp[step]:
                    dp[step] = v
    print(dp[-1])


if __name__ == '__main__':    
    main()

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):
    for j in range(1, k+1):
        step = i+j
        if step >= n:
            break
        dp[step] = min(dp[step], dp[i]+abs(h[step]-h[i]))
print(dp[-1])


Fixed submission:
def main():
    n, k = map(int, input().split())
    stones = tuple(map(int, input().split()))
    inf = 10**9
    dp = [inf]*n
    dp[0] = 0
    for i in range(n):
        for t in range(1, k+1):
            step = i+t
            if step < n:
                v = dp[i]+abs(stones[i]-stones[step])
                if v < dp[step]:
                    dp[step] = v
    print(dp[-1])


if __name__ == '__main__':    
    main()

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):
    for j in range(1, k+1):
        if i+j >= n:
            break
        dp[i+j] = min(dp[i+j], dp[i]+abs(h[i+j]-h[i]))
print(dp[-1])


Fixed submission:
def main():
    n, k = map(int, input().split())
    stones = tuple(map(int, input().split()))
    inf = 10**9
    dp = [inf]*n
    dp[0] = 0
    for i in range(n):
        for t in range(1, k+1):
            step = i+t
            if step < n:
                v = dp[i]+abs(stones[i]-stones[step])
                if v < dp[step]:
                    dp[step] = v
    print(dp[-1])


if __name__ == '__main__':    
    main()