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 II(): return int(input())
#def LI(): return [int(i) for i in input().split()]

#N, K = LI()
#H = LI()

#cost = [0] * N
#cost[0] = 0
#for n in range(1, N):
#  cost[n] = min([ cost[n-k]+abs(H[n-k]-H[n]) for k in range(1, min(n+1, K+1)) ])

#print(cost[-1])

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):
import time
N, K = list(map(int, input().split()))
H = list(map(int, input().split()))

cost = [0] * N
cost[0] = 0
for n in range(1, N):
  # t = time.time()
  cost[n] = min([ cost[n-k]+abs(H[n-k]-H[n]) for k in range(1, min(n+1, K+1)) ])
  # print(time.time()-t)
print(cost[-1])

Fixed submission:
#  def II(): return int(input())
#def LI(): return [int(i) for i in input().split()]

#N, K = LI()
#H = LI()

#cost = [0] * N
#cost[0] = 0
#for n in range(1, N):
#  cost[n] = min([ cost[n-k]+abs(H[n-k]-H[n]) for k in range(1, min(n+1, K+1)) ])

#print(cost[-1])

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 = list(map(int, input().split()))
H = list(map(int, input().split()))

cost = [0] * N
cost[0] = 0
for n in range(1, N):
  cost[n] = min([ cost[n-k]+abs(H[n-k]-H[n]) for k in range(1, min(n+1, K+1)) ])

print(cost[-1])

#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()

Fixed submission:
#  def II(): return int(input())
#def LI(): return [int(i) for i in input().split()]

#N, K = LI()
#H = LI()

#cost = [0] * N
#cost[0] = 0
#for n in range(1, N):
#  cost[n] = min([ cost[n-k]+abs(H[n-k]-H[n]) for k in range(1, min(n+1, K+1)) ])

#print(cost[-1])

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 = list(map(int, input().split()))
H = map(int, input().split())

cost = [0] * N
cost[0] = 0
for n in range(1, N):
  cost[n] = min([ cost[n-k]+abs(H[n-k]-H[n]) for k in range(1, min(n+1, K+1)) ])

print(cost[-1])

#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()

Fixed submission:
#  def II(): return int(input())
#def LI(): return [int(i) for i in input().split()]

#N, K = LI()
#H = LI()

#cost = [0] * N
#cost[0] = 0
#for n in range(1, N):
#  cost[n] = min([ cost[n-k]+abs(H[n-k]-H[n]) for k in range(1, min(n+1, K+1)) ])

#print(cost[-1])

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):
def II(): return int(input())
def LI(): return [int(i) for i in input().split()]

N, K = map(int, input().split())
H = map(int, input().split())

cost = [0] * N
cost[0] = 0
for n in range(1, N):
  cost[n] = min([ cost[n-k]+abs(H[n-k]-H[n]) for k in range(1, min(n+1, K+1)) ])

print(cost[-1])

#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()

Fixed submission:
#  def II(): return int(input())
#def LI(): return [int(i) for i in input().split()]

#N, K = LI()
#H = LI()

#cost = [0] * N
#cost[0] = 0
#for n in range(1, N):
#  cost[n] = min([ cost[n-k]+abs(H[n-k]-H[n]) for k in range(1, min(n+1, K+1)) ])

#print(cost[-1])

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):
#  def II(): return int(input())
#def LI(): return [int(i) for i in input().split()]

#N, K = LI()
#H = LI()

#cost = [0] * N
#cost[0] = 0
#for n in range(1, N):
#  cost[n] = min([ cost[n-k]+abs(H[n-k]-H[n]) for k in range(1, min(n+1, K+1)) ])

#print(cost[-1])

def II(): return int(input())
def LI(): return [int(i) for i in input().split()]
 
N, K = LI()
H = LI()
 
cost = [0] * N
cost[0] = 0
for n in range(1, N):
  MIN = min(
  	[ cost[n-k]+abs(H[n-k]-H[n]) for k in range(1, min(n+1, K+1)) ]
  )
  cost[n] = MIN
 
print(cost[-1])

Fixed submission:
#  def II(): return int(input())
#def LI(): return [int(i) for i in input().split()]

#N, K = LI()
#H = LI()

#cost = [0] * N
#cost[0] = 0
#for n in range(1, N):
#  cost[n] = min([ cost[n-k]+abs(H[n-k]-H[n]) for k in range(1, min(n+1, K+1)) ])

#print(cost[-1])

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):
def II(): return int(input())
def LI(): return [int(i) for i in input().split()]

