Harryxun/stf_run huggingface dataset:
n = int(input())
List = list(map(int,input().split()))
A = []
B = []
List = sorted(List,reverse=True)
for i in range(len(List)):
  if i%2 == 0:
    A.append(item)
  else:
    B.append(item)
Answer = sum(A) - sum(B)
print(Answer)

### FIXED CODE ###

n = int(input())
List = list(map(int,input().split()))
A = []
B = []
List = sorted(List,reverse=True)
for i in range(len(List)):
  if i%2 == 0:
    A.append(List[i])
  else:
    B.append(List[i])
Answer = sum(A) - sum(B)
print(Answer)
n = int(input())
sn = input()
sr = ''.join(list(reversed(sn)))
sint = int(sn, 2)
spop = sn.count('1')

def f(x):
    count = 0
    while x != 0:
        count += 1
        pop = bin(x).count('1')
        x %= pop
    return count



m1 = sint % (spop + 1)
m2 = sint % (spop - 1)

a = [0] * n
for i in range(n):
    if sr[i] == '0':
        d = pow(2, i, spop + 1)
        m = (m1 + d) % (spop + 1)
    else:
        d = pow(2, i, spop - 1)
        m = (m2 - d + spop - 1) % (spop - 1)
    a[i] = f(m) + 1

for ans in reversed(a):
    print(ans)


### FIXED CODE ###

n = int(input())
sn = input()
sr = ''.join(list(reversed(sn)))
sint = int(sn, 2)
spop = sn.count('1')

def f(x):
    count = 0
    while x != 0:
        count += 1
        pop = bin(x).count('1')
        x %= pop
    return count



m1 = sint % (spop + 1)
m2 = 0 if spop <= 1 else sint % (spop - 1)

a = [0] * n
for i in range(n):
    if sr[i] == '0':
        d = pow(2, i, spop + 1)
        m = (m1 + d) % (spop + 1)
        a[i] = f(m) + 1
    elif spop != 1:
        d = pow(2, i, spop - 1)
        m = (m2 - d + spop - 1) % (spop - 1)
        a[i] = f(m) + 1
    else:
        a[i] = 0

for ans in reversed(a):
    print(ans)
import itertools
import math

N, K = map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A)

mod = 10**9+7

# print(list(itertools.combinations(range(6), 3)))
# A = range(6)
# N = 6
# K = 3

