Harryxun/stf_run huggingface dataset:
import math
from functools import reduce

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

n, x = map(int,input().split())
li = list(map(int,input().split()))
d = [abs(x-li[0])]

for i in range(n-1):
    d.append(abs(li[i]-li[i+1]))

print(gcd_list(d))

### FIXED CODE ###

import fractions
from functools import reduce
 
def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

n, x = map(int,input().split())
li = list(map(int,input().split()))
d = [abs(x-li[0])]
 
for i in range(n-1):
    d.append(abs(li[i]-li[i+1]))

print(gcd(*d))
n = int(input())
xy = []
diff = []
for _ in range(n):
  tmp = list(map(int,input().split()))
  xy.append(tmp)
for i in range(n):
  for j in range(n):
    if j != i:
      tmpd = [ xy[j][0] - xy[i][0] , xy[j][1] - xy[i][1] ]
      flag = 0
      for mxy in diff:
        if mxy[1:] == tmpd:
            flag = 1
            mxy[0] += 1
            break
      if flag == 0:
        diff.append([0]+tmpd)
diff.sort()
diff.reverse()
print(n-diff[0][0]-1)

### FIXED CODE ###

n = int(input())
xy = []
diff = []
for _ in range(n):
  tmp = list(map(int,input().split()))
  xy.append(tmp)
for i in range(n):
  for j in range(n):
    if j != i:
      tmpd = [ xy[j][0] - xy[i][0] , xy[j][1] - xy[i][1] ]
      flag = 0
      for mxy in diff:
        if mxy[1:] == tmpd:
            flag = 1
            mxy[0] += 1
            break
      if flag == 0:
        diff.append([0]+tmpd)
diff.sort()
diff.reverse()
if n == 1:
  print(1)
else:
  print(n-diff[0][0]-1)
N=int(input())
s=[]
t=[]
for i range(N):
    s_tmp,t_tmp=map(str,input().split())
    s.append(s_tmp)
    t.append(int(t_tmp))
X=input() 

# N=3
# s=["dwango","sixth","prelims"]
# t=[ 2, 5,25]
# X="prelims"

print(sum(t[s.index(X)+1:]))





### FIXED CODE ###

N=int(input())
s=[]
t=[]
for i in range(N):
    s_tmp,t_tmp=map(str,input().split())
    s.append(s_tmp)
    t.append(int(t_tmp))
X=input() 

# N=3
# s=["dwango","sixth","prelims"]
# t=[ 2, 5,25]
# X="prelims"

print(sum(t[s.index(X)+1:]))
x = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
 
    return divisors


d = make_divisors(x)


for i in d:
    for b in range(-100,100):
        a = i + b
        if x // i == a**4 + (a**3)*b + (a**2)*(b**2) + a*(b**3) + b**4:
            ans = [a,b]
            break
        
print(ans)

### FIXED CODE ###

x = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
 
    return divisors


d = make_divisors(x)


for i in d:
    for b in range(-10000,10000):
        a = i + b
        if x // i == a**4 + (a**3)*b + (a**2)*(b**2) + a*(b**3) + b**4:
            ans = [str(a),str(b)]
            break
        
print(*ans)
import sys
import numpy as np
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
X, Y, A, B, C = [int(x) for x in input().strip().split()]
p = np.array(sorted([int(x) for x in input().strip().split()], reverse=True))[:X]
q = np.array(sorted([int(x) for x in input().strip().split()], reverse=True))[:Y]
r = np.array(sorted([int(x) for x in input().strip().split()], reverse=True))[:X+Y]

pi, qi, ri = X-1, Y-1, 0
tp, tq, tr = p[pi], q[qi], r[ri]
ans = 0
while pi >= 0 or qi >= 0:
    if tp >= tr and  tq >= tr:
        break
    elif tp < tr and tq < tr:
        if tp < tq:
            p[pi] = r[ri]
            pi -= 1
            ri += 1
        else:
            q[qi] = r[ri]
            qi -= 1
            ri += 1
    elif tp < tr or tq < tr:
        if tp < tr:
            p[pi] = r[ri]
            ri += 1
            pi -= 1
            tp = p[pi]
        else:
            q[qi] = r[ri]
            ri += 1
            qi -= 1
            tq = q[qi]
    else:
        break