N, K = LI()
H = LI()

cost = [0] * N
cost[0] = 0
for n in range(1, N):
  cost[n] = min([ cost[n-k]+abs(H[n-k]-H[n]) for k in range(1, min(n+1, K+1)) ])

print(cost[-1])

Fixed submission:
#  def II(): return int(input())
#def LI(): return [int(i) for i in input().split()]

#N, K = LI()
#H = LI()

#cost = [0] * N
#cost[0] = 0
#for n in range(1, N):
#  cost[n] = min([ cost[n-k]+abs(H[n-k]-H[n]) for k in range(1, min(n+1, K+1)) ])

#print(cost[-1])

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):
def II(): return int(input())
def LI(): return [int(i) for i in input().split()]

N, K = LI()
H = LI()

cost = [0] * N
cost[0] = 0
for n in range(1, N):
  MIN = min(
  	[ cost[n-k]+abs(H[n-k]-H[n]) for k in range(1, min(n+1, K+1)) ]
  )
  cost[n] = MIN

print(cost[-1])

Fixed submission:
#  def II(): return int(input())
#def LI(): return [int(i) for i in input().split()]

#N, K = LI()
#H = LI()

#cost = [0] * N
#cost[0] = 0
#for n in range(1, N):
#  cost[n] = min([ cost[n-k]+abs(H[n-k]-H[n]) for k in range(1, min(n+1, K+1)) ])

#print(cost[-1])

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):
def II(): return int(input())
def LI(): return [int(i) for i in input().split()]

N, K = LI()
H = LI()

cost = [0] * N
cost[0] = 0
for n in range(1, N):
  MIN = min(
  	[ cost[n-k]+abs(H[n-k]-H[n]) for k in range(1, K+1) if n-k>=0 ]
  )
  cost[n] = MIN

print(cost[-1])

Fixed submission:
#  def II(): return int(input())
#def LI(): return [int(i) for i in input().split()]

#N, K = LI()
#H = LI()

#cost = [0] * N
#cost[0] = 0
#for n in range(1, N):
#  cost[n] = min([ cost[n-k]+abs(H[n-k]-H[n]) for k in range(1, min(n+1, K+1)) ])

#print(cost[-1])

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):
def II(): return int(input())
def LI(): return [int(i) for i in input().split()]

N, K = LI()
H = LI()

cost = [0] * n
cost[0] = 0
for n in range(1, N):
  MIN = min(
  	[ cost[n-k]+abs(H[n-k]-H[n]) for k in range(1, K+1) if n-k>=0 ]
  )
  cost[n] = MIN

print(cost[-1])

Fixed submission:
#  def II(): return int(input())
#def LI(): return [int(i) for i in input().split()]

#N, K = LI()
#H = LI()

#cost = [0] * N
#cost[0] = 0
#for n in range(1, N):
#  cost[n] = min([ cost[n-k]+abs(H[n-k]-H[n]) for k in range(1, min(n+1, K+1)) ])

#print(cost[-1])

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):
def II(): return int(input())
def LI(): return [int(i) for i in input().split()]

N, K = LI()
H = LI()

cost = list()
cost.append(0)
for n in range(1, N):
  MIN = min(
  	[ cost[n-k]+abs(H[n-k]-H[n]) for k in range(1, K+1) if n-k>=0 ]
  )
  cost.append(MIN)

print(cost[-1])

Fixed submission:
#  def II(): return int(input())
#def LI(): return [int(i) for i in input().split()]

#N, K = LI()
#H = LI()

#cost = [0] * N
#cost[0] = 0
#for n in range(1, N):
#  cost[n] = min([ cost[n-k]+abs(H[n-k]-H[n]) for k in range(1, min(n+1, K+1)) ])

#print(cost[-1])

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):
def II(): return int(input())
def LI(): return [int(i) for i in input().split()]

N, K = LI()
H = LI()

cost = list()
cost.append(0)
for n in range(1, N):
  MIN = min(
  	[ cost[n-k]+abs(H[n-k]-H[n]) for k in range(1, K+1) if n-k>=0 ]
  )
  cost.append(MIN)

print(cost[-1])

Fixed submission:
#  def II(): return int(input())
#def LI(): return [int(i) for i in input().split()]

#N, K = LI()
#H = LI()

#cost = [0] * N
#cost[0] = 0
#for n in range(1, N):
#  cost[n] = min([ cost[n-k]+abs(H[n-k]-H[n]) for k in range(1, min(n+1, K+1)) ])

#print(cost[-1])

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()