Harryxun/stf_run huggingface dataset:
n,k = map(int,input().split())

x = list(map(int,input().split()))
ans = 100000000000000


for i in range(n-k+1):
	if x[i+k-1] <= 0:
		ans = min(ans,-x[i])
	elif x[i] >= 0:
		ans = min(x[i+k-1],ans)
	else:
		ans = min(x[i+k-1]-x[i]+min(abs(x[i]),x[i+k-1]))
print(ans)

### FIXED CODE ###

n,k = map(int,input().split())

x = list(map(int,input().split()))
ans = 100000000000000

a = 0
while a != n:
	if x[a] >= 0:
		break
	a += 1
for i in range(max(0,a-k),n-k+1):
	if x[i+k-1] <= 0:
		ans = min(ans,-x[i])
	elif x[i] >= 0:
		ans = min(x[i+k-1],ans)
	else:
		ans = min(x[i+k-1]-x[i]+min(-x[i],x[i+k-1]),ans)
print(ans)
import collections

n = int(input())
a = list(map(int,input().split()))
q = int(input())

collect_dict = dict(collections.Counter(a))

now = sum(a)

ans = []
for i in range(q):
    b, c = map(int,input().split())
    now -= collect_dict[b] * b
    tmp = collect_dict[b]
    collect_dict.pop(b)
    if c not in collect_dict.keys():
        collect_dict[c] = 0
    collect_dict[c] += tmp
    now += c * tmp
    ans.append(now)

for i in ans:
    print(i)

### FIXED CODE ###

import collections

n = int(input())
a = list(map(int,input().split()))
q = int(input())

collect_dict = dict(collections.Counter(a))

now = sum(a)

ans = []
for i in range(q):
    b, c = map(int,input().split())
    if b not in collect_dict.keys():
        ans.append(now)
        continue
    now -= collect_dict[b] * b
    tmp = collect_dict[b]
    collect_dict.pop(b)
    if c not in collect_dict.keys():
        collect_dict[c] = 0
    collect_dict[c] += tmp
    now += c * tmp
    ans.append(now)

for i in ans:
    print(i)
N=int(N)
S=[input() for i in range(N)]

A=S.count('AC')
B=S.count('WA')
C=S.count('TLE')
D=S.count('RE')

print('AC x',A)
print('WA x',B)
print('TLE x',C)
print('RE x',D)


### FIXED CODE ###

N=int(input())
S=[input() for i in range(N)]

A=S.count('AC')
B=S.count('WA')
C=S.count('TLE')
D=S.count('RE')

print('AC x',A)
print('WA x',B)
print('TLE x',C)
print('RE x',D)
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
b = [int(input()) for _ in range(N)]