print(sum(p)+sum(q))

### FIXED CODE ###

import sys
import numpy as np
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
X, Y, A, B, C = [int(x) for x in input().strip().split()]
p = np.array(sorted([int(x) for x in input().strip().split()], reverse=True))[:X]
q = np.array(sorted([int(x) for x in input().strip().split()], reverse=True))[:Y]
r = np.array(sorted([int(x) for x in input().strip().split()], reverse=True))[:min(C, X+Y)]

pq = np.hstack((p, q))
pq.sort()
ri = 0
for i, t in enumerate(pq):
    if t < r[ri]:
        pq[i] = r[ri]
        ri += 1
    if ri == len(r):
        break
print(sum(pq))
s,w=map(int.input().split());
if s<=w:
  print('unsafe');
else:
  print('safe');


### FIXED CODE ###

def issafe(S,W):
    if S > W:
        return "safe"
    return "unsafe"

S,W = map(int,input().split())
print(issafe(S,W))
import os
import sys
from collections import defaultdict, Counter, deque
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt
from copy import deepcopy

def main():
    
    n,m,k = map(int, input().split())
    n_list = list(map(int, input().split()))
    m_list = list(map(int, input().split()))
    i,j,count = 0,0,0

    while(k>=0):

        if count == n+m:
            break

        if i <= n and j <= m:

            if n_list[i] < m_list[j]:
                k -= n_list[i]
                i += 1
            else:
                k -= m_list[j]
                j += 1
              
            if k < 0:
                break
            else:
                count += 1

        else:
            if i > n:
                if j > m:
                    break
                k -= m_list[j]
                j += 1

            elif j > m:
                if i > n:
                    break
                k -= n_list[i]
                i += 1

            if k < 0:
                break
            else:
                count += 1

    print(count)



            

if __name__ == "__main__":
    main()


### FIXED CODE ###

import os
import sys
from collections import defaultdict, Counter, deque
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt
from copy import deepcopy

def main():
    
    n,m,k = map(int, input().split())
    n_list = list(map(int, input().split()))
    m_list = list(map(int, input().split()))

    a_list = [0]
    b_list = [0]

    ans = 0
    num = 0

    for i in range(n):
        a_list.append(a_list[i] + n_list[i])

    for i in range(m):
        b_list.append(b_list[i] + m_list[i])


    
    for i in range(n+1):
        if k < a_list[i]:
            break
        while(b_list[m] > k - a_list[i]):
            m -= 1
        ans = max(ans, i+m)
    print(ans)
            

if __name__ == "__main__":
    main()
from functools import lru_cache
import sys

sys.setrecursionlimit(10**8)

N = int(input())
S = input()

@lru_cache(maxsize=None)
def dp(s):
    result = s.count("ABC")
    return result
print(dp(S))



### FIXED CODE ###

from functools import lru_cache
import sys

sys.setrecursionlimit(10**8)

K, X = map(int, input().split())

@lru_cache(maxsize=None)
def dp(k,x):
    if k*500 < x:
        result = 'No'
    else:
        result = 'Yes'
    return result
print(dp(K,X))
from scipy.sparse.csgraph import dijkstra

n, m, k = map(int, input().split())
graph = [[10 ** 9 + 7 for i in range(n)] for i in range(n)]

for i in range(m):
    a, b = map(int, input().split())
    graph[a - 1][b - 1], graph[b - 1][a - 1] = 1, 1

block = [[] for i in range(n)]
for i in range(k):
    c, d = map(int, input().split())
    block[c - 1].append(d - 1)
    block[d - 1].append(c - 1)

