Harryxun/stf_run huggingface dataset:
X, N = map(int, input().split())
P = list(map(int, input().split()))

lis = [1] * 100
print(lis)
for p in P: lis[p-1] -= 1
print(lis)

for i in range(50):
    up = X+i
    down = X-i
    if lis[down-1] == 1:
        print(down)
        exit()
    elif lis[up-1] == 1:
        print(up)
        exit()


### FIXED CODE ###

X, N = map(int, input().split())
P = list(map(int, input().split()))

lis = [1] * (201)
for p in P: lis[p+99] -= 1

for i in range(100+1):
    up = X+i
    down = X-i
    if lis[100+down-1] == 1:
        print(down)
        exit()
    elif lis[100+up-1] == 1:
        print(up)
        exit()
n = int(input())
a = list(map(int, input().split()))

counter = 0

while True:
    exist_odd = False

    for i in range(n):
        if (a[i] % 2 != 0):
            exist_odd = True

    if exist_odd:
        break

    for i in range(n):
        a[i] = a[i] // 2

    counter += 1

print(counter)

### FIXED CODE ###

print(input().count("1"))
number = int(input())
list = list(map(int, input().split()))
ls = sorted(list)
print(ls)
count = 0

for a in range(0, number - 2):
    num_a = ls[a]
    for b in range(a + 1, number - 1):
        num_b = ls[b]
        for c in  range(b + 1, number):
            num_c = ls[c]
            if num_a + num_b > num_c:
                count += 1

print(count)


### FIXED CODE ###

import re
count = input()
string = input()
result = 1
for num_word in range(0, len(string) - 1):
    if string[num_word] != string[num_word + 1]:
        result += 1
print(result)
#!/usr/bin/env python3
import sys


def gdp(n, dp, G):
    if dp[n]!=-1:
        return dp[n]

    if G[n]==[]:
        dp[n]=0
        return 0

    for i in G[n]:
        ll=gdp(i, dp, G)
        if dp[n]<ll+1:
            dp[n]=ll+1

    return dp[n]

def solve(N: int, M: int, x: "List[int]", y: "List[int]"):
    G=[[] for _ in range(N)]
    for i in range(M):
        G[x[i]-1].append(y[i]-1)

    dp=[-1]*N

    print(max(gdp(i, dp, G) for i in range(N)))

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    x = [int()] * (M)  # type: "List[int]"
    y = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, M, x, y)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
 
sys.setrecursionlimit(150000)

def gdp(n, dp, G):
    if dp[n]!=-1:
        return dp[n]
 
    if G[n]==[]:
        dp[n]=0
        return 0
 
    for i in G[n]:
        ll=gdp(i, dp, G)
        if dp[n]<ll+1:
            dp[n]=ll+1
 
    return dp[n]
 
def solve(N: int, M: int, x: "List[int]", y: "List[int]"):
    G=[[] for _ in range(N)]
    for i in range(M):
        G[x[i]-1].append(y[i]-1)
 
    dp=[-1]*N
 
    print(max(gdp(i, dp, G) for i in range(N)))
 
    return
 
 
# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    x = [int()] * (M)  # type: "List[int]"
    y = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, M, x, y)
 
if __name__ == '__main__':
    main()
n=int(input())
a=[i for i in input().split()]
print(len(set(a)))
print('YES' if len(set(a)==n) else 'NO')

### FIXED CODE ###

n=int(input())
a=[i for i in input().split()]

print('YES' if len(set(a))==n else 'NO')
print("error") if sum(input().split()) >= 10 else print(sum(input().split()))

### FIXED CODE ###

a, b = map(int, input().split()) 
if a + b >= 10:
  print("error") 
else:
  print(a + b)
a,b=map(int,input(),split())
if a-2b>=0:
  print(a-2b)
else a-2b<0:
  print(0)

### FIXED CODE ###

a,b=map(int,input().split())
if a-2*b>=0:
  print(a-2*b)
else:
  print(0)
N = int(input())
A = list(map(int,input().split()))

nodeS = [0 for i in range(N+1)]
nodeS[0] = 1

nodeM = nodeS[0]-A[0]

laS = [0 for i in range(N+1)]

laS[-1] = A[-1]
for i in range(N):
    laS[-2-i] = A[-2-i] + laS[-1-i]


