Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = list(map(int, input().split()))
a = [0] * n
a[0] = 0
for i in range(1, n):
    a[i] = min([a[j] + abs(h[i] - h[j]) for j in range(max(0, i - k), i)])
print(a[-1])


Fixed submission:
def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    a = [0] * n
    a[0] = 0
    for i in range(1, n):
        a[i] = min([a[j] + abs(h[i] - h[j]) for j in range(max(0, i - k), i)])
    print(a[-1])
 
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
c=list(map(int,input().split()))
dp=[0]*n
dp[0]=0
for i in range(1,n):
    dp[i]=min([dp[j]+abs(c[i]-c[j]) for j in range(max(0,i-k),i)])
print(dp[-1])

Fixed submission:
def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    a = [0] * n
    a[0] = 0
    for i in range(1, n):
        a[i] = min([a[j] + abs(h[i] - h[j]) for j in range(max(0, i - k), i)])
    print(a[-1])
 
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
c=list(map(int,input().split()))
dp=[0 for i in range(n)]
for i in range(1,n):
    dp[i]=min([dp[j]+abs(c[i]-c[j]) for j in range(max(0,i-k),i)])
print(dp[-1])

Fixed submission:
def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    a = [0] * n
    a[0] = 0
    for i in range(1, n):
        a[i] = min([a[j] + abs(h[i] - h[j]) for j in range(max(0, i - k), i)])
    print(a[-1])
 
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
c=list(map(int,input().split()))
dp=[0]
for i in range(1,n):
    dp.append(min([dp[j]+abs(c[i]-c[j]) for j in range(max(0,i-k),i)]))
print(dp[-1])

Fixed submission:
def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    a = [0] * n
    a[0] = 0
    for i in range(1, n):
        a[i] = min([a[j] + abs(h[i] - h[j]) for j in range(max(0, i - k), i)])
    print(a[-1])
 
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
c=list(map(int,input().split()))
dp=[0]
for i in range(1,n):
    m=min([dp[j]+abs(c[i]-c[j]) for j in range(max(0,i-k),i)])
    dp.append(m)
print(dp[-1])


Fixed submission:
def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    a = [0] * n
    a[0] = 0
    for i in range(1, n):
        a[i] = min([a[j] + abs(h[i] - h[j]) for j in range(max(0, i - k), i)])
    print(a[-1])
 
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
c=list(map(int,input().split()))
dp=[0]
if n>1:
    dp.append(abs(c[1]-c[0]))
    for i in range(2,n):
        m=10**9+1
        for j in range(1,min(k+1,n)):
            m=min(m,dp[max(0,i-j)]+abs(c[i]-c[max(0,i-j)]))
        dp.append(m)
print(dp[-1])


Fixed submission:
def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    a = [0] * n
    a[0] = 0
    for i in range(1, n):
        a[i] = min([a[j] + abs(h[i] - h[j]) for j in range(max(0, i - k), i)])
    print(a[-1])
 
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
c=list(map(int,input().split()))
dp=[0]
if n>1:
    dp.append(abs(c[1]-c[0]))
    for i in range(2,n):
        m=10**9+1
        for j in range(1,k+1):
            if j<n:
                m=min(m,dp[max(0,i-j)]+abs(c[i]-c[max(0,i-j)]))
        dp.append(m)
print(dp[-1])


Fixed submission:
def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    a = [0] * n
    a[0] = 0
    for i in range(1, n):
        a[i] = min([a[j] + abs(h[i] - h[j]) for j in range(max(0, i - k), i)])
    print(a[-1])
 
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
c=list(map(int,input().split()))
dp=[0]
if n>1:
    dp.append(abs(c[1]-c[0]))
    for i in range(2,n):
        m=10**9+1
        for j in range(1,k+1):
            m=min(m,dp[max(n-k-1,0)]+abs(c[i]-c[max(0,i-j)]))
        dp.append(m)
print(dp[-1])


Fixed submission:
def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    a = [0] * n
    a[0] = 0
    for i in range(1, n):
        a[i] = min([a[j] + abs(h[i] - h[j]) for j in range(max(0, i - k), i)])
    print(a[-1])
 
if __name__ == '__main__':
    main()