field = 0
for v in b:
	for i in range(9):
		if A[i // 3][i % 3] == v:
			f|=1<<i
ans = 0
for v in [7,56,73,84,146,273,292,448]:
  ans |= f&v==v;
print('Yes' if ans else 'No')


### FIXED CODE ###

A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
b = [int(input()) for _ in range(N)]

field = 0
for v in b:
	for i in range(9):
		if A[i // 3][i % 3] == v:
			field = field | (1 << i)
ans = False
for v in sum([[273,84],sum([[73<<i,7<<i*3]for i in range(3)],[])],[]):
  ans = ans or field&v==v;
print('Yes' if ans else 'No')
a, b, c = map(int, input().split())
# import math
# left = a + b + 2 * math.sqrt(a * b)
left = 4 * a * b
right = (c - a - b) ** 2
if (c - a - b) >= 0　and left < right:
  print('Yes')
else:
  print('No')


### FIXED CODE ###

a, b, c = map(int, input().split())
# import math
# left = a + b + 2 * math.sqrt(a * b)
left = 4 * a * b
right = (c - a - b) ** 2
if (c - a - b) >= 0 and left < right:
  print('Yes')
else:
  print('No')
n = int(input())
for i in range(1, n+1):
  if i%3!==0 and i%5!==0:
    a+=i
print(i)

### FIXED CODE ###

n = int(input())
a=0
for i in range(1, n+1):
  if i%3!=0 and i%5!=0:
    a=a+i
print(a)
i = list(map(int,input().split()))
l = list(map(int,input().split()))
n = i[0]
x =i[1]

d = 0
count = 0
j = 0
while d <= x:
  count = count + 1
  d = d + l[j]
  j = j + 1
  

if count < n+1:
  print(count)
else:
  print(n+1)


### FIXED CODE ###

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

d = 0
count = 0

for i in range(len(l)):
  if d <= x:
  	d = d + l[i]
  	count = count + 1
  
if d <= x:
  count += 1
  
print(count)
n=int(input())
a,b,c,d=0,0,0,0
for i in range(n):
    if input()=='AC':a+=1
    elif input()=='WA':b+=1
    elif input()=='TLE':c+=1
    else:d+=1
print('AC','x',a)
print('WA','x',b)
print('TLE','x',c)
print('RE','x',d)

### FIXED CODE ###

n=int(input())
a,b,c,d=0,0,0,0
l=[input() for _ in range(n)]
for i in range(n):
    if l[i]=='AC':a+=1
    elif l[i]=='WA':b+=1
    elif l[i]=='TLE':c+=1
    else:d+=1
print('AC','x',a)
print('WA','x',b)
print('TLE','x',c)
print('RE','x',d)
N,M = map(int,input().split())
G = {}
for node in range(1,N+1):
	G[node] = set()
for _ in range(M):
	x,y = map(int,input().split())
	G[x].add(y)

maxpath = [-1 for _ in range(N+1)]

def maxpa(G,source,maxpath):
	#print(source)
	if maxpath[source] != -1:
		return maxpath[source]
	else:	
		if len(G[source]) == 0:
			maxpath[source] = 0
			return maxpath[source]
		else:	
			for ngbr in G[source]:
				maxpath[source] = max(maxpath[source],1+maxpa(G,ngbr,maxpath))
			return maxpath[source]

for i in range(1,N+1):
	if maxpath[i]==-1:
		maxpa(G,i,maxpath)

print(max(maxpath))

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**9)

N,M = map(int,input().split())
G = {}
for node in range(1,N+1):
	G[node] = set()
for _ in range(M):
	x,y = map(int,input().split())
	G[x].add(y)

maxpath = [-1 for _ in range(N+1)]

def maxpa(G,source,maxpath):
	if maxpath[source] != -1:
		return maxpath[source]
	else:	
		if len(G[source]) == 0:
			maxpath[source] = 0
			return maxpath[source]
		else:	
			for ngbr in G[source]:
				maxpath[source] = max(maxpath[source],1+maxpa(G,ngbr,maxpath))
			return maxpath[source]

for i in range(1,N+1):
	if maxpath[i]==-1:
		maxpa(G,i,maxpath)

print(max(maxpath))
a = list(map(int, input().strip().split(" ")))
a.append(0)
a.insert(0, 0)
s = [abs(j - i) for i, j in zip(a, a[1:])]
base = sum(s)
for i in range(1, n + 1):
    if min(a[i - 1], a[i + 1]) <= a[i] <= max(a[i - 1], a[i + 1]):
        print(base)
    elif max(a[i - 1], a[i + 1]) < a[i]:
        print(base - 2*abs(a[i] - max(a[i - 1], a[i + 1])))
    else:
        print(base - 2*abs(a[i] - min(a[i - 1], a[i + 1])))


### FIXED CODE ###

n = int(input().strip())
a = list(map(int, input().strip().split(" ")))
a.append(0)
a.insert(0, 0)
s = [abs(j - i) for i, j in zip(a, a[1:])]
base = sum(s)
for i in range(1, n + 1):
    if min(a[i - 1], a[i + 1]) <= a[i] <= max(a[i - 1], a[i + 1]):
        print(base)
    elif max(a[i - 1], a[i + 1]) < a[i]:
        print(base - 2 * abs(a[i] - max(a[i - 1], a[i + 1])))
    else:
        print(base - 2 * abs(a[i] - min(a[i - 1], a[i + 1])))
"""
KがAの最大公約数の倍数であれば実現可能。そうでなければ実現不可能。
"""
N,K = map(int,input().split())
A = list(map(int,input().split()))

def gcd(a,b):
    return a if b==0 else gcd(b,a%b)

g = gcd(A[0],A[1])
for i in range(2,N):
    g = gcd(g,A[2])

if K<=max(A) and K%g == 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

### FIXED CODE ###

import sys
sys.setrecursionlimit(2000000)
N,K = map(int,input().split())
A = list(map(int,input().split()))
def gcd(a,b):
    return a if b==0 else gcd(b,a%b)
if N ==1:
    g = A[0]
else:
    g = gcd(A[0],A[1])
    if N > 2:
        for i in range(2,N):
            g = gcd(g,A[i])
if K <= max(A) and K%g==0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
def f(n):
	res=0
	while n>0:
		res+=n%10
		n//=10
	return res

N=int(input())
print(x)
if N%x==0:
	print("Yes")
else:
	print("No")

### FIXED CODE ###

def f(n):
	res=0
	while n>0:
		res+=n%10
		n//=10
	return res

N=int(input())
x=f(N)
if N%x==0:
	print("Yes")
else:
	print("No")
d={}
try:
    while True:
        n=int(input())
        if n in d:
            d[n]+=1
        else:
            d[n]=1
except EOFError:
    pass
a=[]
m=max(d.value())
for key, value in d:
    if value == m:
        a.append(key)
a.sort()
for i in a:
    print(i)

### FIXED CODE ###

d={}
try:
    while True:
        n=int(raw_input())
        if n in d:
            d[n]+=1
        else:
            d[n]=1
except EOFError:
    pass
a=[]
m=max(d.values())
for key, value in d.items():
    if value == m:
        a.append(key)
a.sort()
for i in a:
    print i
a,b,k = map(int,input().split())
count = 0
gcd = []

if(a < b):
  tmp = a
  a = b
  b = tmp
  
for i in range(a):
  if(i != 0):
   if((a%i == 0)and(b%i == 0)):
    gcd.append(i)
 
print(gcd[-k])

### FIXED CODE ###

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

def gcd(a,b):
  while(b > 0):
   a,b = b,a%b
  return a

if(a < b):
  tmp = a
  a = b
  b = tmp
  
#a > b 
if(k > 1):
 for i in range(b+1):
  if(i != 0):
   if((a%i == 0)and(b%i == 0)):
    G.append(i)
 #print(G)
 print(G[-k]) 
elif(k == 1):
  print(gcd(a,b))
n, m = map(int, input().split())
l = [-1] * n
ans = 0
for _ in range(m):
    a, b = map(int, input().split())
    a = a - 1
    if l[a] == -1 or l[a] == b:
        l[a] = b
    else:
        print(-1)
        exit()

if n > 1 and l[0] == 0:
    print(-1)
elif n == 1:
    print(l[0])
else:
    for i in range(n):
        if i == 0 and l[0] == -1:
            l[0] = 1
        elif l[i] == -1:
            l[i] = 0
        # ans += l[i] * (10 ** (n - i - 1))
        ans += str(l[i])
    print(int(ans))


### FIXED CODE ###

n, m = map(int, input().split())
sl = []
cl = []
ans = [-1] * n
a = ""
for _ in range(m):
    s, c = map(int, input().split())
    sl.append(s)
    cl.append(c)
    if ans[s - 1] == -1:
        ans[s - 1] = c
    elif ans[s - 1] == c:
        continue
    else:
        ans[s - 1] = -10
        break

if ans.count(-10) > 0:
    print(-1)
else:
    if n == 1:
        if ans[0] == -1:
            print(0)
        else:
            print(ans[0])
    else:
        for i in range(n):
            if i != n - 1 and ans[i] == 0:
                print(-1)
                exit()
            elif ans[i] == -1 and i == 0:
                ans[i] = 1
            elif ans[i] == -1 and i != 0:
                ans[i] = 0
        for i in ans:
            a += str(i)
        print(a)
def back_oturigation(fee, coin_values, coin_nums):
    """
    1. ????????????????????????????????£??????????????????
    2. 1????????????????????????????????????????????????????????????
       ???????????§?????????????????????-> ?°????????????????????¶???????????????????
    3. 2????????????????????°?????????????????????????????????????????????
    """
    # 1.
    oturi = coin_values[0] * coin_nums[0] \
            + coin_values[1] * coin_nums[1] \
            + coin_values[2] * coin_nums[2] \
            + coin_values[3] * coin_nums[3] \
            - fee
    use_coins = [0] * len(coin_values)
    no_use_coins = [0] * len(coin_values)

    # 2.
    for i in range(len(coin_values) - 1, -1, -1):
        no_use_coins[i] = int(oturi / coin_values[i])
        oturi = oturi - (coin_values[i] * no_use_coins[i])

    # 3.
    result = ''
    for i in range(0, len(use_coins), 1):
        use_coins[i] = coin_nums[i] - no_use_coins[i]
        if use_coins[i] > 0:
            print(str(coin_values[i]) + ' ' + str(use_coins[i]))
            # result = result + str(coin_values[i]) + ' ' + str(use_coins[i]) + '\n'
            # return result

if __name__ == "__main__":
    total_fee = int(input('total_fee:'))

    while (total_fee != 0):
        coins = input('total_coins:')
        coins = coins.split(' ')  # 10, 50, 100, 500????????§????????????
        coins = [int(coin) for coin in coins]
        coin_values = [10, 50, 100, 500]
        back_oturigation(total_fee, coin_values, coins)

### FIXED CODE ###

import math
def back_oturigation(fee, coin_values, coin_nums):
    """
    1. ?????????????????????????????????£??????????????????
    2. 1????????????????????????????????????????????????????????????
       ????????????§?????????????????????-> ??°?????????????????????¶???????????????????
    3. 2?????????????????????°?????????????????????????????????????????????
    """
    # 1.
    oturi = coin_values[0] * coin_nums[0] \
            + coin_values[1] * coin_nums[1] \
            + coin_values[2] * coin_nums[2] \
            + coin_values[3] * coin_nums[3] \
            - fee

    use_coins = [0] * len(coin_values)
    no_use_coins = [0] * len(coin_values)
 
    # 2.
    for i in range(len(coin_values) - 1, -1, -1):
        no_use_coins[i] = int(oturi / coin_values[i])
        oturi = oturi - (coin_values[i] * no_use_coins[i])
 
    # 3.
    for i in range(0, len(use_coins), 1):
        use_coins[i] = coin_nums[i] - no_use_coins[i]
        if use_coins[i] > 0:
            print(str(coin_values[i]) + ' ' + str(use_coins[i]))
 
if __name__ == "__main__":
    first = True
    while (True):
        total_fee = int(input(''))
        if total_fee == 0:
            break
        if first:
            first = False
        else:
            print('')
        coins = input('')
        coins = coins.split(' ')  # 10, 50, 100, 500?????????§????????????
        coins = [int(coin) for coin in coins]
        coin_values = [10, 50, 100, 500]
        back_oturigation(total_fee, coin_values, coins)
num = list(map(int,input().split()))
word = [input for i in range(n[0])]
print(''.join(sorted(num)))

### FIXED CODE ###

n = list(map(int,input().split()))
word = [input() for i in range(n[0])]
print(''.join(sorted(word)))
from sys import setrecursionlimit
setrecursionlimit(100000)

nVertices, nEdges = map(int, input().split())
g = [[] for _ in range(nVertices + 1)]
for _ in range(nEdges):
    u, v, _ = map(int, input().split())
    g[u].append(v)
    g[v].append(u)

def dfs(v):
    visited[v] = True
    for to in g[v]:
        if not visited[to]:
            dfs(to)

cnt = 0
visited = [False] * (nVertices + 1)
for v in range(1, nVertices + 1):
    if not visited[v]:
        dfs(v)
        cnt += 1
print(cnt)

### FIXED CODE ###

from sys import setrecursionlimit
setrecursionlimit(100000)
from collections import deque

nVertices, nEdges = map(int, input().split())
g = [[] for _ in range(nVertices + 1)]
for _ in range(nEdges):
    u, v, _ = map(int, input().split())
    g[u].append(v)
    g[v].append(u)

def dfs(v):
    visited[v] = True
    for to in g[v]:
        if not visited[to]:
            dfs(to)

def bfs(v):
    visited[v] = True
    q = deque([v])
    while q:
        cur = q.pop()
        for to in g[cur]:
            if not visited[to]:
                visited[to] = True
                q.appendleft(to)

cnt = 0
visited = [False] * (nVertices + 1)
for v in range(1, nVertices + 1):
    if not visited[v]:
        bfs(v)
        cnt += 1
print(cnt)
n = int(input())
h = list(map(int, input().split()))
gap = [0]
mt = []
va = []
i = 0
while i+1 <= len(h)-1:
    if h[i+1]-h[i] != 0:
        gap.append(h[i+1]-h[i])
        i += 1
    else:
        h.pop(i+1)
for i in range(h)    
    if gap[i] >= 0: 
        if gap[i+1] < 0:
            mt.append(h[i])
    else:
        if gap[i+1] > 0:
            va.append(h[i])
if gap[-1] > 0 :
    mt.append(h[-1])
if mt == []:
    mt.append(h[0])
ans = 0
for x in mt:
    ans += x
for x in va:
    ans -= x
print(ans)

### FIXED CODE ###

n = int(input())
h = list(map(int, input().split()))
gap = [0]
mt = []
va = []
i = 0
while i+1 <= len(h)-1:
    if h[i+1]-h[i] != 0:
        gap.append(h[i+1]-h[i])
        i += 1
    else:
        h.pop(i+1)
for i in range(len(h)-1):    
    if gap[i] >= 0: 
        if gap[i+1] < 0:
            mt.append(h[i])
    else:
        if gap[i+1] > 0:
            va.append(h[i])
if gap[-1] > 0 :
    mt.append(h[-1])
if mt == []:
    mt.append(h[0])
ans = 0
for x in mt:
    ans += x
for x in va:
    ans -= x
print(ans)
def f(n):
  if n=1:
    return(1)
  else:
    f(n)=2f(n-1)+1
    return f(n)
n=int(input())
print(f(n))

### FIXED CODE ###

life=int(input())
count=0
while life>=1:
    life=life/2
    count+=1
print(2**count-1)
a,b,c=map(int,input().split())
numlist=[a,b,c]
numlist.sort()
print numlist

### FIXED CODE ###

a,b,c=map(int,input().split())
d=sorted([a,b,c])
print ("{0} {1} {2}".format(d[0],d[1],d[2]))
import itertools
import operator

dataset = []
while True:
    try:
        dataset.append(input())
    except EOFError:
        break

for item in dataset:
    a, b, c, d, e, f = [int(i) for i in item.split()]
    e = e * (a/d)
    f = f * (a/d)

    y = (c - f)/(b-e)
    x = (c - b*y) / a 

    print("{:.3f} {:.3f}".format(x, y))

### FIXED CODE ###

import sys
dataset = sys.stdin.readlines()

for item in dataset:
    a, b, c, d, e, f = list(map(int, item.split()))

    y = (c * d - f * a)/(b * d - e * a)
    x = (c * e - b * f) / (a * e - b * d)
    if x == 0:
        x = 0
    print("{:.3f} {:.3f}".format(x, y))
import sys
import math
from collections import deque
import copy

N, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(N)]
INF = 10 ** 9 + 7
dp = [[INF for _ in range(N * 300 + 1)] for _ in range(N + 1)]