# 二項係数を素数で割った余り
def combMod(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    fact = [-1 for _ in range(n+1)]
    fact[0] = 1
    fact[1] = 1
    inv = [-1 for _ in range(n+1)]
    inv[0] = 0
    inv[1] = 1
    factinv = [-1 for _ in range(n+1)]
    factinv[0] = 1
    factinv[1] = 1
    
    for i in range(2, n + 1):
        fact[i] = ((fact[i-1] * i) % p)
        inv[i] = ((-inv[p % i] * (p // i)) % p)
        factinv[i] = ((factinv[i-1] * inv[i]) % p)

    return fact[n] * factinv[r] * factinv[n-r] % p


ans = 0
for i in range(N):
    ans += (combMod(i, K-1, mod) - combMod(N-i-1, K-1, mod)) * A[i] % mod

print(ans%mod)

### FIXED CODE ###

# import itertools
# import math

N, K = map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A)

mod = 10**9+7

# print(list(itertools.combinations(range(6), 3)))
# A = range(6)
# N = 6
# K = 3

# 二項係数を素数で割った余り
def combMod(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p
    # fact = [-1 for _ in range(n+1)]
    # fact[0] = 1
    # fact[1] = 1
    # inv = [-1 for _ in range(n+1)]
    # inv[0] = 0
    # inv[1] = 1
    # factinv = [-1 for _ in range(n+1)]
    # factinv[0] = 1
    # factinv[1] = 1
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
p = mod
    
for i in range(2, N + 1):
    # fact[i] = ((fact[i-1] * i) % p)
    # inv[i] = ((-inv[p % i] * (p // i)) % p)
    # factinv[i] = ((factinv[i-1] * inv[i]) % p)
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)




ans = 0
for i in range(N):
    num = combMod(i, K-1, mod) % mod
    ans += num * A[i] % mod
    ans -= num * A[N-i-1] % mod
    ans %= mod

print(ans)
a, b, c, d = map(int, input().split())
if abs(c-a) <= d or (abs(c-b) <= d and abs(b-a) <=d:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

a, b, c, d = map(int, input().split())
if abs(c-a) <= d or (abs(c-b) <= d and abs(b-a) <=d):
    print("Yes")
else:
    print("No")
a,b,c = map(int, input().split())

array =[]
l = b-a

for i in range(l):
  n = c %i; i +=1
  if n ==0:
    array.append(i)
    print(len(array))
 


### FIXED CODE ###

a,b,c = map(int,input().split())

ans = 0
num = a

while True:
    if c%num == 0:
        ans += 1
    num += 1
    if num > b:
        break

print(ans)
n,k=map(int,input().split())
A=list(map(int,input().split()))
c=0
for i in range(len(A)):
  if A[i]>=K:
    c+=1
print(c)

### FIXED CODE ###

n,k=map(int,input().split())
A=list(map(int,input().split()))
c=0
for i in range(len(A)):
    if A[i]>=k:
        c+=1
print(c)
N = int(input())
S = []
for i in range(N):
    S.append(input())

COUNT = S.count("Y")

if COUNT > 0:
  print("Four")
else:
  print("Three")
    
    

### FIXED CODE ###

N = int(input())
S = list(input().split())

COUNT = S.count("Y")

if COUNT > 0:
  print("Four")
else:
  print("Three")
def mergesort(A, left, right):

    if left + 1 < right:
        mid = (left + right)/2
        
        mergesort(A, left, mid)
        mergesort(A, mid, right)
        merge(A, left, mid, right)


def merge(A, left, mid, right):
   
    n1 = mid -left
    n2 = right - mid
    L = []
    R = []
    x = [" "," ", 100000000000000000000]
    for i in range(0, n1):
        L.append(A[left + i])
    for i in range(0, n2):
        R.append(A[mid + i])
    L.append(x)
    R.append(x)
    i = 0
    j = 0
    for k in range(left, right):
        if int(L[i][-1]) <= int(R[j][-1]):
            A[k] = L[i]
            i = i + 1
        else:
            A[k] = R[j]
            j = j + 1
        



# kannsei
def partition(A, p, r):
    x = int(A[r-1][2])
    i = p - 1
    for j in range(p, r-1):
        if int(A[j][2]) <= x:
            i = i + 1
            A[i],A[j]=A[j], A[i]
            
    A[i+1], A[r-1]=A[r-1], A[i+1]
    
    return i+1

def quicksort(A, p, r):
    if p < r-1:
        q = partition(A, p, r)
        
        quicksort(A, p, q)
        quicksort(A, q+1, r)





if __name__ == "__main__":
    num = int(raw_input())
    num_list = []
    num_list1 = []
    for i in range(num):
        num_list.append(raw_input())
    num_list1 = list(num_list)
    quicksort(num_list, 0, len(num_list))
 
    mergesort(num_list1, 0, len(num_list1))
    
    if num_list == num_list1:
        print ("Stable")
    else:
        print ("NOt stable")

   print " \n".join(num_list)

### FIXED CODE ###

def mergesort(A, left, right):
 
    if left + 1 < right:
        mid = (left + right)/2
         
        mergesort(A, left, mid)
        mergesort(A, mid, right)
        merge(A, left, mid, right)
 
 
def merge(A, left, mid, right):

    n1 = mid -left
    n2 = right - mid
    L = []
    R = []
    x = "  10000000000"
    for i in range(0, n1):
        L.append(A[left + i])
    for i in range(0, n2):
        R.append(A[mid + i])
    L.append(x)
    R.append(x)
    i = 0
    j = 0
    for k in range(left, right):
        if int(L[i][2:]) <= int(R[j][2:]):
            A[k] = L[i]
            i = i + 1
        else:
            A[k] = R[j]
            j = j + 1
            
            
def partition(A, p, r):
    x = int(A[r-1][2:])
    i = p - 1
    for j in range(p, r-1):
        if int(A[j][2:]) <= x:
            i = i + 1
            A[i],A[j]=A[j], A[i]
             
    A[i+1], A[r-1]=A[r-1], A[i+1]
    return i+1
 
def quicksort(A, p, r):
    if p < r-1:
        q = partition(A, p, r)
         
        quicksort(A, p, q)
        quicksort(A, q+1, r)
 
 
 
 
if __name__ == "__main__":
    num = int(raw_input())
    num_list = []
    num_list1 = []
    for i in range(num):
        num_list.append(raw_input())
    num_list1 = list(num_list)
    quicksort(num_list, 0, len(num_list))
  
    mergesort(num_list1, 0, len(num_list1))
     
    if num_list == num_list1:
        print ("Stable")
    else:
        print ("Not stable")
    print "\n".join(num_list)
n = int(input())
a = n//4
b = n//7
ans = 0
for i in range(a+1):
    for j in range(b+1):
        if 4*i+7*j == n:
            ans = 1
if ans = 1:
  print('Yes')
else:
  print('No')        


### FIXED CODE ###

x=int(input())
t=0
while x>=0:
  if x%7==0:
    t=1
  x-=4
if t==0:
  print('No')
else: print('Yes')
n,a,b=map(int,input().split())
n=0
for i in range (1,n+1):
    result=sum(list(map(int,str(i))))
    if result>=a and result<=b:
        ans+=i
print(ans) 

### FIXED CODE ###

n,a,b=map(int,input().split())
ans=0
for i in range (1,n+1):
    result=sum(list(map(int,str(i))))
    if result>=a and result<=b:
        ans+=i
print(ans)
def minimumNumOfCandies(candies,atmostValue):
  candiesToEat = 0
  for i in range( 0 , len ( candies ) - 1 ) :
    if( candies[i] > atmostValue ) :
      candiesToEat = candiesToEat + ( candies[i] - atmostValue)
      candies[i] = candies[i] - ( candies[i] - atmostValue )
    if( candies[i] + candies[i + 1] > atmostValue ):
      candiesToEat = candiesToEat + ( candies[i + 1] - atmostValue )
      candies[i + 1] = candies[i + 1] - ( candies[i + 1] - atmostValue)
  return candiesToEat
n = list(int(i) for i in input())
candies = list( int (i) for i in input())
print(minimumNumOfCandies(candies,n[1]))

### FIXED CODE ###

def minimumNumOfCandies(candies,atmostValue):
  candiesToEat = 0
  for i in range( 0 , len ( candies ) - 1 ) :
    if( candies[i] > atmostValue ) :
      candiesToEat = candiesToEat + ( candies[i] - atmostValue)
      candies[i] = candies[i] - ( candies[i] - atmostValue )
    if( candies[i] + candies[i + 1] > atmostValue ):
      candiesToEat = candiesToEat + ( (candies[i + 1] + candies[i]) - atmostValue )
      candies[i + 1] = candies[i + 1] - ( (candies[i + 1] + candies[i])- atmostValue)
  return candiesToEat
n = list(int(i) for i in input().split())
candies = list( int (i) for i in input().split())
print(minimumNumOfCandies(candies,n[1]))
A, B, K = map(int, input().split())
AB = list(range(A, B+1))
ans = sorted(set(AB[K:]) | set(AB[:-K]))
 
for i in ans:
    print(i)

### FIXED CODE ###

a, b, k = map(int, input().split())

if b-a+1 <= 2*k:
    for num in range(a, b+1):
        print(num)
else:
    for num in range(a, a+k):
        print(num)
    for num in range(b-k+1,b+1):
        print(num)
x = int(input("x"))

if x >= 30:
    print("Yes")
Else:
    print("No")

### FIXED CODE ###

x = int(input(""))

if x >= 30:
    print("Yes")
else:
    print("No")
#coding: utf-8

h1 = int(input("H₁＝"))
m1 = int(input("M₁＝"))
h2 = int(input("H₂＝"))
m1 = int(input("H₂＝"))
k = int(input("k＝"))

Time = (h1 * 60 + m1) - (h2 * 60 + m2) - K
print(int(Time))


### FIXED CODE ###

#coding: utf-8
string = str(input())
X = 0
li = []
for a in range(len(string)):
    if string[a] == " ":
        li.append(string[X:a])
        X = a+1
li.append(string[X:])
for aa in range(len(li)):
    li[aa] = int(li[aa])
h1 = li[0]
m1 = li[1]
h2 = li[2]
m2 = li[3]
k = li[4]
Time = (h2 * 60 + m2) - (h1 * 60 + m1) - k
print(int(Time))
N=int(input())
d=[int(input()) for _ in range(N)]
print(len(set(d))

### FIXED CODE ###

N=int(input())
d=[int(input()) for _ in range(N)]
print(len(set(d)))
l,r=list(map(int, input().split()))
c=[0]*(r-l+1)
for i in range(l,r+1):
	c[i-l]=i%2019
minc=min(c)
print(minc*(minc+1)%2019)

### FIXED CODE ###

l,r=list(map(int, input().split()))
minmod=2018
if r-l>=2018:
	print(0)
else:
	for i in range(l,r+1):
		for j in range(i+1,r+1):
			minmod=min(minmod,(i*j)%2019)
	print(minmod)
def prime_numbers(N):
  A=list(range(2,N+1))
  p=list()
  while A[0]**2<=N:
    tmp=A[0]
    p.append(tmp)
    A=[e for e in A if e%tmp!=0]
  return p+A

n=int(input())
a=sorted(list(map(int,input().split())))
pri,prit=prime_numbers(a[-1])
ans=2
for i in prit:
  cnt=0
  for j in a:
    if i>j:
      continue
    if j%i==0:
      cnt+=1
  if cnt==n:
    ans=0
    break
  if cnt>=2:
    ans=1
if ans==2:
  print('pairwise coprime')
elif ans==1:
  print('setwise coprime')
else:
  print('not coprime')

### FIXED CODE ###

def resolve():
    import sys
    input = sys.stdin.readline
    n=int(input())
    a=sorted(list(map(int,input().split())))
    ma=a[-1]
    pn=[i for i in range(ma+1)]
    for i in range(2,ma//2+1):
      j=2
      while j*i<=ma:
        pn[j*i]=min(pn[j*i],i)
        j+=1
    chk=[0]*(ma+1)
    for i in a:
      if i==1:
        continue
      x=pn[i]
      chk[x]+=1
      while x!=i:
        while i%x==0:
          i//=x
        x=pn[i]
        chk[x]+=1
    ans=2
    for i in chk[2:]:
      if i==n:
        ans=0
        break
      if i>=2:
        ans=1
    if ans==2:
      print('pairwise coprime')
    elif ans==1:
      print('setwise coprime')
    else:
      print('not coprime')

if __name__ == '__main__':
    resolve()
a = list(input())
b = list(input())
c = list(input())

n = a[0]
del a[0]
if len(a) == 0:
    print("A")
while True:
    if n == "a":
        n = a[0]
        del a[0]
        if len(a) == 0:
            print("A")
            break
    elif n == "b":
        n = b[0]
        del b[0]
        if len(b) == 0:
            print("B")
            break
    elif n == "c":
        n = c[0]
        del c[0]
        if len(c) == 0:
            print("C")
            break


### FIXED CODE ###

a = list(input())
b = list(input())
c = list(input())

n = a[0]
if len(a) < 1:
    del a[0]

while True:
    if n == "a":
        n = a[0]
        del a[0]
        if len(a) == 0:
            print("A")
            break
    elif n == "b":
        n = b[0]
        del b[0]
        if len(b) == 0:
            print("B")
            break
    elif n == "c":
        n = c[0]
        del c[0]
        if len(c) == 0:
            print("C")
            break
def f1(x, y):
    if not x in data:
        data[x] = [y]
    else:
        data[x].append(y)
        
def f2():
    for i in range(1, w+1):
        f3(data[i][0], i, i)
    else:
        for a in ans:
            print a
        
def f3(a, b, c):
    for i, num in enumerate(data[a]):
        if num == b:
            if i+1 < len(data[a]):
                return f3(data[a][i+1], a, c)
            else:
                ans[a-1] = c
                break
        
w = int(raw_input())
n = int(raw_input())
ans = [0 for i in range(1, w+1)]
data = {}
for i in range(n):
    a, b = map(int, raw_input().split(','))
    f1(a, b)
    f1(b, a)
else:
    f2()

### FIXED CODE ###

ans = [i+1 for i in range(int(raw_input()))]
for i in range(int(raw_input())):
    a, b = map(int, raw_input().split(','))
    ans[b-1], ans[a-1] = ans[a-1], ans[b-1]
else:
    for a in ans:
        print a
def main():
    N, M = map(int, input().split())
    X = sorted(list(map(int, input().split())))

    if M == 1:
        print(0)
    elif N == 1:
        print(max(X) - min(X))
    else:
        dx = [abs(X[m] - X[m + 1]) for m in range(M - 1)]
        for _ in range(N - 1):
            dx.pop(dx.index(max(dx)))
        print(sum(dx))


main()


### FIXED CODE ###

def main():
    N, M = map(int, input().split())
    X = sorted(list(map(int, input().split())))

    if M == 1:
        print(0)
    elif N == 1:
        print(max(X) - min(X))
    else:
        if N > M:
            N = M
        dx = sorted([abs(X[m] - X[m + 1]) for m in range(M - 1)])
        print(sum(dx[:M - N]))


main()
N, C = map(int, input().split())
 
D = [ [int(i) for i in input().split()] for _ in xrange(C) ]
c = [ [int(i) for i in input().split()] for _ in xrange(N) ]
 
costD = [ [0, 0, 0] for _ in xrange(C)]
 
for c0 in xrange(C):
    for i in xrange(N):
        for j in xrange(N):
            costD[c0][(i+j)%3] += D[c[i][j]-1][c0]
 
kohoD = []
 
for c1 in xrange(C):
    for c2 in xrange(C):
        if c1 == c2:
            continue
        for c3 in xrange(C):
            if c1 == c3 or c2 == c3:
                continue
            kohoD += [(costD[c1][0] + costD[c2][1] + costD[c3][2])]
 
print(min(kohoD))

### FIXED CODE ###

import itertools
 
 
def main():
    N, C = map(int, input().split())
    D = [list(map(int, input().split())) for _ in range(C)]
    CC = [list(map(lambda x: int(x) - 1, input().split())) for _ in range(N)]
 
    cost = [[0 for _ in range(C)] for _ in range(3)]
    for c in range(C):
        for i in range(N):
            for j in range(N):
                cost[(i + j) % 3][c] += D[CC[i][j]][c]
 
    res = float("inf")
    color = [i for i in range(C)]
    for i, c in enumerate(list(itertools.permutations(color, 3))):
        tmp = 0
        for it in range(3):
            tmp += cost[it][c[it]]
        res = min(res, tmp)
 
    print(res)
 
main()
n=int(input())
p=list(map(int,input().split()))
new_p=p.reversesort()

for i in range(n-1):
    if p[i]<=p[i+1]:
        tmp=p[i]
        p[i]=p[i+1]
        p[i+1]=tmp
        break
if new_p==p:
    print('YES')
else:
    print('NO')

### FIXED CODE ###

n=int(input())
p=list(map(int,input().split()))
new_p=sorted(p)
cnt=0

for i in range(n):
    if p[i] != new_p[i]:
        cnt += 1
        
if cnt > 2:
    print('NO')
else:
    print('YES')
from collections import Counter
import itertools

N = int(input())
xy = [list(map(int, input().split())) for i in range(N)]

ptn=list(itertools.combinations(xy,2))
pq=[]
for idx,val in enumerate(ptn):
        pq.append(str(val[1][0]-val[0][0]) + 'x' + str(val[1][1]-val[0][1]))

cpq = Counter(pq)

for i in range(1,N):
        pqans=cpq.most_common(i)[0][0]
        if pqans != '0x0':
                redsc=cpq.most_common(i)[0][1]
                break


print(N-redsc)

### FIXED CODE ###

from collections import Counter
import itertools

N = int(input())
xy = [list(map(int, input().split())) for i in range(N)]
xy.sort()
if N == 1:
        print(1)
        exit()

ptn=list(itertools.combinations(xy,2))
pq=[]
for idx,val in enumerate(ptn):
        if val[1][0]-val[0][0] <= 0 and val[1][1]-val[0][1] <= 0:
                pq.append(str(abs(val[1][0]-val[0][0])) + 'x' + str(abs(val[1][1]-val[0][1])))
        else:
                pq.append(str(val[1][0]-val[0][0]) + 'x' + str(val[1][1]-val[0][1]))

cpq = Counter(pq)

# pqans=cpq.most_common(1)[0][0]
redsc=cpq.most_common(1)[0][1]

# p,q = map(int,pqans.split('x'))
print(N-redsc)
import numpy as np
c0= list(map(int, input().split(' ')))
c1= list(map(int, input().split(' ')))
c2= list(map(int, input().split(' ')))

C = np.array([c0, c1, c2])
if C[1][0] - C[0][0] == C[1][1]-C[0][1] == C[1][2] - C[0][2] and C[2][0] - C[0][0] == C[2][1]-C[0][1 ]== C[2][2] - C[0][2]  :
 print('Yes')
else:
 print('No')

### FIXED CODE ###

N = int(input())
A = int(input())
if A >= N % 500 :
 print('Yes')
else:
 print('No')
# sys.stdin.readline()
import sys
import math
input = sys.stdin.readline

n = input()
if n.count('0') >= or n.count('1') >= 3 or n.count('2') >= 3 or n.count('3') >= 3 or n.count('4') >= 3 or n.count('5') >= 3 or n.count('6') >= 3 or n.count('7') >= 3 or n.count('8') >= 3 or n.count('9'):
    ans = 'Yes'
else:
    ans = 'No'
print(ans)

### FIXED CODE ###

# sys.stdin.readline()
import sys
import math
input = sys.stdin.readline

n = input()
if '000' in n or '111' in n or '222' in n or '333' in n or '444' in n or '555' in n or '666' in n or '777' in n or '888' in n or '999' in n:
    ans = 'Yes'
else:
    ans = 'No'
print(ans)
from math import gcd

# = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
mA = max(A)
primenum = [2]
sgn = [-1 for _ in range(int(mA**0.5)+1)]
k = 3
while k**2 <= mA:
  if sgn[k] == -1:
    primenum.append(k)
    add = k*k
    ok = k
    while ok**2 <= mA:
      sgn[ok] = 1
      ok += add
  k += 2
#prime_num が用意されているとき
primecounter = [0 for _ in range(len(primenum))]
biggerprime = [0 for _ in range(mA//2+1)]
def factorization(n):
  M = n
  for k in range(len(primenum)):
    p = primenum[k]
    if p**2 > M:
      break
    else:
      if M%p == 0:
        if primecounter[k] == 0:
          primecounter[k] = 1
        else:
          return False
        while M%p == 0:
          M //= p

  if M > 1:
    if biggerprime[M] == 0:
      biggerprime[M] = 1
    else:
      return False
  return True



g = A[0]
flag = True
for k in range(N):
  a = A[k]
  g = gcd(g, a)
  if flag:
    flag = factorization(a)
  if flag == False:
    if g == 1:
      break


if flag:
  print('pairwise coprime')
  exit()
if g == 1:
  print('setwise coprime')
else:
  print('not coprime')


### FIXED CODE ###

from math import gcd

# = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
mA = max(A)
counter = [0 for _ in range(mA+1)]

primenum = [2]
sgn = [-1 for _ in range(int(mA**0.5)+1)]
k = 3
while k**2 <= mA:
  if sgn[k] == -1:
    primenum.append(k)
    add = k*k
    ok = k
    while ok**2 <= mA:
      sgn[ok] = 1
      ok += add
  k += 2
#prime_num が用意されているとき
def factorization(n):
  M = n
  for p in primenum:
    if p**2 > M:
      break
    else:
      if M%p == 0:
        if counter[p] == 0:
          counter[p] = 1
        else:
          return False
        while M%p == 0:
          M //= p

  if M > 1:
    if counter[M] == 0:
      counter[M] = 1
    else:
      return False
  return True



g = A[0]
flag = True
for k in range(N):
  a = A[k]
  g = gcd(g, a)
  if flag:
    flag = factorization(a)


if flag:
  print('pairwise coprime')
  exit()
if g == 1:
  print('setwise coprime')
else:
  print('not coprime')
import sys

readline = sys.stdin.buffer.readline


def main():
    N, K = map(int, readline().split())
    H = list(map(int, readline().split()))
    for i in range(K):
        H.append(10**10)

    dp = [10**10] * (N+K)
    dp[0] = 0

    for i in range(N):
        for k in range(1, K+1):
            dp[i+k] = min(dp[i+k], dp[i] + abs(H[i+k]-H[i]))

    print(dp[N-1])


main()


### FIXED CODE ###

import sys

import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def main():
    N, W = map(int, readline().split())
    WV = np.array([[int(x) for x in readline().split()] for _ in range(N)])

    dp = np.zeros([W+1], np.int64)

    for w, v in WV:
        np.maximum(dp[w:], dp[:-w] + v, out=dp[w:])

    print(np.max(dp))


main()
n = map(int,input().split())
lis = list(map(int,input().split()))
ans = 0
def f(x):
 if x%2:
  return(0)
 else:
  return(f(x//2)+1)
for i in range(n):
 ans += f(lis[i])
print(ans)

### FIXED CODE ###

n = int(input())
lis = list(map(int,input().split()))
ans = 0
def f(x):
 if x%2:
  return(0)
 else:
  return(f(x//2)+1)
for i in range(n):
 ans += f(lis[i])
print(ans)
a = [int(input())]
f = lambda n : n // 2 if n % 2 == 0 else 3 * n + 1
i = 2
while f(a[-1]) not in a:
    a.append(f(a[-1]))
    i += 1
print(i)

### FIXED CODE ###

a = list(map(int, input().split()))
print(a[0]*a[1]//2)
N=int(input)
S=list(input())

ans=[]
for i in S:
    if ord(i)+N>90:
        temp=chr(ord(i)+N-26)
        ans.append(temp)
    else:
        temp=chr(ord(i)+N)
        ans.append(temp)

f=''.join(ans)

print(f)

### FIXED CODE ###

N=int(input())
S=list(input())
 
ans=[]
for i in S:
    if ord(i)+N>90:
        temp=chr(ord(i)+N-26)
        ans.append(temp)
    else:
        temp=chr(ord(i)+N)
        ans.append(temp)
 
f=''.join(ans)
 
print(f)
a=int(input)
if a%2==0:
  print(a*a)
else:
  print((a-1)*a)

### FIXED CODE ###

a=int(input())
if a%2==0:
  print(int(a*a/4))
else:
  print(int(((a+1)*(a-1))/4))
lst=list(map(int,input().split()))


if abs(lst[0]-lst[2])<=lst[3] or (abs(lst[0]-lst[1])<=lst[3] and abs(lst[2]-lst[1])<=lst[3]:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

lst=list(map(int,input().split()))


if abs(lst[0]-lst[2])<=lst[3] or (abs(lst[0]-lst[1])<=lst[3] and abs(lst[2]-lst[1])<=lst[3]):
    print("Yes")
else:
    print("No")