cost = dijkstra(graph)
ans2 = []
for i in range(n):
    ans = 0
    for j in range(n):
        if i == j:
            continue
        if cost[i][j] < 10 ** 9 + 7 and cost[i][j] != 1:
            if j not in block[i]:
                ans += 1
    ans2.append(str(ans))

print(' '.join(ans2))


### FIXED CODE ###

class UnionFind():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1]*(n+1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    # 木の併合、入力は併合したい各ノード
    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if(x == y):
            return
        # 違う木に属していた場合rnkを見てくっつける方を決める
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            # rnkが同じ（深さに差がない場合）は1増やす
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    # xとyが同じグループに属するか判断
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return -self.root[self.Find_Root(x)]

n, m, k = map(int, input().split())
friendUnion = UnionFind(n)
friend = [[] for i in range(n)]

for i in range(m):
    a, b = map(int, input().split())
    friendUnion.Unite(a - 1, b - 1)
    friend[a - 1].append(b - 1)
    friend[b - 1].append(a - 1)

block = [[] for i in range(n)]

for i in range(k):
    c, d = map(int, input().split()) 
    block[c - 1].append(d - 1)
    block[d - 1].append(c - 1)

ans = []
for i in range(n):
    tmp = friendUnion.Count(i) - 1 - len(friend[i]) 
    for j in block[i]:
        if friendUnion.isSameGroup(i, j):
            tmp -= 1
    ans.append(str(tmp))

print(' '.join(ans))
n = int(input())

xu = [[i for i in input().split()] for j in range(n)]

ans = 0

for i in range(n):
    if xu[i][1] == 'JPY':
        ans += int(xu[i][0])
    else:
        ans += 1000*int(xu[i][0])
        
print(ans)

### FIXED CODE ###

n = int(input())

xu = [[i for i in input().split()] for j in range(n)]

ans = 0

for i in range(n):
    if xu[i][1] == 'JPY':
        ans += int(xu[i][0])
    else:
        ans += 380000*float(xu[i][0])
        
print(ans)
A, B = input().split()
A = int(input())
B = int(B.replace(".". ""))

print(A*B//100)

### FIXED CODE ###

A, B = input().split()
A = int(A)
B = int(B.replace(".", ""))

print(A*B//100)
import statistics
import math

n = int(input())
x = list(map(int,input().split()))

for i in range(n):
  tmp = x
  print(statistics.median(x.pop(i)))

### FIXED CODE ###


n = int(input())
x = list(map(int,input().split()))
sort_x = sorted(x)

mid_1 = sort_x[n//2-1]
mid_2 = sort_x[n//2]

for i in range(n):
  
  if x[i] <= mid_1:
    print(mid_2)
  else:
    print(mid_1)
N=int(input())
S=list(input())
dot=0
sha=0
s_r=list(reversed(S))
#print(s_r)
for i in range(N):
    if S[i] == ".":
        dot=i
        #break
for i in range(N):
    if s_r[i] == "#":
        sha=i
        #break

count=0
#print(dot)#左から
#print(sha)#右から
count_a=0
count_b=0

if dot<=sha:
    for i in range(N):
        if i<dot and S[i]!=".":
            count_a+=1
    for i in range(N):
        if i<sha and s_r[i]!="#":
            count_b+=1
    #print(count)
    c=count_a+count_b
else:
    d=min(count_a,count_b)

a=0
b=0

for i in range(N):
    if S[i]!=".":
        a+=1
    if S[i]!="#":
        b+=1

#print(count)
ans=min(a,b,c,d)
print(ans)



### FIXED CODE ###

# 累積和次は倒す
N = int(input())
S = input()
ans = 10 ** 9
white = [0] * (N + 1)
black = [0] * (N + 1)

for i, c in enumerate(S):
    if c == ".":
        white[i + 1] = white[i] + 1
        black[i + 1] = black[i]
    else:
        white[i + 1] = white[i]
        black[i + 1] = black[i] + 1
# 累積和
ans = min(ans, black[N], white[N])

white_sum = white[N]

for i in range(1, N):
    a = white_sum - white[i]
    b = black[i]
    # a 境目より右領域にどれだけ白があるか，その白は黒に変更
    # b 境目より左領域にどれだけ黒があるか，その黒は白に変更
    cnt = a + b
    ans = min(ans, cnt)
print(ans)
n,k = map(int, input().split())
mod = 10**9 + 7

ans = 0
lim = 2*(10**5) + 5
mothers = [1] * lim
mothers_inv = [1] * lim
for i in range(1, lim):
    mothers[i] = mothers[i-1] * i % mod
    mothers_inv[i] = pow(mothers[i], mod-2, mod)


def calc(n,k):
    child = mothers[n] * mothers_inv[n-k] % mod
    mother_inv = mothers_inv[k]
    return((child * mother_inv)%mod)

if( n <= k+1):
    ans = calc(2*n-1, n-1)
    print(ans)
    exit()

ans = calc(2*n-1, n-1)

tmp = 0
for i in range(1,n-k):
    if(i ==1):
        c1 = 1
    else:
        c1 = calc(n-1, i-1) 

    c2 = calc(n, i) 
    ans = (ans - c1 * c2)%mod


print(ans)

### FIXED CODE ###

n,k = map(int, input().split())
mod = 10**9 + 7

ans = 0
lim = 2*(10**5) + 5
mothers = [1] * lim
mothers_inv = [1] * lim
for i in range(1, lim):
    mothers[i] = mothers[i-1] * i % mod
    mothers_inv[i] = pow(mothers[i], mod-2, mod)


def calc(n,k):
    child = mothers[n] * mothers_inv[n-k] % mod
    mother_inv = mothers_inv[k]
    return((child * mother_inv)%mod)

def calc2(n,k):
    child = 1
    for i in range(n, n-k, -1):
        child = child * i % mod
    mother_inv = mothers_inv[k]
    return((child * mother_inv)%mod)

if( n <= k+1):
    ans = calc2(2*n-1, n-1)
    print(ans)
    exit()

ans = calc2(2*n-1, n-1)

for i in range(1,n-k):
    if(i ==1):
        c1 = 1
    else:
        c1 = calc(n-1, i-1)

    c2 = calc(n, i)
    ans = (ans - c1 * c2)%mod


print(ans)
n = int(input())
w = list(map(int, input().split()))

list_sum = sum(list)

ans = 1000000
s1 = 0
s2 = list_sum
for i in range(n):
  s1 += w[i]
  s2 -= w[i]
  ans = min(ans,max(s1-s2,s2-s1))

print(ans)

### FIXED CODE ###



n = int(input())
w = list(map(int, input().split()))

list_sum = sum(w)

ans = 1000000
s1 = 0
s2 = list_sum
for i in range(n):
  s1 += w[i]
  s2 -= w[i]
  ans = min(ans,max(s1-s2,s2-s1))

print(ans)
import sys    
while True :
    a, b = map(int, sys.stdin.readline().split())
    if (a == 0) & (b == 0) :
        break
      if a < b : print(a, b)
      else : print(b, a)

### FIXED CODE ###

import sys
while True:
    a,b=map(int,sys.stdin.readline().split())
    if a==0 and b==0:
        break
    if a<b:print(a,b)
    else:print(b,a)
nm = [int(i) for i in input().split()]
points = sorted([int(i) for i in input().split()])
n, m = nm[0], nm[1]

if n >= m:
    print(0)
elif n == 1:
    print(max(points) - min(points))
else:
    list_diff = [points[i+1] - points[i] for i in range(m-1)]
    list_th = []
    for i in range(n-1):
        max_index = list_diff.index(max(list_diff))
        list_th.append(max_index)
        list_diff[max_index] = 0
        
    x = points[0]
    th = 0
    count = 0
    print(list_th)
    while x < points[-1]:
        if x == points[list_th[th]]:
            x = points[list_th[th]+1]
            th += 1
        else:
            x += 1
            count += 1
            if x == points[-1]:
                break
    print(count)

### FIXED CODE ###

n, m = list(map(int, input().split()))
xxx = list(map(int, input().split()))
 
if n >= m:
    print(0)
    exit()
xxx.sort()
ddd = [b - a for a, b in zip(xxx, xxx[1:])]
ddd.sort()
print(sum(ddd[:m - n]))
def chmin(DP,b,i):
    if (DP[i]> b):
        DP[i] = b
        return True
    return False
N = int(input())
H = [i for i in map(int,input().split())]
dp = [10**5 for i in range(N)]
dp[0] = 0
for i in range(1,N):
    chmin(dp,dp[i-1]+abs(H[i]-H[i-1]),i)
    print(dp)
    if i > 1:
        chmin(dp,dp[i-2]+abs(H[i]-H[i-2]),i)
print(dp[-1])

### FIXED CODE ###

def chmin(DP,b,i):
    if (DP[i]> b):
        DP[i] = b
        return True
    return False
N = int(input())
H = [i for i in map(int,input().split())]
dp = [10**10 for i in range(N)]
dp[0] = 0
for i in range(1,N):
    chmin(dp,dp[i-1]+abs(H[i]-H[i-1]),i)
    if i > 1:
        chmin(dp,dp[i-2]+abs(H[i]-H[i-2]),i)
print(dp[-1])
def resolve():
    from collections import deque

    h, w = map(int, input().split())
    c_h, c_w = map(int, input().split())
    c_h -= 1
    c_w -= 1
    d_h, d_w = map(int, input().split())
    d_h -= 1
    d_w -= 1
    dist = [[10**18 for i in range(w)] for i in range(h)]
    dist[c_h][c_w] = 0

    C = []
    for _ in range(h):
        C.append(list(input()))
    D = [(-1, 0), (1, 0), (0, -1), (0, 1)]
    queue = deque([(c_h, c_w)])

    while queue:
        (x, y) = queue.popleft()
        d = dist[x][y]

        for (dx, dy) in D:
            new_x, new_y = x + dx, y + dy
            if -1 < new_x < h and -1 < new_y < w:
                if C[new_x][new_y] == '.' and dist[new_x][new_y] > d:
                    dist[new_x][new_y] = d
                    queue.appendleft((new_x, new_y))

        for dx in range(-2, 3):
            for dy in range(-2, 3):
                if -1 < x + dx < h and -1 < y + dy < w and (dx != 0 or dy != 0):
                    if C[x + dx][y + dy] == '.' and dist[x + dx][y + dy] > d:
                        dist[x + dx][y + dy] = d + 1
                        queue.append((x + dx, y + dy))

    ans = dist[d_h][d_w]
    if ans == 10**18:
        print(-1)
    else:
        print(ans)

resolve()

### FIXED CODE ###

def resolve():
    import math
    n, x, t = map(int, input().split())
    print(math.ceil(n / x) * t)

resolve()
import numpy as np
N,K = map(int, input().split())

A_list = np.array([0]+list(map(int, input().split())))
#print(A_np)


for j in range(min(K,46):
  new_A=np.zeros(N+2,dtype=np.int64)
  for i in range(1,N+1):
    #print(new_A)
    mi=i-A_list[i]
    ma=i+A_list[i]
    if mi<0:
      mi=0
    if ma>N:
      ma=N
    #new_A[mi:ma+1]+=1
    new_A[mi]+=1
    new_A[ma+1]-=1

  A_list=np.cumsum(new_A)
  #if A_list[1:N+1])==N*N:
  #  break
    
for i in range(1,N+1):
  print(A_list[i],end=" ")


### FIXED CODE ###

import numpy as np
from numba import njit

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

A_list = np.array([0]+list(map(int, input().split())))

@njit
def update(A_list):

  for j in range(min(K,46)):
    new_A=np.zeros(N+2,dtype=np.int64)
    for i in range(1,N+1):
      #print(new_A)
      mi=i-A_list[i]
      ma=i+A_list[i]
      if mi<0:
        mi=0
      if ma>N:
        ma=N
      #new_A[mi:ma+1]+=1
      new_A[mi]+=1
      new_A[ma+1]-=1

    A_list=np.cumsum(new_A)
    #if sum(A_list[1:N+1])==N*N:
    #  return(A_list)    
    #  break
      
  return(A_list)

A_list=update(A_list)
for i in range(1,N+1):
  print(A_list[i],end=" ")
n = int(input())
a = list(map(int,input().split()))
b = []
for i in range(n):
  b.append(0)
k = 0
if(n%2==1):
  k = (n-1)//2
else:
  k = n//2
for i in range(n):
  if(i%2==0):
    print(a[i])
    print(k+i//2)
    b[k+i//2]=a[i]
  else:
     print(a[i])
    b[k-(i+1)//2]=a[i]
print(b)
  
  
 


### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
b = []
for i in range(n):
  b.append(0)
k = 0
if(n%2==1):
  k = (n-1)//2
  m = -1
else:
  k = n//2
  m = 1
for i in range(n):
  if(i%2==0):
    b[k+m*i//2]=a[i]
  else:
    b[k-m*(i+1)//2]=a[i]
ans = ""
for i in range(n):
  ans += str(b[i])+" "
print(ans)
a = (input())
if a == "SUN":
    print(7)
elif a == "MON":
    print(6)
elif a == "TUE":
    print(5)
elif a == "WED":
    print(4)
elif a == "THU":
    print(3)
elif a == "FRI":
    print(2)
elif a == "SAT":
     print(1)

### FIXED CODE ###

s = ['SUN','MON','TUE','WED','THU','FRI','SAT']
day = input()
start = s.index(day)
if day == 'SUN':
    print(7)
else:
    count = 0
    for x in range(7):
        if start == 7:
            start = 0
        if s[start] == 'SUN':
            print(count)
            break
        else:
            start += 1
        count += 1
n=int(inout())
k=int(input())
x=int(input())
y=int(input())
print(x*k+y*max(0,n-k))

### FIXED CODE ###

n=int(input())
k=int(input())
x=int(input())
y=int(input())
print(x*min(n,k)+y*max(0,n-k))
# -*- coding:utf-8 -*-
#ICPC得点集計ソフトウェア
import sys
def solve(n):
	nums = []
	for i in xrange(n):
		temp = input()
		nums.append(temp)
	nums.sort()
	sum = 0
	for i in xrange(1,n-1):
		sum += nums[i]
	return sum / (n-2)


if __name__ == "__main__":
	while :
		N = input()
		if N == 0:
			sys.exit()
		else:
			print solve(N)

### FIXED CODE ###

# -*- coding:utf-8 -*-
#ICPC得点集計ソフトウェア
import sys
def solve(n):
	nums = []
	for i in xrange(n):
		temp = input()
		nums.append(temp)
	nums.sort()
	sum = 0
	for i in xrange(1,n-1):
		sum += nums[i]
	return sum / (n-2)


if __name__ == "__main__":
	while 1:
		N = input()
		if N == 0:
			sys.exit()
		else:
			print solve(N)
from sys import stdin, gettrace
import sys
 
if not gettrace():
    def input():
        return next(stdin)[:-1]
 
 
# def input():
#    return stdin.buffer.readline()
 
def mincost(n,h,k):
    	dp=[-1 for i in range(n)]
    	dp[n-1]=0
    	dp[n-2]=abs(h[n-2]-h[n-1])
    	for i in range(n-3,-1,-1):
        	mn=min(i+k+1,n)
        	mnm=sys.maxsize
        	for j in range(i+1,mn):
            	mnm=min(dp[j]+abs(h[j]-h[i]),mnm)
        	dp[i]=mnm    
    	return dp[0]

def main():
	n,k=map(int,input().split())
	h=[int(x) for x in input().split()]
	print(mincost(n,h,k)) 
 
if __name__ == "__main__":
    main()

### FIXED CODE ###

from sys import stdin, gettrace
import sys
 
if not gettrace():
    def input():
        return next(stdin)[:-1]
 
 
# def input():
#    return stdin.buffer.readline()
 
def mincost(n,h,k):
  dp=[-1 for i in range(n)]
  dp[n-1]=0
  dp[n-2]=abs(h[n-2]-h[n-1])
  for i in range(n-3,-1,-1):
    mn=min(i+k+1,n)
    mnm=sys.maxsize
    for j in range(i+1,mn):
      mnm=min(dp[j]+abs(h[j]-h[i]),mnm)
    dp[i]=mnm    
  return dp[0]
 
def main():
  n,k=map(int,input().split())
  h=[int(x) for x in input().split()]
  print(mincost(n,h,k)) 
 
if __name__ == "__main__":
    main()
from decimal import Decimal

a, b = map(float, input().split())

ab = Decimal(a) * Decimal(b)
result = str(ab).split('.')

print(int(result[0]))


### FIXED CODE ###

from decimal import *

a, b = input().split()

ab = Decimal(a) * Decimal(b)
result = Decimal(str(ab)).quantize(Decimal(str(1)), rounding=ROUND_DOWN)

print(int(result))
n = len(a)-1
i = 0
for _ in range(len(a)-1):
    temp = a[i]
    a[i] = a[n-1]
    a[n-1] = temp
for i in a:
  print(i,end=" ")

### FIXED CODE ###

a = list(map(int,input().split()))
n = len(a)-1
i = 0
for _ in range(len(a)-1):
    temp = a[i]
    a[i] = a[n-1]
    a[n-1] = temp
    n+=1
for  i in a:
         print(i,end=" ")
if __name__ == '__main__':
    A = input()
    B = input()
    C = input()
    K = input()

    if A > K:
        print(K)
    elif A+B >k:
        print(A)
    else:
        print(2*A-K-B)


### FIXED CODE ###

if __name__ == '__main__':
    A =[]
    B = input()
    A = B.split()

    a = int(A[0])
    b = int(A[1])
    c = int(A[2])
    k = int(A[3])

    if a > k:
        print(k)
    elif (a+b) > k:
        print(a)
    else:
        ans = 2*a-k+b
        print(ans)
#n,l = map(int,input().split())
#l = kist(input())

l = list(input())
cnt=0
ans=0

for i in range(n):
    if l[i]=='I':
        cnt+=1
    else:
        cnt-=1
    ans = max(ans,cnt)

print(ans)

### FIXED CODE ###

#n,l = map(int,input().split())
#l = kist(input())

n = int(input())
l = list(input())
cnt=0
ans=0

for i in range(n):
    if l[i]=='I':
        cnt+=1
    else:
        cnt-=1
    ans = max(ans,cnt)

print(ans)
*a=map(int,input().split())
print(max(a)-min(a))

### FIXED CODE ###

a=list(map(int,input().split()))
print(max(a)-min(a))
# input
A, B = int(input())

snack = max([A, B])
while snack % A != 0 and snack % B != 0:
    snack += 1

print(snack)

### FIXED CODE ###

def gcd(m, n):
    x = max(m, n)
    y = min(m, n)
    if x % y == 0:
        return y
    else:
        while x % y != 0:
            z = x % y
            x = y
            y = z
        return z


def lcm(m, n):
    return (m * n) // gcd(m, n)


# input
A, B = map(int, input().split())

# lcm
snack = lcm(A, B) 

print(snack)
while True:
    a,b = map(int,input().split())
        print (len(str(a+b)))
    except EOFError:
        break

### FIXED CODE ###

while True:
    try:
        a,b = map(int,input().split())
        print (len(str(a+b)))
    except EOFError:
        break