for i in dp:
    i[0] = 0
for i in range(1, wv[0][1] + 1):
    dp[1][i] = wv[0][0]

for i in range(2, N + 1):
    for l in range(1, N * 300 + 1):
        if l - wv[i - 1][1] >= 0:
            dp[i][l] = min(dp[i - 1][l], dp[i - 1][l - wv[i - 1][1]] + wv[i - 1][0])
        elif dp[i][l] == 10 ** 9 + 7:
            dp[i][l] = min(wv[i - 1][0], dp[i - 1][l])
        else:
            dp[i][l] = dp[i - 1][l]
for i in range(N * 300):
    if dp[-1][i] <= W < dp[-1][i + 1]:
        print(i)
        break
    elif i == N*300-1:
        print(i)


### FIXED CODE ###

import sys
import math
from collections import deque
import copy

INF = 10 ** 9 + 7
N, W = map(int, input().split())
weight = []
value = []
for i in range(N):
    tempW, tempV = map(int, input().split())
    weight.append(tempW)
    value.append(tempV)

dp = [[INF for _ in range(N * 1000 + 1)] for _ in range(N + 1)]
dp[0][0] = 0

for i in range(1, N + 1):
    for l in range(N * 1000 + 1):
        if l - value[i - 1] >= 0:
            dp[i][l] = min(dp[i - 1][l], dp[i - 1][l - value[i - 1]] + weight[i - 1])
        else:
            dp[i][l] = dp[i - 1][l]
