Buggy python submission (verdict: Time Limit Exceeded):
def main():
  num, K, *line = map(int, open(0).read().split())
  dp = [float("inf")]* num
  dp[0] = 0
  for i in range(1, num):
    I = min(i + 1 , K + 1)
    dp[i] = min([dp[i - k] + abs(line[i] - line[i - k]) for k in range(1 , I)])
  #kの範囲: k = 1,2,3...K 無理なときは k = 1,2..i
  print(dp[-1])
main()

Fixed submission:
def ans():
    n, k, *h = map(int, open(0).read().split())
    dp = [float("inf")] * n
    dp[0] = 0
    for i in range(1, n):
        min_j = max(0, i-k)
        dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(min_j , i)])
    print(dp[n-1])
 
ans()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  number = list(map(int,input().split()))
  line = list(map(int,input().split()))
 
  num = number[0]
  K = number[1]
  dp = [float("inf")]* num
  dp[0] = 0
 
  for i in range(1, num):
    I = min(i + 1 , K + 1)
    dp[i] = min([dp[i - k] + abs(line[i] - line[i - k]) for k in range(1 , I)])
  #kの範囲: k = 1,2,3...K 無理なときは k = 1,2..i
  
  print(dp[-1])
  
main()

Fixed submission:
def ans():
    n, k, *h = map(int, open(0).read().split())
    dp = [float("inf")] * n
    dp[0] = 0
    for i in range(1, n):
        min_j = max(0, i-k)
        dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(min_j , i)])
    print(dp[n-1])
 
ans()

Buggy python submission (verdict: Time Limit Exceeded):
num, K, *line = map(int, open(0).read().split())
def main():
  dp = [float("inf")]* num
  dp[0] = 0
  for i in range(1, num):
    min_j = max(0, i - K)
    dp[i] = min([dp[j] + abs(line[i] - line[j]) for j in range(min_j , i)])
  #kの範囲: k = 1,2,3...K 無理なときは k = 1,2..i
  print(dp[-1])
main()

Fixed submission:
def ans():
    n, k, *h = map(int, open(0).read().split())
    dp = [float("inf")] * n
    dp[0] = 0
    for i in range(1, n):
        min_j = max(0, i-k)
        dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(min_j , i)])
    print(dp[n-1])
 
ans()

Buggy python submission (verdict: Time Limit Exceeded):
num, K, *line = map(int, open(0).read().split())

dp = [float("inf")]* num
dp[0] = 0
 
for i in range(1, num):
  min_j = max(0, i - K)
  dp[i] = min([dp[j] + abs(line[i] - line[j]) for j in range(min_j , i)])

print(dp[-1])

Fixed submission:
def ans():
    n, k, *h = map(int, open(0).read().split())
    dp = [float("inf")] * n
    dp[0] = 0
    for i in range(1, n):
        min_j = max(0, i-k)
        dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(min_j , i)])
    print(dp[n-1])
 
ans()

Buggy python submission (verdict: Time Limit Exceeded):
num, K, *line = map(int, open(0).read().split())

dp = [float("inf")]* num
dp[0] = 0
 
for i in range(1, num):
  I = min(i + 1 , K + 1)
  dp[i] = min([dp[i - k] + abs(line[i] - line[i - k]) for k in range(1 , I)])
  #kの範囲: k = 1,2,3...K 無理なときは k = 1,2..i
  
print(dp[-1])

Fixed submission:
def ans():
    n, k, *h = map(int, open(0).read().split())
    dp = [float("inf")] * n
    dp[0] = 0
    for i in range(1, n):
        min_j = max(0, i-k)
        dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(min_j , i)])
    print(dp[n-1])
 
ans()

Buggy python submission (verdict: Time Limit Exceeded):
number = list(map(int,input().split()))
line = list(map(int,input().split()))
 
num = number[0]
K = number[1]
dp = [float("inf")]* num
dp[0] = 0

for i in range(1, num):
  I = min(i + 1 , K + 1)
  dp[i] = min([dp[i - k] + abs(line[i] - line[i - k]) for k in range(1 , I)])
  #kの範囲: k = 1,2,3...K 無理なときは k = 1,2..i
  
print(dp[-1])

Fixed submission:
def ans():
    n, k, *h = map(int, open(0).read().split())
    dp = [float("inf")] * n
    dp[0] = 0
    for i in range(1, n):
        min_j = max(0, i-k)
        dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(min_j , i)])
    print(dp[n-1])
 
