Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
line = list(map(int,input().split()))
 
inf = float('inf')
line.extend([inf for i in range(k)])
box = [inf for i in range(n + k)]
#out of rangeを避けるため

box[0] = 0
for x in range(n):   
  for i in range(1,k+1):
    cost = abs(line[x] - line[x+i])
    if box[x+i] >= box[x] + cost:
      box[x+i] = box[x] + cost
print(box[n-1])

Fixed submission:
n,k = map(int,input().split())
line = list(map(int,input().split()))
 
inf = float('inf')
line.extend([inf for i in range(k)])
box = [inf for i in range(n + k)]
#out of rangeを避けるため

box[0] = 0
for x in range(n):   
  for i in range(1,k+1):
    cost = abs(line[x] - line[x+i])
    if box[x+i] >= box[x] + cost:
      box[x+i] = box[x] + cost
print(box[n-1])

Buggy python submission (verdict: Runtime Error):
import sys
# 再帰回数上弦を100000回に設定
sys.setrecursionlimit(100000)

n,k = map(int,input().split())
line = list(map(int,input().split()))
 
inf = float('inf')
line.extend([inf for i in range(k)])
box = [inf for i in range(n + k)]
#out of rangeを避けるため
  
def frog(x):
  box[0] = 0
  if x == n-1:
    return box[n-1]
  else:    
    for i in range(1,k+1):
      cost = abs(line[x] - line[x+i])
      if box[x+i] >= box[x] + cost:
        box[x+i] = box[x] + cost
    return frog(x+1)
print(frog(0))

Fixed submission:
n,k = map(int,input().split())
line = list(map(int,input().split()))
 
inf = float('inf')
line.extend([inf for i in range(k)])
box = [inf for i in range(n + k)]
#out of rangeを避けるため

box[0] = 0
for x in range(n):   
  for i in range(1,k+1):
    cost = abs(line[x] - line[x+i])
    if box[x+i] >= box[x] + cost:
      box[x+i] = box[x] + cost
print(box[n-1])

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

inf = float('inf')
line.extend([inf for i in range(k)])
box = [inf for i in range(n + k)]
#out of rangeを避けるため
  
def frog(x):
  box[0] = 0
  if x == n-1:
    return box[n-1]
  else:    
    for i in range(1,k+1):
      cost = abs(line[x] - line[x+i])
      if box[x+i] >= box[x] + cost:
        box[x+i] = box[x] + cost
    return frog(x+1)
print(frog(0))

Fixed submission:
n,k = map(int,input().split())
line = list(map(int,input().split()))
 
inf = float('inf')
line.extend([inf for i in range(k)])
box = [inf for i in range(n + k)]
#out of rangeを避けるため

box[0] = 0
for x in range(n):   
  for i in range(1,k+1):
    cost = abs(line[x] - line[x+i])
    if box[x+i] >= box[x] + cost:
      box[x+i] = box[x] + cost
print(box[n-1])

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

inf = float('inf')
line.extend([inf for i in range(k)])
box = [inf for i in range(n + k)]
  
def frog(x):
  box[0] = 0
  if x == n-1:
    return box[n-1]
    exit()
  else:    
    for i in range(1,k+1):
      cost = abs(line[x] - line[x+i])
      if box[x+i] >= box[x] + cost:
        box[x+i] = box[x] + cost
    return frog(x+1)
print(frog(0))

Fixed submission:
n,k = map(int,input().split())
line = list(map(int,input().split()))
 
inf = float('inf')
line.extend([inf for i in range(k)])
box = [inf for i in range(n + k)]
#out of rangeを避けるため

box[0] = 0
for x in range(n):   
  for i in range(1,k+1):
    cost = abs(line[x] - line[x+i])
    if box[x+i] >= box[x] + cost:
      box[x+i] = box[x] + cost
print(box[n-1])

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

inf = float('inf')
line.extend([inf for i in range(k)])
box = [inf for i in range(n + k)]
  
def frog(x):
  box[0] = 0
  if x == n-1:
    return box[n-1]
  else:    
    for i in range(1,k+1):
      cost = abs(line[x] - line[x+i])
      if box[x+i] >= box[x] + cost:
        box[x+i] = box[x] + cost
    return frog(x+1)
print(frog(0))

Fixed submission:
n,k = map(int,input().split())
line = list(map(int,input().split()))
 
inf = float('inf')
line.extend([inf for i in range(k)])
box = [inf for i in range(n + k)]
#out of rangeを避けるため

box[0] = 0
for x in range(n):   
  for i in range(1,k+1):
    cost = abs(line[x] - line[x+i])
    if box[x+i] >= box[x] + cost:
      box[x+i] = box[x] + cost
print(box[n-1])

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

inf = float('inf')
line.extend([inf for i in range(k)])
box = [inf for i in range(n + k)]
  
def frog(x):
  box[0] = 0
  if x == n-1:
    return box[n-1]
  else:    
    for i in range(1,k+1):
      cost = abs(line[x] - line[x+i])
      if box[x+i] == inf:
        box[x+i] = box[x] + cost
      else:
        box[x+i] = min(box[x]+cost,box[x+i])
    return frog(x+1)
print(frog(0))

Fixed submission:
n,k = map(int,input().split())
line = list(map(int,input().split()))
 
inf = float('inf')
line.extend([inf for i in range(k)])
box = [inf for i in range(n + k)]
#out of rangeを避けるため

box[0] = 0
for x in range(n):   
  for i in range(1,k+1):
    cost = abs(line[x] - line[x+i])
    if box[x+i] >= box[x] + cost:
      box[x+i] = box[x] + cost
print(box[n-1])

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

inf = float('inf')
line.extend([inf for i in range(k)])
box = [inf for i in range(n + k)]
  
def frog(x):
  box[0] = 0
  if x == n-1:
    return box[n-1]
  else:    
    for i in range(1,k+1):
      cost = abs(line[x] - line[x+i])
      if box[x+i] == inf:
        box[x+i] = box[x] + cost
      else:
        box[x+i] = min(box[x] + cost,box[x+1])
    return frog(x+1)
print(frog(0))

Fixed submission:
n,k = map(int,input().split())
line = list(map(int,input().split()))
 
inf = float('inf')
line.extend([inf for i in range(k)])
box = [inf for i in range(n + k)]
#out of rangeを避けるため

box[0] = 0
for x in range(n):   
  for i in range(1,k+1):
    cost = abs(line[x] - line[x+i])
    if box[x+i] >= box[x] + cost:
      box[x+i] = box[x] + cost
print(box[n-1])