for i in range(N):
    nodeS[i+1] = nodeM*2
    nodeM = nodeS[i+1] - A[i+1]
    if nodeS[i] >= laS[i]:
        j = i
        break
    if i == N-1:
        if nodeS[i+1] >= laS[i+1]:
            j = i+1
        else:
            print(-1)
            exit()

for i in nodeS:
    if i < 0:
        print(-1)
        exit()
ans = sum(nodeS[:j]) + sum(laS[j::])
print(ans)





### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
if N == 0:
    print(1 if A[0] == 1 else -1)
    exit()

nodeS = [0 for i in range(N+1)]
nodeS[0] = 1

nodeM = nodeS[0]-A[0]

laS = [0 for i in range(N+1)]

laS[-1] = A[-1]
for i in range(N):
    laS[-2-i] = A[-2-i] + laS[-1-i]


for i in range(N):
    nodeS[i+1] = nodeM*2
    nodeM = nodeS[i+1] - A[i+1]
    if nodeS[i] >= laS[i]:
        j = i
        break
    if i == N-1:
        if nodeS[i+1] >= laS[i+1]:
            j = i+1
        else:
            print(-1)
            exit()

for i in nodeS:
    if i < 0:
        print(-1)
        exit()

ans = sum(nodeS[:j]) + sum(laS[j:])
print(ans)
input()
A = list(set(map(int, input().split()))
N = len(A)

def gcd(x, y):
  while y != 0:
    x, y = y, x%y
  return x


if N <= 2:
  print(max(A))
else:
  max = 0
  for i in range(N):
    temp = A.pop(0)
    ans = gcd(A[0], A[1])
    for j in A[1:]:
      ans = gcd(ans, j)
    if max < ans:
      max = ans
    A.append(temp)
  print(max)

### FIXED CODE ###

l = list(map(int, input().split()))
print((l[2] // l[0]) * l[1], "")
a,b,c=map(int,input().split())
print(b*(t/a))

### FIXED CODE ###

a,b,t=map(int,input().split())
print(b*(t//a))
import sympy
N = int(input())
count = 0
for i in range(0,N):
    count = count + sympy.divisor_count(i)
print(count)

### FIXED CODE ###

N = int(input())
count = 0
for i in range(1,N):
    count = count + (N-1)//i
print(count)
# coding:utf-8


def inpl(): return list(map(int, input().split()))


H, W = inpl()
board = []
for i in range(H):
    board.append(inpl())

ans = []
for h in range(H):
    if h % 2 == 0:
        for w in range(W):
            if board[h][w] % 2 == 1:
                board[h][w] -= 1
                if w + 1 < W:
                    board[h][w + 1] += 1
                    ans.append([h + 1, w + 1, h + 1, w + 2])
                elif h + 1 < H:
                    board[h + 1][w] += 1
                    ans.append([h + 1, w + 1, h + 2, w + 1])
    else:
        for w in range(W)[::-1]:
            if board[h][w] % 2 == 1:
                board[h][w] -= 1
                if 0 < w - 1:
                    board[h][w - 1] += 1
                    ans.append([h + 1, w + 1, h + 1, w])
                elif 0 < h - 1:
                    board[h + 1][w] += 1
                    ans.append([h + 1, w + 1, h + 2, w + 1])

for a in ans:
    print(' '.join(map(str, a)))




### FIXED CODE ###

# coding:utf-8

INF = float('inf')


def inpl(): return list(map(int, input().split()))


dx = (1, 0, -1, 0)
dy = (0, 1, 0, -1)

H, W = inpl()
mass = []
coin = 0
for i in range(H):
    tmp = inpl()
    coin += sum(tmp)
    mass.append(tmp)

odd = []
for h in range(H):
    for w in range(W):
        if mass[h][w] % 2 == 1:
            odd.append([h, w])

count = 0
ans = []
odd.sort()
for i in range(H):
    for j in range(W):
        if mass[i][j] & 1:
            if j < W - 1:
                count += 1
                ans.append([i + 1, j + 1, i + 1, j + 2])
                mass[i][j] -= 1
                mass[i][j + 1] += 1
            elif i < H - 1:
                count += 1
                ans.append([i + 1, j + 1, i + 2, j + 1])
                mass[i][j] -= 1
                mass[i + 1][j] += 1

print(count)
for a in ans:
    print(' '.join(map(str, a)))
W , H, x, y、r = map(int, input().split())

if r <= x <= W -r:
    if r <= y ,= H -r:
        print("Yes")

else:
    print("No")



### FIXED CODE ###

W, H, x, y, r = map(int, input().split())

if r <= x and x <= (W - r):
    if r <= y and y <= (H - r):
        print("Yes")
    else:
        print("No")

else:
    print("No")
n = int(input())
s = input()
ans = 1
for i in range(n):
  if s[i] != s[i+1]:
    ans += 1
print(ans+1)

### FIXED CODE ###

n = int(input())
s = input()
ans = 1
for i in range(n-1):
  if s[i] != s[i+1]:
    ans += 1
print(ans)
import numpy as np

N,M = map(int,input().split())
Xs = sorted([int(i) for i in input().split()])

if N >= M:
    print(0)
else:

    margin = [Xs[i+1]-Xs[i] for i in range(len(Xs)-1)]
    point = []
    for i in range(N-1):
        p = np.argmax(margin)
        point.append(p)
        margin[p] = 0
    move = 0
    move += abs(Xs[point[0]] - Xs[0])
    for i in range(1,len(point)):
        move += abs(Xs[point[i]] - Xs[point[i-1]+1])
    move += abs(Xs[-1] - Xs[point[-1]+1])
    print(move)


### FIXED CODE ###

import numpy as np

N,M = map(int,input().split())
Xs = sorted([int(i) for i in input().split()])

if N >= M:
    print(0)
elif N == 1:
    print(Xs[-1]-Xs[0])
else:
    margin = [Xs[i+1]-Xs[i] for i in range(len(Xs)-1)]
    margin = [(i,x) for i,x in enumerate(margin)]
    point = [x[0] for x in sorted(margin,key=lambda x:x[1],reverse=True)[:N-1]]
    move = 0
    move += Xs[point[0]] - Xs[0]
    for i in range(1,len(point)):
        move += Xs[point[i]] - Xs[point[i-1]+1]
    move += Xs[-1] - Xs[point[-1]+1]
    print(move)
N, M =map(int,input().split())
class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        """
        x が属するグループを探索
        """
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        """
        x と y のグループを結合
        """
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]

    def is_same(self, x, y):
        """
        x と y が同じグループか否か
        """
        return self.find(x) == self.find(y)

    def get_size(self, x):
        """
        x が属するグループの要素数
        """
        x = self.find(x)
        return self.size[x]
uf = UnionFind(N)
cnt = 0
for i in range(M):
  x, y, z = map(int, input().split())
  if !uf.is_same(x, y):
    cnt += 1
    uf.union(x,y)
    
print(N-cnt)

### FIXED CODE ###

N, M =map(int,input().split())
class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        """
        x が属するグループを探索
        """
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        """
        x と y のグループを結合
        """
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]

    def is_same(self, x, y):
        """
        x と y が同じグループか否か
        """
        return self.find(x) == self.find(y)

    def get_size(self, x):
        """
        x が属するグループの要素数
        """
        x = self.find(x)
        return self.size[x]
uf = UnionFind(N)
cnt = 0
for i in range(M):
  x, y, z = map(int, input().split())
  if not uf.is_same(x-1, y-1):
    cnt += 1
    uf.union(x-1,y-1)
    
print(N-cnt)
from heapq import heappop, heapify, heappush


def main():
    n, m = map(int, input().split())
    work = [[] for _ in range(10 ** 4 + 1)]
    for _ in range(n):
        a, b = map(int, input().split())
        work[a].append(b)
    ans = 0
    q = []
    heapify(q)
    for i in range(1, m + 1):
        for w in work[i]:
            heappush(q, -w)
        if len(q) == 0:
            continue
        ans += heappop(q)
    ans *= -1
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

from heapq import heappop, heapify, heappush


def main():
    n, m = map(int, input().split())
    work = [[] for _ in range(10 ** 5 + 1)]
    for _ in range(n):
        a, b = map(int, input().split())
        work[a].append(b)
    ans = 0
    q = []
    heapify(q)
    for i in range(1, m + 1):
        for w in work[i]:
            heappush(q, -w)
        if len(q) == 0:
            continue
        ans += heappop(q)
    ans *= -1
    print(ans)


if __name__ == '__main__':
    main()
K=int(input())
A,B=map(int,input().split())
a=0
if i in range(A,B+1):
  if k%i==0:
    a+=1
if a==1:
  print("OK")
else:
  print("NG")

### FIXED CODE ###

k=int(input())
a,b=map(int,input().split())
s=""
for i in range(a,b+1):
  if i%k==0:
    s="OK"
    print(s)
    break
if s!="OK":
  print("NG")
print((int(input()+1)//2-1)

### FIXED CODE ###

n=int(input())
if n%2==0:
    print(n//2-1)
else:
    print((n-1)//2)
n=int(input())
lst=list(map(int,input().split()))
cnt=0
for i in range(5):
  if lst[i]!=i+1:
    cnt+=1
print("YES" if cnt<=2 else "NO") 

### FIXED CODE ###

n=int(input())
lst=list(map(int,input().split()))
cnt=0
for i in range(n):
  if lst[i]!=i+1:
    cnt+=1
print("YES" if cnt<=2 else "NO")
class Dice:
    def _init_ (self,data):
        self.data = data

    def move(self,direction):
        if direction == 'E':
            self.data[0],self.data[3],self.data[5],self.data[2] = \
                    self.data[3].self.data[5],self.data[2],self.data[0]
        elif direction == 'N':
            self.data[0],self.data[4],self.data[5],self.data[1] = \
                    self.data[4].self.data[5],self.data[1],self.data[0]
        elif direction == 'S':
            self.data[0],self.data[1],self.data[5],self.data[4] = \
                    self.data[4].self.data[0],self.data[1],self.data[5]
        elif direction == 'W':
            self.data[0],self.data[2],self.data[5],self.data[3] = \
                    self.data[2].self.data[5],self.data[3],self.data[0]

    def getTop(self):
        return self.data[0]

dice = Dice.Dice(input().split())
cmd = input()
for i in range(len(cmd)):
    dice.move(cmd[i])
    print(dice.getTop())

### FIXED CODE ###

class Dice:
    def __init__ (self,data):
        self.data = data

    def move(self,direction):
        if direction == 'E':
            self.data[0],self.data[3],self.data[5],self.data[2] = \
                    self.data[3],self.data[5],self.data[2],self.data[0]
        elif direction == 'N':
            self.data[0],self.data[4],self.data[5],self.data[1] = \
                    self.data[1],self.data[0],self.data[4],self.data[5]
        elif direction == 'S':
            self.data[0],self.data[1],self.data[5],self.data[4] = \
                    self.data[4],self.data[0],self.data[1],self.data[5]
        elif direction == 'W':
            self.data[0],self.data[2],self.data[5],self.data[3] = \
                    self.data[2],self.data[5],self.data[3],self.data[0]

    def getTop(self):
        return self.data[0]

dice = Dice(input().split())
cmd = input()
for i in range(len(cmd)):
    dice.move(cmd[i])
print(dice.getTop())
N, M = map(int, input().split())
p = []
S = []
for _ in range(M):
    a, b = input().split()
    p.append(int(a))
    S.append(b)

ans = [[] for i in range(N)]
WA, AC = 0, 0
for p, S in zip(p, S):
    if ans[p - 1].count("AC") != 0:
        pass
    else:
        ans[p - 1].append(S)
        if S == "WA":
            WA += 1
        if S == "AC"
            AC += 1

print(AC, WA)

### FIXED CODE ###

N, M = map(int, input().split())
Q = [list(map(str, input().split())) for _ in range(M)]

ans = [0] * N
AC = 0
WA = 0

for P in Q:
    p = int(P[0])
    S = P[1]
    if ans[p - 1] == "END":
        continue
    if S == "WA":
        ans[p - 1] += 1
    if S == "AC":
        WA += ans[p - 1]
        AC += 1
        ans[p - 1] = "END"


print(AC, WA)
x,y = map(int,input().split())
s=2*x-y
t=2*y-x
if s%3!=0 or s<0 or t%3!=0 or t<0:
  print(0)
else:
  import sys
  mod = 1000000007
  p = 1
  q = 1
  for i in range(s//3):
    p = (p*(n-i)) % mod
    q = (q*(i+1)) % mod
  print((p*pow(q, -1, mod)) % mod)

### FIXED CODE ###

def nCr(n, r, mod):
    x, y = 1, 1
    for i in range(1, r+1):
        x = x*(n+1-i)%mod
        y = y*i%mod
    return x*pow(y, mod-2, mod)%mod
a,b = map(int,input().split())
s=2*a-b
t=2*b-a
if s%3!=0 or s<0 or t%3!=0 or t<0:
  print(0)
else:
  print(nCr((s+t)//3,(t//3),10**9+7))
n,a = map(int,open(0).read())
print("Yes" if n%500 <= a else "No")

### FIXED CODE ###

n,a = map(int,open(0).read().split())
print("Yes" if n%500 <= a else "No")
n = int(input())
a = input().split()
pl = []
sb = []
for i in range(len(a)):
	pl.append(i+int(a[i])+1)
	if i - int(a[i]) > 1:
		sb.append(i-int(a[i])+1)


if len(sb) == 0:
	print('0')
else:

# spl = sorted(pl)
	isb = [int(i) for i in sb]
	ipl = [int(i) for i in pl]
	ssb = sorted(isb)
	t = min(ssb)
	tl = [0] * max(ipl)
	for i in ssb:
		if int(i)-1 < len(tl):
			tl[int(i)-1] += 1
	# print(pl)
	# print(sb)
	# print(tl)
	cnt = 0
	for i in pl:
		if int(i)-1 < len(tl):
			cnt += tl[int(i)-1]

	print(cnt)
	



### FIXED CODE ###

n = int(input())
a = input().split()
pl = []
sb = []
for i in range(len(a)):
	pl.append(i+int(a[i])+1)
	if i - int(a[i]) > 0:
		sb.append(i-int(a[i])+1)


if len(sb) == 0:
	print('0')
else:

# spl = sorted(pl)
	isb = [int(i) for i in sb]
	ipl = [int(i) for i in pl]
	ssb = sorted(isb)
	t = min(ssb)
	# tl = [0] * max(ipl)
	tl = [0] * 2000000	
	for i in ssb:
		if int(i)-1 < len(tl):
			tl[int(i)-1] += 1
	# print(pl)
	# print(sb)
	# print(tl)
	cnt = 0
	for i in pl:
		if int(i)-1 < len(tl):
			cnt += tl[int(i)-1]

	print(cnt)
N,M = map(int,input().split())
road = [[] for _ in range(N+1)]
for _ in range(M):
    x,y=map(int,input().split())
    road[x].append(y)
flag = [0]*(N+1)
dist = [0]*(N+1)
def distance(i):#地点iから終点までの最長距離
    if flag[i] == 1:
        return dist[i]
    
    if road[i] == []:#行き先がない
        return 0
    else:#行き先がある
        long_dist = 0
        for dirct in road[i]:
            tmp = 1 + distance(dirct)
            long_dist = max(long_dist,tmp)
    flag[i]=1
    dist[i] = long_dist
    return long_dist

ans = 0
for i in range(1,N+1):
    ans = max(ans,distance(i))
print(ans)


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**9)
N,M = map(int,input().split())
road = [[] for _ in range(N+1)]
for _ in range(M):
    x,y=map(int,input().split())
    road[x].append(y)
flag = [0]*(N+1)
dist = [0]*(N+1)
def distance(i):#地点iから終点までの最長距離
    if flag[i] == 1:
        return dist[i]
    
    if road[i] == []:#行き先がない
        return 0
    else:#行き先がある
        long_dist = 0
        tmp = 0
        for dirct in road[i]:
            tmp = 1 + distance(dirct)
            long_dist = max(long_dist,tmp)
        flag[i]=1
        dist[i] = long_dist
        return long_dist

ans = 0
for i in range(1,N+1):
    ans = max(ans,distance(i))
print(ans)
from functools import lru_cache

def main():
    n,m = map(int,input().split())
    A = []
    for _ in range(m):
        a = int(input())
        A.append(a)
    mod = 10**9+7
    @lru_cache(maxsize=1000)
    def root(n):
        if n==0 or n==1:
            return 1
        else:
            if n-1 in A and n-2 in A:
                return 0
            elif n-1 in A and n-2 not in A:
                return pow(root(n-2),1,mod)
            elif n-1 not in A and n-2 in A:
                return pow(root(n-1),1,mod)
            else:
                return pow(root(n-1)+root(n-2),1,mod)
    print(root(n))

if __name__ == "__main__":
    main()

### FIXED CODE ###

from functools import lru_cache

def main():
    n,m = map(int,input().split())
    import numpy as np
    ans = np.ones(n+1,dtype=int)*-1
    ans[0] = 1
    mod = 10**9+7
    for _ in range(m):
        a = int(input())
        ans[a]=0
    if ans[1]!=0:
        ans[1]=1
    for i in range(2,n+1):
        if ans[i]!=0:
            ans[i] = (ans[i-1]+ans[i-2])%mod
    print(ans[-1])
        

if __name__ == "__main__":
    main()
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
for i in range(1, N): A[i] += A[i - 1]
for i in range(1, M): B[i] += B[i - 1]
ans, j = 0, M - 1
for i in range(N):
    if A[i] > K: break
    while B[j] > K - A[i]: j -= 1
    ans = max(ans, i + j + 2)
    j = M - 1
print(ans)


### FIXED CODE ###

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a, b = [0], [0]
for i in range(N):
	a.append(a[i] + A[i])
for i in range(M):
	b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N + 1):
	if a[i] > K: break
	while b[j] > K - a[i]: j -= 1
	ans = max(ans, i + j)
print(ans)
M,N=map(int,input().split())
X = list(map(int,input().split()))
X.sort()
xdelta = []

for i in range(len(X)-1):
	xdelta.append(abs(X[i+1]-X[i]))

xdelta.sort()
#print(xdelta)

if xdelta == [] or N == 1:
	print(int(sum(map(abs,X))))
else:
	for i in range(M-1):
		xdelta.pop(-1)
	print(sum(xdelta))

### FIXED CODE ###

N,M=map(int,input().split())
X = list(map(int,input().split()))
X.sort()
xdelta = []

for i in range(len(X)-1):
	xdelta.append(abs(X[i+1]-X[i]))

xdelta.sort()

if N < M:
	if N == 1:
		print(sum(xdelta))
	else:
		for i in range(N-1):
			xdelta.pop(-1)
		print(sum(xdelta))
else:
	print(0)
from collections import deque
from heapq import heapify, heappop, heappush
N = int(input())
A = deque(map(int, input().split(' ')))
former_heap = list()
latter_heap = list()
for _ in range(N):
    former_heap.append(A.popleft())
    latter_heap.append(- A.pop())
heapify(former_heap)
heapify(latter_heap)

former_sum = sum(former_heap)
former_sum_list = [former_sum]
former_A = A.copy()
for k in range(N):
    new_a = former_A.popleft()
    heappush(former_heap, new_a)
    min_a = heappop(former_heap)
    former_sum += new_a - min_a
    former_sum_list.append(former_sum)

latter_sum = sum(latter_heap)
latter_sum_list = [latter_sum]
latter_A = A.copy()
for k in range(N):
    new_a = - latter_A.pop()
    heappush(latter_heap, new_a)
    min_a = heappop(latter_heap)
    latter_sum += new_a - min_a
    latter_sum_list.append(latter_sum)
latter_sum_list.reverse()

answer = max([former + latter for former, latter in zip(former_sum_list, latter_sum_list)])
print(answer)

### FIXED CODE ###

from collections import deque
from heapq import heapify, heappop, heappush
N = int(input())
tmp = list(map(int, input().split(' ')))
former_A = deque(tmp)
latter_A = deque(tmp.copy())
former_heap = list()
latter_heap = list()
for _ in range(N):
    former_heap.append(former_A.popleft())
    latter_heap.append(- latter_A.pop())
heapify(former_heap)
heapify(latter_heap)

former_sum = sum(former_heap)
former_sum_list = [former_sum]
for k in range(N):
    new_a = former_A.popleft()
    heappush(former_heap, new_a)
    min_a = heappop(former_heap)
    former_sum += new_a - min_a
    former_sum_list.append(former_sum)

latter_sum = sum(latter_heap)
latter_sum_list = [latter_sum]
for k in range(N):
    new_a = - latter_A.pop()
    heappush(latter_heap, new_a)
    min_a = heappop(latter_heap)
    latter_sum += new_a - min_a
    latter_sum_list.append(latter_sum)
latter_sum_list.reverse()

answer = max([former + latter for former, latter in zip(former_sum_list, latter_sum_list)])
print(answer)