ans()

Buggy python submission (verdict: Time Limit Exceeded):
number = list(map(int,input().split()))
line = list(map(int,input().split()))
 
num = number[0]
K = number[1]
dp = [0]* num

for i in range(1, num):
  I = min(i + 1 , K + 1)
  dp[i] = min([dp[i - k] + abs(line[i] - line[i - k]) for k in range(1 , I)])
  #kの範囲: k = 1,2,3...K 無理なときは k = 1,2..i
  
print(dp[-1])

Fixed submission:
def ans():
    n, k, *h = map(int, open(0).read().split())
    dp = [float("inf")] * n
    dp[0] = 0
    for i in range(1, n):
        min_j = max(0, i-k)
        dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(min_j , i)])
    print(dp[n-1])
 
ans()

Buggy python submission (verdict: Time Limit Exceeded):
number = list(map(int,input().split()))
line = list(map(int,input().split()))
 
num = number[0]
K = number[1]
dp = [0]* num


for i in range(1, num):
  dp[i] = min([dp[i - k] + abs(line[i] - line[i - k]) for k in range(1 , min(i + 1 , K + 1))])
  #kの範囲: k = 1,2,3...K 無理なときは k = 1,2..i
  
print(dp[-1])

Fixed submission:
def ans():
    n, k, *h = map(int, open(0).read().split())
    dp = [float("inf")] * n
    dp[0] = 0
    for i in range(1, n):
        min_j = max(0, i-k)
        dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(min_j , i)])
    print(dp[n-1])
 
ans()

Buggy python submission (verdict: Time Limit Exceeded):
number = list(map(int,input().split()))
line = list(map(int,input().split()))
 
num = number[0]
K = number[1]
dp = [0, abs(line[1] - line[0])]
for i in range(2, num):
  a = min([(dp[-k] + abs(line[i] - line[i - k])) for k in range(1, min(i + 1 , K + 1))])
  dp += [a]
print(dp[-1])

Fixed submission:
def ans():
    n, k, *h = map(int, open(0).read().split())
    dp = [float("inf")] * n
    dp[0] = 0
    for i in range(1, n):
        min_j = max(0, i-k)
        dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(min_j , i)])
    print(dp[n-1])
 
ans()

Buggy python submission (verdict: Time Limit Exceeded):
number = list(map(int,input().split()))
line = list(map(int,input().split()))
 
num = number[0]
K = number[1]
dp = [0, abs(line[1] - line[0])]
for i in range(2, num):
  line2 = []
  a = min([(dp[-k] + abs(line[i] - line[i - k])) for k in range(1, min(i + 1 , K + 1))])
  dp += [a]
print(dp[-1])

Fixed submission:
def ans():
    n, k, *h = map(int, open(0).read().split())
    dp = [float("inf")] * n
    dp[0] = 0
    for i in range(1, n):
        min_j = max(0, i-k)
        dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(min_j , i)])
    print(dp[n-1])
 
ans()

Buggy python submission (verdict: Time Limit Exceeded):
number = list(map(int,input().split()))
line = list(map(int,input().split()))
 
num = number[0]
K = number[1]
dp = [0, abs(line[1] - line[0])]
for i in range(2, num):
  line2 = []
  for k in range(1, min(i + 1 , K + 1)):
    a = dp[-k] + abs(line[i] - line[i - k])
    line2.append(a)
  dp += [min(line2)]
print(dp[-1])


Fixed submission:
def ans():
    n, k, *h = map(int, open(0).read().split())
    dp = [float("inf")] * n
    dp[0] = 0
    for i in range(1, n):
        min_j = max(0, i-k)
        dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(min_j , i)])
    print(dp[n-1])
 
ans()

Buggy python submission (verdict: Runtime Error):
number = list(map(int,input().split()))
line = list(map(int,input().split()))

num = number[0]
K = number[1]
dp = [0, abs(line[1] - line[0])]
for i in range(2, num):
  line2 = []
  for k in range(1, K + 1):
    a = dp[-k] + abs(line[i] - line[i - k])
    line2.append(a)
  dp += [min(line2)]
print(dp[-1])

Fixed submission:
def ans():
    n, k, *h = map(int, open(0).read().split())
    dp = [float("inf")] * n
    dp[0] = 0
    for i in range(1, n):
        min_j = max(0, i-k)
        dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(min_j , i)])
    print(dp[n-1])
 
ans()