Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
A=list(map(int,input().split()))

if k>=n:
  print(abs(A[n-1]-A[0]))
else:
  dp=list(range(n))
  for i in range(k):
    dp[i]=abs(A[i]-A[0])
  for i in range(n-k):
    temp=list(range(k))
    for j in range(k):
      temp[j]=dp[i+j]+abs(A[i+k]-A[i+j])
    dp[i+k]=min(temp)
  print(dp[n-1])

Fixed submission:
n,k=map(int,input().split())
A=list(map(int,input().split()))

if k>=n:
  print(abs(A[n-1]-A[0]))
else:
  dp=list(range(n))
  for i in range(k):
    dp[i]=abs(A[i]-A[0])
  for i in range(n-k):
    temp=list(range(k))
    for j in range(k):
      temp[j]=dp[i+j]+abs(A[i+k]-A[i+j])
    dp[i+k]=min(temp)
  print(dp[n-1])

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


if k>=n:
  print(abs(A[k-1]-A[0]))
else:
  dp=list(range(n))
  for i in range(k):
    dp[i]=abs(A[i]-A[0])
  for i in range(n-k):
    temp=list(range(k))
    for j in range(k):
      temp[j-1]=dp[i]+abs(A[i+k]-A[i])
      dp[i+k]=min(temp)
  print(dp[n-1])

Fixed submission:
n,k=map(int,input().split())
A=list(map(int,input().split()))

if k>=n:
  print(abs(A[n-1]-A[0]))
else:
  dp=list(range(n))
  for i in range(k):
    dp[i]=abs(A[i]-A[0])
  for i in range(n-k):
    temp=list(range(k))
    for j in range(k):
      temp[j]=dp[i+j]+abs(A[i+k]-A[i+j])
    dp[i+k]=min(temp)
  print(dp[n-1])

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


if k>=n:
  print(abs(A[k-1]-A[0]))
else:
  dp=list(range(n))
  for i in range(k):
    dp[i]=abs(A[i]-A[0])
  for i in range(n-k):
    temp=list(range(k))
    for j in range(k):
      temp[j-1]=dp[i]+abs(A[i+k]-A[i])
      dp[i+k]=min(temp)
  print(dp[n-1])

Fixed submission:
n,k=map(int,input().split())
A=list(map(int,input().split()))

if k>=n:
  print(abs(A[n-1]-A[0]))
else:
  dp=list(range(n))
  for i in range(k):
    dp[i]=abs(A[i]-A[0])
  for i in range(n-k):
    temp=list(range(k))
    for j in range(k):
      temp[j]=dp[i+j]+abs(A[i+k]-A[i+j])
    dp[i+k]=min(temp)
  print(dp[n-1])

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


if k>=n:
  print(abs(A[k-1]-A[0]))
else:
  dp=list(range(n))
  for i in range(k):
    dp[i]=abs(A[i]-A[0])
  for i in range(n-k):
    temp=list(range(k))
    for j in range(k):
      temp[j-1]=dp[i]+abs(A[i+k]-A[i])
      dp[i+k]=min(temp)
  print(dp[n-1])

Fixed submission:
n,k=map(int,input().split())
A=list(map(int,input().split()))

if k>=n:
  print(abs(A[n-1]-A[0]))
else:
  dp=list(range(n))
  for i in range(k):
    dp[i]=abs(A[i]-A[0])
  for i in range(n-k):
    temp=list(range(k))
    for j in range(k):
      temp[j]=dp[i+j]+abs(A[i+k]-A[i+j])
    dp[i+k]=min(temp)
  print(dp[n-1])

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


if k>=n:
  print(abs(A[k-1]-A[0]))
else:
  dp=list(range(n))
  for i in range(k):
    dp[i]=abs(A[i]-A[0])
  for i in range(n-k):
    temp=list(range(k))
    for j in range(k):
      temp[j-1]=dp[i]+abs(A[i+k]-A[i])
      dp[i+k]=min(temp1,temp2)
  print(dp[n-1])

Fixed submission:
n,k=map(int,input().split())
A=list(map(int,input().split()))

if k>=n:
  print(abs(A[n-1]-A[0]))
else:
  dp=list(range(n))
  for i in range(k):
    dp[i]=abs(A[i]-A[0])
  for i in range(n-k):
    temp=list(range(k))
    for j in range(k):
      temp[j]=dp[i+j]+abs(A[i+k]-A[i+j])
    dp[i+k]=min(temp)
  print(dp[n-1])

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


if k>=n:
  print(abs(A[k-1]-A[0]))
else:
  dp=list(range(n))
  for i in range(k):
    dp[i]=abs(A[i]-A[0])
  for i in range(n-k):
    temp=list(range(k))
    for j in range(k):
      temp[j-1]=dp[i]+abs(A[i+k]-A[i])
      dp[i+k]=min(temp1,temp2)
  print(dp[n-1])

Fixed submission:
n,k=map(int,input().split())
A=list(map(int,input().split()))

if k>=n:
  print(abs(A[n-1]-A[0]))
else:
  dp=list(range(n))
  for i in range(k):
    dp[i]=abs(A[i]-A[0])
  for i in range(n-k):
    temp=list(range(k))
    for j in range(k):
      temp[j]=dp[i+j]+abs(A[i+k]-A[i+j])
    dp[i+k]=min(temp)
  print(dp[n-1])