for i in range(N * 1000 + 1):
    if dp[N][i] <= W:
        ans = i
print(ans)
let test a b =
  max (max (a+b) (a-b)) (a*b);;

Scanf.sscanf (read_line ()) "%d %d" (fun a b -> test a b);;

### FIXED CODE ###

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

X = K+N
Y = K-N
Z = K*N

print(max(X,Y,Z))
n=int(input())
m=int(input())
if n>1:
    c=int((n*(n-1))/2)
else:
    c=0
if m>1:
    d=int((m*(m-1))/2)
else:
    d=0
print(c+d)


### FIXED CODE ###

n,m=map(int,input().split())
print((n*(n-1)+m*(m-1))//2)
N, M = map(int, input().split())
s = [list(map(int, list(input().split()))) for i in range(M)]

ans = [-1] * M
for i in s:
    if ans[i[0] - 1] != -1 and ans[i[0] - 1] != i[1]:
        print(-1)
        return 
    ans[i[0] - 1] = i[1]

ans = [int(str(a).replace('-1', '0')) for a in ans]
res = ''.join((map(str, ans)))
if int(res) != 0:
    print(int(res))
else:
    print(-1)

### FIXED CODE ###

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

ans = [-1] * N

for i in s:
    if ans[i[0] - 1] != -1 and ans[i[0] - 1] != i[1]:
        print(-1)
        exit()
    ans[i[0] - 1] = i[1]

if M == 0 and N != 1:
    ans[0] = 1
tmp = int(''.join((map(str, [int(str(a).replace('-1', '0')) for a in ans]))))
if N >= 2 and ans[0] == -1:
    ans[0] = 1

ans = [int(str(a).replace('-1', '0')) for a in ans]

res = ''.join((map(str, ans)))
if int(res) >= 0 and len(str(int(res))) == N:
    print(int(res))
else:
    print(-1)
import collections

N = int(input())
a = list(map(int,input().split()))
a = collections.Counter(a)

value, count = list(a.keys()), list(a.values())

if len(value)<3:
    if len(value)==1
        if sum(a)==0:
            print('Yes')
        else:
            print('No')

    if len(value)==2
        if 0 in value:
            if count[0]==N/3 or count[1]==N/3:
                print('Yes')
            else:
                print('No')

        else:
            print('No')

if len(value)>=3:
    if count[0]+count[1]+count[2] == N:
        if value[0]^value[1]^value[2] == 0:
            if count[0]==count[1]==count[2]:
                print('Yes')
            else:
                print('No')

    else:
        print('No')


### FIXED CODE ###

import collections

N = int(input())
a = list(map(int,input().split()))
a = collections.Counter(a)

value, count = list(a.keys()), list(a.values())

if len(value)<3:
    if len(value)==1:
        if sum(a)==0:
            print('Yes')
        else:
            print('No')

    if len(value)==2:
        if 0 in value:
            if count[0]==N/3 or count[1]==N/3:
                print('Yes')
            else:
                print('No')

        else:
            print('No')

if len(value)>=3:
    if count[0]+count[1]+count[2] == N:
        if value[0]^value[1]^value[2] == 0:
            if count[0]==count[1]==count[2]:
                print('Yes')
            else:
                print('No')
        else:
            print('No')
    else:
        print('No')
N, M= (int(i) for i in input().split())
if (N<M)
    X = list(int(i) for i in input().split())
    X.sort()
    Y = [X[i] - X[i-1] for i in range(1, len(X))].sort()
    print(sum(Y[0:M-N]))
else:
    print(0)


# -100 | -10 -3 0 2 9 | 17
# 0 | 90 97 100 102 109 | 117
#   90  7  3   2   7    6
# 90 7 7 6 3 2


"""
N個のコマ：N-1個の閉経路が存在する
各座標の距離を求める(M-1個)
M：座標の数　N:駒の数
移動しなくても通っている座標の数: N
M - N
"""



### FIXED CODE ###

N, M= (int(i) for i in input().split())
if (N<M):
    X = list(int(i) for i in input().split())
    X.sort()
    Y = [X[i] - X[i-1] for i in range(1, len(X))]
    Y.sort()
    print(sum(Y[0:M-N]))
else:
    print(0)


"""
N個のコマ：N-1個の閉経路が存在する
各座標の距離を求める(M-1個)
M：座標の数　N:駒の数
移動しなくても通っている座標の数: N
M - N
"""
def f(n, x):
   if (n < 0):
      return(0)
   else:
      return(n//x+1)

print(f(b, x) - f(a-1, x))


### FIXED CODE ###

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

def f(n, x):
   if (n < 0):
      return(0)
   else:
      return(n//x+1)

print(f(b, x) - f(a-1, x))
import sys
from bisect import bisect.bisect_right 
A, B, Q = map(int, input().split())
INF = 10 ** 18
s = [-INF] + [sys.stdin.readline() for i in range(A)] + [INF]
t = [-INF] + [sys.stdin.readline() for i in range(B)] + [INF]
for q in range(Q):
    x = int(input())
    b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
    #print(b,d)
    res = INF
    for S in [s[b - 1], s[b]]:
        for T in [t[d - 1], t[d]]:
            d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
            res = min(res, d1, d2)
    print(res)



### FIXED CODE ###

import bisect
A, B, Q = map(int, input().split())
INF = 10 ** 18
s = [-INF] + [int(input()) for i in range(A)] + [INF]
t = [-INF] + [int(input()) for i in range(B)] + [INF]
for q in range(Q):
    x = int(input())
    b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
    #print(b,d)
    res = INF
    for S in [s[b - 1], s[b]]:
        for T in [t[d - 1], t[d]]:
            d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
            res = min(res, d1, d2)
    print(res)
while True:
  x = input()
  y = input()
  if x == 0 and y == 0:
    break
  elif x < y:  
      print "%d %d" % (x, y)
  elif x > y:  
      print "%d %d" % (y, x)

### FIXED CODE ###

while True:
  x,y = map(int,raw_input().split())
  if x == y == 0:
    break
  print min(x,y), max(x,y)
N=int(input())
K=int(input())
list1=list(input())
SUM=0
for i in range(N):
  x=int(list1[i])
  if x>K-x:
    SUM+=2*(K-x)
  else:
    SUM+=2*x
print(SUM)    

### FIXED CODE ###

N=int(input())
K=int(input())
SUM=0
list1=list(map(int,input().split()))
for i in range(N):
  x=list1[i]
  if x>K-x:
    SUM+=2*(K-x)
  else:
    SUM+=2*(x)
print(SUM)
n = int(input())
if n ==1:
    print("Hello World")
else:
    a,b = map(int,input().split())
    print(a+b)

### FIXED CODE ###

n = int(input())
if n ==1:
    print("Hello World")
elif n ==2:
    a = int(input())
    b = int(input())
    print(a+b)
N = int(raw_input())
print(N/3)


### FIXED CODE ###

N = int(input())
print(N/3)
A = []
n = int(raw_input())
stack = []
for i in range(n):
	A.append(raw_input())

for i in A:
	if "insert" in i:
		stack.insert(0, int(i[7:]))
	elif "delete " in i and len(stack) > 0:
		stack.remove(int(i[7:]))
	elif "deleteFirst" in i and len(stack) > 0:
		stack.pop(0)
	elif "deleteLast" in i and len(stack) > 0:
		stack.pop()
if len(stack) > 0:
    print " ".join(map(str, stack))

### FIXED CODE ###

from collections import deque
n = int(raw_input())
stack = deque()
for i in range(n):
	i = raw_input()
	if "insert" in i:
		stack.appendleft(int(i[7:]))
	elif "delete " in i:
		if int(i[7:]) in stack:
		    stack.remove(int(i[7:]))
	elif "deleteFirst" in i:
		stack.popleft()
	elif "deleteLast" in i:
		stack.pop()
print " ".join(map(str, stack))