Buggy python submission (verdict: Runtime Error):
if __name__ == '__main__':
    n = stdin.readline()
    n, K = n.split(' ')
    n = int(n)
    K = int(K)
    arr = stdin.readline()
    arr = [int(a) for a in arr.split(' ')]
    dp = [float('inf')]*n
    dp[0] = 0
    for i in range(n):
        for k in range(1, K+1):
            if i - k < 0:
                break
            dp[i] = min(dp[i], dp[i-k]+abs(arr[i]-arr[i-k]))
    print(dp[-1])

Fixed submission:
def woo(x, y):
    res = [0]*x
    z = list(map(int, input().split()))
    for i in range(1, x):
        res[i] = min(abs(z[i] - z[j]) + res[j] for j in range(max(0, i - y), i))
    return res

if __name__ == '__main__':
    x, y = map(int, input().split())
    r = woo(x, y)
    f = len(r)-1
    print(r[f])

Buggy python submission (verdict: Runtime Error):
n, k = [int(item) for item in linha1.split()]
linha2 = input()
alturas = [int(item) for item in linha2.split()]
matriz = [[abs(alturas[0] - alturas[1])]]
if n > 2:
    for i in range(1,n-1):
        matriz.append([])
        for j in range(0,min(k, i+1, n-1)):
            if i-j == 0:
                custo_atual = abs(alturas[i+1] - alturas[0])
            else:
                custo_atual = abs(alturas[i+1] - alturas[i-j]) + min(matriz[i-j-1])
            matriz[i].append(custo_atual)
print(min(matriz[-1]))

Fixed submission:
def woo(x, y):
    res = [0]*x
    z = list(map(int, input().split()))
    for i in range(1, x):
        res[i] = min(abs(z[i] - z[j]) + res[j] for j in range(max(0, i - y), i))
    return res

if __name__ == '__main__':
    x, y = map(int, input().split())
    r = woo(x, y)
    f = len(r)-1
    print(r[f])

Buggy python submission (verdict: Time Limit Exceeded):
# Problem A - Frog 2 - Algoritmos e Grafos - MATA52
def frog2(n, h, k_max):
    global stones
    stones[0] = 0
    stones[1] = abs(h[1] - h[0])
    for i in range(2, n):
        for j in range(1, min(i, k_max) + 1):
            w1 = stones[i]
            w2 = abs(h[i - j] - h[i])
            stones[i] = min(w1, stones[i - j] + w2)
    return stones[n - 1]

n, k_max = list(map(int, input().split()))
h = list(map(int, input().split()))

stones = [float("inf")] * n
print(frog2(n, h, k_max))

Fixed submission:
def woo(x, y):
    res = [0]*x
    z = list(map(int, input().split()))
    for i in range(1, x):
        res[i] = min(abs(z[i] - z[j]) + res[j] for j in range(max(0, i - y), i))
    return res

if __name__ == '__main__':
    x, y = map(int, input().split())
    r = woo(x, y)
    f = len(r)-1
    print(r[f])

Buggy python submission (verdict: Time Limit Exceeded):
# Problem A - Frog 2 - Algoritmos e Grafos - MATA52
def frog2(n, h, k_max):
    global stones
    stones[0] = 0
    stones[1] = 0
    for i in range(1, n):
        for j in range(1, k_max):
            if i + j < n:
                w1 = stones[i + j]
                w2 = abs(h[i + j] - h[i])
                stones[i + j] = min(w1, stones[i] + w2)
    return stones[-1]

inf = input()
inf = inf.split()
n = int(inf[0]) + 1
k_max = int(inf[1]) + 1
h = [int(x) for x in input().split()]
h = [0] + h

stones = [2222222222] * n
print(frog2(n, h, k_max))

Fixed submission:
def woo(x, y):
    res = [0]*x
    z = list(map(int, input().split()))
    for i in range(1, x):
        res[i] = min(abs(z[i] - z[j]) + res[j] for j in range(max(0, i - y), i))
    return res

if __name__ == '__main__':
    x, y = map(int, input().split())
    r = woo(x, y)
    f = len(r)-1
    print(r[f])