peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
n,m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]

ans = ["0"] * n
if n>=2: ans[0] = "1"

ok = True
for s,c in sc:
    if s-1==0 and n>=2:
        if ans[s-1] == "1" or ans[s-1] == str(c): ans[s-1] = str(c)
        else: ok = False
    else:
        if ans[s-1] == "0" or ans[s-1] == str(c): ans[s-1] = str(c)
        else: ok = False

if n>=2:
    if ans[0] == "0": ok = False
print(-1 if not ok else "".join(ans))
# Judge status: Wrong Answer
a,b,c = map(int,input().split())
d=[a,b,c]
d =list(set(d))
print(d)
# Judge status: Accepted
r,g,b = map(str, input().split())
rgb = int(r+g+b)
print("YES") if rgb % 4 == 0 else print("NO")
# Judge status: Accepted
a,b=map(int,input().split())

if a%3==0 or b%3==0 or (a+b)%3==0:
    print("Possible")
else:
    print("Impossible")
# Judge status: Accepted
s = input()
for i in range(len(s)):
    for j in range(len(s) - 1):
        S = s[:j] + s[j+i:]
        if S == 'keyence':
            print('YES')
            exit()
else:
    print('NO')
# Judge status: Accepted
A = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
B = set([int(input()) for _ in range(n)])

cr1 = {A[0][0], A[1][1], A[2][2]}
cr2 = {A[2][0], A[1][1], A[0][2]}
main_list= [cr1, cr2]

R = [set([A[i][j] for j in range(3)]) for i in range(3)]
C = [set([A[i][j] for i in range(3)]) for j in range(3)]
main_list.extend(R)
main_list.extend(C)

for D in main_list:
  if D.issubset(B):
    print('Yes')
    quit()

print('No')
# Judge status: Accepted
#!/usr/bin/env python3

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


ans = S + T
end = N
for i in range(N):
    if S[i:] == T[:end]:
        ans = S + T[end:]
        break

    end -= 1

print(len(ans))
# Judge status: Accepted
n = int(input())
l = [int(_) for _ in input().split()]
ans = float('inf')
for i in range(n):
    ans = min(ans, abs(sum(l[:i]) - sum(l[i:])))
print(ans)
# Judge status: Wrong Answer
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    X = [int(x) for x in input().split()]

    X_sorted = sorted(X)
    a = X_sorted[N // 2]
    b = X_sorted[(N // 2) - 1]
    for i in range(N):
        if X[i] == a:
            print(b)
        else:
            print(a)



if __name__ == '__main__':
    main()
# Judge status: Accepted
x = int(input())

for i in range(-500, 500):
    for j in range(-500, 500):
        if i**5-j**5 == x:
            a = i
            b = j
            break
print(a, b)
# Judge status: Accepted
S=input()
N=len(S)
ans=S[0]
for i in range(1,N):
    if i%2==1:
        continue
    T=S[:i]
    T1=T[:i//2]
    T2=T[i//2:]
    if T1==T2:
        ans=T
        #print(T1,T2)
print(len(ans))
# Judge status: Accepted
from sys import stdin
import math

[N, x] = list(map(int, stdin.readline().rstrip().split()))
a = list(map(int, stdin.readline().rstrip().split()))

a_sorted = sorted(a)


count=0
for i in range(N):
    #x -= a_sorted[i]
    x = x - a_sorted[i]
    if x >=0:
        count += 1
    else:
        break

if x > 0:
    count -= 1

print(count)
# Judge status: Accepted
N = int(input())

f = False
for i in range(1,10):
  for j in range(1,10):
    if i * j == N:
      f = True
      
print('Yes') if f else print('No')
# Judge status: Accepted
#!/usr/bin/env python3

X = int(input())

ret = 0
for i in range(1, 1001):
    for j in range(2, 20):
        if i**j <= X:
            ret = max(i**j, ret)

print(ret)
# Judge status: Wrong Answer
A,V=map(int,input().split())
B,W=map(int,input().split())
T=int(input())
if V!=W:
    if abs(A-B)/abs(V-W)<=T:
        print('YES')
else:
    print('No')
# Judge status: Accepted
a=[int(input()) for i in range(6)]
for i in range(5):
    for j in range(i+1,5):
        if a[j]-a[i]>a[5]:
            print(":(")
            exit()
print("Yay!")
# Judge status: Accepted
import collections
n = int(input())
s = [''] + list(input())
cnt_1 = collections.Counter(s)

sub = 0
for j in range(1, (n+1)//2):
    for i in range(1, n-2*j+1):
        tmp = s[i] + s[i+j] + s[i+j*2]
        cnt_2 = collections.Counter(tmp)
        if cnt_2['R'] == 1 and cnt_2['G'] == 1 and cnt_2['B'] == 1:
            sub += 1

print((cnt_1['R']*cnt_1['G']*cnt_1['B'])-sub)
# Judge status: Wrong Answer
a,b,c,k = map(int,input().split())

if k <= a + b:
    print(a)
else:
    print(2*a - k + b)
# Judge status: Accepted
# solution

data=input()

k=int(input())

for i,c in enumerate(data):
  if c!='1' or i>=k-1:
    break

print(c)
# Judge status: Accepted
n,m = map(int,input().split())
if n ==m:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
from collections import deque

K = int(input()) 
a = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])

for i in range(K-1):
    j = a.popleft()
    if j%10 != 0:
        a.append((10*j) + ((j%10) -1))
        
    a.append((10*j)+j%10)
    
    if j%10 != 9:
        a.append((10*j) +((j%10)+1))
    
print(a.popleft())
# Judge status: Accepted
#B
import math
n = int(input())
w = list(map(int, input().split()))
min=float('inf')
for t in range(1,n):
    a = sum(w[:t])
    b = sum(w[t:])
    # print(a, b)
    if min > abs(a - b):
        min = abs(a - b)
print(min)
# Judge status: Accepted
x,y,z=map(int,input().split())

res=x-z
ans=0
while res>=y+z:
    res-=(y+z)
    ans+=1
print(ans)
# Judge status: Wrong Answer
a , b , c = map(int, input().split())
for i in range(b):
	if i == b:
		print('NO')
		break
	if a*(i+1)%b==c:
		print('YES')
		break
# Judge status: Accepted
x = int(input())
for i in range(-2*10**2,2*10**2):
    for j in range(-2*10**2,2*10**2):
        if i**5- j**5 ==x:
            print(i,j)
            exit()
        elif j**5 - i**5 == x:
            print(j,i)
            exit()
# Judge status: Accepted
S = input()
T = input()
s = []
t = []
for i in range(len(S)):
  s.append(S[i])
  t.append(T[i])
flag = 0
if s == t:
  print("Yes")
  flag += 1
else:
  for i in range(len(s)):
    A = s[0]
    s.remove(A)
    s.append(A)
    if s == t:
      print("Yes")
      flag += 1
      break
if flag == 0:
  print("No")
# Judge status: Accepted
n,x=map(int,input().split())
a=list(map(int,input().split()))

cnt=0
for i in range(1,n):
    v = a[i]+a[i-1]-x
    if v>0:
        cnt+=v
        if a[i]>=v:
            a[i]-=v
        else:
            v-=a[i]
            a[i]=0
            a[i-1]-=v
        
print(cnt)
# Judge status: Accepted
k,x=map(int,input().split())
l=[]
for i in range(x-k+1,x+k):
  l.append(str(i))
print(' '.join(l))
# Judge status: Wrong Answer
List = list(map(int, input().split()))
List.sort()
res = List[2]-List[1]
List[1] = List[2]
List[0] += res
mid = List[2] - List[0]
if mid % 2 == 1:
  res += mid //2 +1
else:
  res += mid //2
print(res)
# Judge status: Wrong Answer
n = int(input())
list = []
list1 = []
list2 = []
list3 = []
c = 0
a = input().split()
for i in range(0, len(a)):
    list1.append(int(a[i]))
for j in range(1, 100):
    for item in list1:
        c = c+ (item-j)**2
    list2.append(c)
l = len(list2)
for z in range(0, l-1):
    list3.append(list2[z+1]-list2[z])
list3.sort()
print(list3[0])
# Judge status: Accepted
N=int(input())
ans=""
for i in range(1,10000):
   tmp=2**i
   if N%tmp==2**(i-1):
      N-=(-2)**(i-1)
      ans="1"+ans
   else:
      ans="0"+ans
   if N == 0:
      break
print(ans)
# Judge status: Accepted
from sys import setrecursionlimit, exit
setrecursionlimit(1000000000)

def main():
    a = 100
    x = int(input())
    ans = 0
    while a < x:
        a += a // 100
        ans += 1
    print(ans)

main()
# Judge status: Accepted
import math

N = int(input())

A_list = list()
B_list = list()
A_list.append(0)
B_list.append(0)

for i in range(N):
    A,B = map(int, input().split())
    A_list.append(A)
    B_list.append(B)

#末尾から考える
ans = 0
for i in range(N):
    A = A_list.pop(-1)
    B = B_list.pop(-1)
    #print(A,B,"→",end="")
    A += ans
    goal = B*math.ceil(A/B)
    #print(":",goal)
    ans += goal - A
    
print(ans)
# Judge status: Wrong Answer
s = input()
start = -float('inf')
best_length = -float('inf')
for i,w in enumerate(s):
  if w=='A' and start < 0:
    start = i
  elif w=='Z':
    length = i - start + 1
    if length > best_length:
      best_length = length
print(best_length if best_length > 0 else 0)
# Judge status: Wrong Answer
N = int(input())
if(not N % 10): print(N)
ans = 0
while(N > 0):
    ans += N % 10
    N //= 10
print(ans)
# Judge status: Accepted
import sys


sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N, K = map(int, input().split())
    D = [1] * (N + 1)
    D[0] = 0
    for _ in range(K):
        d = int(input())
        A = list(map(int, input().split()))
        for a in A:
            D[a] = 0
    print(sum(D))


if __name__ == "__main__":
    main()
# Judge status: Accepted
import sys
from collections import Counter
from collections import deque
import math
import bisect
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))


n=int(input())
l=[int(input()) for i in range(n)]
ans=0
c=0
for i in range(n):
    if l[i]==0:
        ans+=c//2
        c=0
    else:
        c+=l[i]
ans+=c//2
print(ans)
# Judge status: Wrong Answer
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**6)
from math import gcd,ceil

def lcm(a,b):return a*b//gcd(a,b)
x=int(input().rstrip())
print(360//x if 360%x==0 else ceil(360/x)*(lcm(360,x)//360))
# Judge status: Accepted
# AtCoder
s = list(map(str, input()))
n = len(s)

for i in range(2**3):  # 2の選ぶものの個数乗
    ops = []
    for j in range(3):
        if ((i >> j) & 1):
            ops.append('+')
        else:
            ops.append('-')
    if eval(s[0]+ops[0]+s[1]+ops[1]+s[2]+ops[2]+s[3]) == 7:
        print(s[0]+ops[0]+s[1]+ops[1]+s[2]+ops[2]+s[3] + '=7')
        exit()
# Judge status: Accepted
X = input()
N = len(X)
S = 0
ans = 0
for i in range(N):
    if X[i] == 'S':
        S += 1
    elif S > 0:
        S -= 1
        ans += 2
print(N-ans)
# Judge status: Accepted
a = int(input())

print(a+a**2+a**3)
# Judge status: Accepted
s = input()
print('2018'+s[4:])
# Judge status: Accepted

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

W = [0]*(N+1)
E = [0]*(N+1)

for i in range(N):
    if S[i]=='W':
        W[i+1] = W[i]+1
    else:
        W[i+1] = W[i]
        
for i in reversed(range(N)):
    if S[i]=='E':
        E[i] = E[i+1] + 1
    else:
        E[i] = E[i+1]

INF = 1<<30
ans = INF

for i in range(N):
    res = W[i] + E[i+1]
    ans = min(ans,res)

print(ans)
# Judge status: Accepted
x = int(input())
h = 0
while x >= 500:
    x -= 500
    h += 1000
while x >= 5:
    x -= 5
    h += 5
print(h)
# Judge status: Accepted
n, a, b = map(int, input().split())

if a > b:
  print(0)
elif n == 1 and a != b:
  print(0)
elif n == 1 and a == b:
  print(1)
else:
  print((b*(n-1)+a) - (a*(n-1)+b) + 1)
# Judge status: Accepted
import sys

input = sys.stdin.readline


def main():
    H1, M1, H2, M2, K = map(int, input().split())

    if H1 == H2:
        time = M2 - M1
    else:
        time = (60 - M1) + (H2 - H1 - 1) * 60 + M2

    ans = time - K
    print(ans)


if __name__ == "__main__":
    main()
# Judge status: Accepted
def main():
    X = input()
    s = 0
    ans = len(X)
    for x in X:
        if x == 'S':
            s += 1
        else:
            if s > 0:
                s -= 1
                ans -= 2
    print(ans)
if __name__ == '__main__':
    main()
# Judge status: Accepted
from sys import stdin
from sys import setrecursionlimit
from collections import Counter, deque, defaultdict
from math import floor, ceil
from bisect import bisect_left
from itertools import combinations
setrecursionlimit(100000)

INF = int(1e10)
MOD = int(1e9 + 7)

def main():
    from builtins import int, map
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort()
    print(sum(A[:K]))

if __name__ == '__main__':
    main()
# Judge status: Accepted
N = int(input())
*A1, = map(int, input().split())
*A2, = map(int, input().split())
ans = 0
for i in range(N):
    ans = max(ans, sum(A1[:i+1]) + sum(A2[i:]))
print(ans)
# Judge status: Accepted
from fractions import gcd

a, b, c, d = [int(i) for i in input().split()]
a-=1
ans = b - a
ans -= b // c - a//c
ans -= b // d - a // d
e = c * d // gcd(c, d)
ans += b // e - a // e
print(ans)
# Judge status: Wrong Answer
n = int(input())
h = list(map(int, input().split()))

h.reverse()
maxH = 0
maxT = 0
for i in range(n-1):
    if h[i] <= h[i + 1]:
        maxT += 1
    else:
        maxH = max(maxH, maxT)
        maxT = 0
print(maxH)
# Judge status: Wrong Answer
N,K = (int(T) for T in input().split())
Now = 0
for TN in range(0,N):
    Num,Count = (int(T) for T in input().split())
    if Now<K<=Now+Count:
        print(Num)
        break
    else:
        Now += Count
# Judge status: Accepted
import math
n=int(input())
dp=[0]*(n+2)
sq=int(math.sqrt(n))
for x in range(1,sq+1):
    for y in range(1,sq+1):
        for z in range(1,sq+1):
            aa=(x*x+y*y+z*z+x*y+y*z+z*x)
            if aa<=n:
                dp[aa]+=1
for i in range(1,n+1):
    print(dp[i])
# Judge status: Wrong Answer
import math
a, b, x = map(int, input().split())
s = x / a
if s >= (a * b) / 2:
    tan = 2*(a*b - s) / a**2
else:
    tan = b**2 / 2*s
print(math.degrees(math.atan(tan)))
# Judge status: Accepted
x,y = map(int,input().split())
t = x
c = 1
if y == 1:
    print(0)
    exit()
for i in range(100):
    if t>=y:
        print(c)
        break
    t += x-1
    c += 1
    #print(t)
# Judge status: Accepted
n, d = map(int, input().split())
lists = []
cnt = 0

for i in range(n):
  x, y = map(int, input().split())
  lists.append([x, y])
  

for j in range(n):
  l = (lists[j][0] ** 2 + lists[j][1] ** 2) ** (1 / 2)
  if l <= d:
    cnt += 1
  else:
    continue

print(cnt)
# Judge status: Accepted
a,b=map(int,input().split())
c=a*b+a
print(c if c%b!=0 else -1)
# Judge status: Accepted
t = ""
for x in input():
    if x=="B":
        t = t[:-1]
    else:
        t += x
print(t)
# Judge status: Accepted
w, h, x, y = map(int, input().split())
max_area = w*h/2
flag = 0
if x == w/2 and y == h/2:
    flag = 1
print(max_area, flag)
# Judge status: Wrong Answer
x, y = map(int, input().split())
if (x > 0 and y < 0) or (x < 0 and y > 0):
    print(abs(abs(x)-abs(y))+1)
elif y < 0:
    print(abs(abs(x)-abs(y))+2)
else:
    print(abs(abs(x)-abs(y)))
# Judge status: Accepted
n, r = map(int, input().split())

if n >= 10:
    print(r)
else:
    print(r + 1000 - 100 * n)
# Judge status: Wrong Answer
x,a,b = map(int, input().split())
print(min(abs(x-a), abs(x-b)))
# Judge status: Accepted
a,b,c=map(int,input().split())
List=[a,b,c]
if List.count(5)==2 and List.count(7)==1:
    print("YES")
else:
    print("NO")
# Judge status: Accepted


b,c=map(int,input().split())
bc=c
cb=b
for i in range(b-1):
    bc=(bc*10+c)
for i in range(c-1):
    cb=(cb*10+b)
print(max(bc,cb))
# Judge status: Wrong Answer

S = input()
l = S[:2]
r = S[2:]

lcnt = 0
rcnt = 0
if 0 < int(l) <= 12 and 0 < int(r):
    lcnt = 1
if  0 < int(r) <= 12 and 0 < int(l):
    rcnt = 1
if lcnt and rcnt:
    print('AMBIGUOUS')
    exit()
elif lcnt:
    print('MMYY')
elif rcnt:
    print('YYMM')
else:
    print('NA')
# Judge status: Accepted
a, b = map(int, input().strip().split())

res = 0
if a < b:
    res = 2 * b - 1
elif a == b:
    res = 2 * a
else:
    res = 2 * a - 1

print(res)
# Judge status: Accepted
n = int(input())

l = [2**i for i in range(8)]

if n==1:
  print(1)
  exit()
for i,v in enumerate(l):
  if n < v:
    print(l[i-1])
    exit()
# Judge status: Accepted
n = int(input())
d  ={}
for i in range(n):
    s = str(input())
    if s in d:
        d[s] += 1
    else:
        d[s] = 1

d = sorted(d.items(), key=lambda x : x[0])
d = sorted(d, key=lambda x : x[1],reverse=1)

flag = d[0][1]
for i in d:
    if i[1] == d[0][1]:
        print(i[0])
    else:
        exit()
# Judge status: Accepted
q,h,s,d=map(int,input().split())
n=int(input())
q*=4
h*=2
if n%2==0:
    print(min(min(q,h,s)*n,d*n//2))
else:
    print(min(min(q,h,s)*n,d*(n//2)+min(q,h,s)))
# Judge status: Wrong Answer
n = int(input())

res = 0
for i in range(1, n):
    if i % 3 == 0 and i % 5 == 0:
        res += 0
    elif i % 3 == 0:
        res += 0
    elif i % 5 == 0:
        res += 0
    else:
        res += i

print(res)
# Judge status: Accepted
# -*- coding: utf-8 -*-
import sys
from sys import stdin

N = int(stdin.readline().rstrip())

for i in range(1, 10):
  for j in range(1, 10):
    if N == i * j:
      print('Yes')
      sys.exit(0)
else:
  print('No')
# Judge status: Accepted
N = int(input())
ans = 0
for i in range(1, N+1):
  n = N//i
  cnt = i*n*(n+1)//2
  ans += cnt
print(ans)
# Judge status: Accepted
S = int(input())
a = 10**9
print(a, (a - (S % a)) % a, 1, (S + a - 1) // a, 0, 0)
# Judge status: Accepted
S = input()
ans_list = [0] * (len(S) + 1)
for i in range(len(S)):
    if S[i] == '<':
        ans_list[i + 1] = ans_list[i] + 1

for i in range(len(S) - 1,-1,-1):
    if S[i] == '>':
        ans_list[i] = max(ans_list[i + 1] + 1, ans_list[i])

print(sum(ans_list))
# Judge status: Wrong Answer
def main():
  s = list(map(int,input().split()))
  n = [0]*s[0]
  for k in range(0,s[1],1):
    d = int(input())
    a = list(map(int,input().split()))
    #print(a)
    for i in range(0,d,1):
      #print(a[i])
      n[a[i]-1] = 1
      #print(n)
      
  sum=0
  print(n)
  
  for k in range(0,s[0],1):  
    if(n[k]==0): sum = sum+1
 
  print(sum)
  
main()
# Judge status: Accepted
def solve():
    X = int(input())
    now = 0
    for i in range(X + 1):
        now += i
        if now >= X:
            return i

print(solve())
# Judge status: Accepted
import sys
import os


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    abc = list(map(str, sys.stdin.readline().split()))
    abc.sort(reverse=True)
    print(int(abc[0]+abc[1])+int(abc[2]))


if __name__ == '__main__':
    main()
# Judge status: Accepted
if __name__ == "__main__":
    N, K = [int(x) for x in input().split(" ")]
    arr = []
    for _ in range(N):
        a, b = [int(x) for x in input().split(" ")]
        arr.append((a, b))
    arr.sort()

    k = 0
    for a, b in arr:
        if k + b < K:
            k = k + b
        else:
            print(a)
            break
# Judge status: Accepted
N=int(input())
L=list(map(int,input().split()))
L.sort(key=int)
ans= L.pop(-1)<sum(L)
print('Yes' if ans else 'No')
# Judge status: Accepted
N = int(input())
xy = [list(map(int,input().split())) for _ in range(N)]
ma = -float('inf')
mi = float('inf')
for x,y in xy:
  ma = max(ma,x-y)
  mi = min(mi,x-y)
ans = ma - mi

ma = -float('inf')
mi = float('inf')
for x,y in xy:
  ma = max(ma,x+y)
  mi = min(mi,x+y)
  
ans = max(ans, ma - mi)
print(ans)
# Judge status: Wrong Answer
a = int(input())

print(int(a*(a*(a+1))))
# Judge status: Wrong Answer
n, m, x = map(int, input().split())
ce = list(list(map(int, input().split())) for _ in range(n))
cst = 12 * 10**5
for i in range(2**n):
    kn = [0 for _ in range(m)]
    for j in range(n):
        if i >> j & 1:
            kn = [kn[k] + ce[j][k] for k in range(m)]
    if all(kn[i] >= x for i in range(1, m)):
        cst = min(kn[0], cst)
print(cst if cst != 12 * 10**5 else -1)
# Judge status: Accepted
n, p = map(int, input().split())
a = list(map(int, input().split()))

odd = sum([item % 2 for item in a])
even = n - odd

ans = 0
if even == n:
    if p == 1:
        print(0)
    else:
        print(2 ** n)
elif n == 1 and odd == 1 and p == 0:
    print(0)
else:
    # 偶数枚入った袋は選ぶor選ばない自由
    ans += 2 ** even
    # 奇数枚入った袋は2で割って余りがPになるよう選ぶ個数を決める
    ans *= 2 ** (odd - 1)
    print(ans)
# Judge status: Accepted
s=input()
odd=["R","U","D"]
even=["L","U","D"]
ans="Yes"

for i in range(len(s)):
    if  i%2==0:
        if s[i] not in odd:
            ans="No"
    else:
        if s[i] not in even:
            ans="No"

print(ans)
# Judge status: Accepted
import math
n,h = map(int,input().split())
A = 0; b = []; ans = 0
for _ in range(n):
    u,v = map(int,input().split())
    A = max(A,u); b.append(v)

for B in sorted(b,key=lambda x:-x):
    if h <= 0 or B <= A:break
    h -= B
    ans += 1
print(max(0,math.ceil(h/A)) + ans)
# Judge status: Accepted
X = int(input())

ans = 0
num = 100
while X > num:
    num = num+num//100
    ans += 1

print(ans)
# Judge status: Accepted
A,B,C=map(int,input().split())
K=int(input())
for i in range(K):
  if A>=B:
    B=B*2
  elif B>=C:
    C=C*2
if ((A<B)&(B<C)):
  print("Yes")
else:
  print("No")
# Judge status: Accepted
t = input()
if(t.islower()):
  print('a')
else:
  print('A')
# Judge status: Wrong Answer
n,m = map(int,input().split())
x = list(map(int,input().split()))
x.sort()
if n>=m:
    print(0)
    exit()
dis = [x[i+1]-x[i] for i in range(m-1)]
dis.sort()
del dis[-(n-1):]
print(sum(dis))
# Judge status: Accepted
a,b,c,d=map(int,input().split())
print(max([0,min([b,d])-max([a,c])]))
# Judge status: Wrong Answer
N = int(input())
M = list(map(int, input().split()))
M = sorted(M)
count = 0
for i in range(N):
  a = M[i]
  for j in range(i+1, N):
    b = M[j]
    upper = a+b
    #二分探索の実装が下手い
    l, r = j, N
    while (r - l) > 1:
      c = (l + r) // 2
      if M[c] <= upper:
        l = c
      else:
        r = c  
    #print(count, j, l, r)
    count += l - j
      
print(count)
# Judge status: Accepted
l=list(map(int,input().split()))
l.sort()
print(l[-1]*10+l[-2]+l[-3])
# Judge status: Accepted
# K = int(input())
# S = input()

# if len(S) > K:
#     print(S[:K] + '...')
# else:
#     print(S)

K = int(input())
S = input()

def answer(K: int, S: str) -> str:
    if len(S) <= K:
        return S
    else:
        return S[:K]+ '...'

print(answer(K, S))
# Judge status: Accepted
N = int(input())
S = list(input())

r = S.count('R')
g = S.count('G')
b = S.count('B')

ans = r*g*b

for i in range(0,N):
  for j in range(i,N):
    k = 2*j - i
    if j < k <= N-1:
      if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
        ans -= 1

print(ans)
# Judge status: Accepted
def main():
  import sys
  input = sys.stdin.readline
  n=int(input())
  l=[tuple(map(int,input().split())) for _ in range(n)]
  dp=[[0]*3 for _ in range(n+1)]
  for i in range(1,n+1):
    dp[i][0]=max(dp[i-1][1],dp[i-1][2])+l[i-1][0]
    dp[i][1]=max(dp[i-1][2],dp[i-1][0])+l[i-1][1]
    dp[i][2]=max(dp[i-1][0],dp[i-1][1])+l[i-1][2]
  print(max(dp[-1]))
if __name__=='__main__':
  main()
# Judge status: Accepted
D = int(input())
day = [' Eve' if D==24 else ' Eve Eve' if D==23 else ' Eve Eve Eve' if D==22 else '']
print('Christmas' + day[0])
# Judge status: Wrong Answer
# -*- coding: utf-8 -*-


def comb(N, A):
    x = 1
    for i in range(A):
        x *= N
        N -= 1
        x %= MOD
    y = 1
    for i in range(A):
        y *= A
        A -= 1
        y %= MOD
    return x*pow(y, MOD-2, MOD) % MOD


N, A, B = map(int, input().split())
MOD = 10**9+7
print(pow(2, N, MOD)-1-comb(N, A)-comb(N, B))
# Judge status: Accepted
S = input()
T = input()
count = 0
for i in range(len(S)):
    if S[i] != T[i]:
        count += 1

print(count)
# Judge status: Accepted
from collections import Counter
n = int(input())

a = tuple(map(int,input().split()))

c = Counter(a)

temp = sorted(c.items())

h = 0
w = 0

while(len(temp)>0):
  k,v = temp.pop()
  if v>=4:
    print(k**2)
    exit()
  elif v>=2:
    h = k
    break
    
while(len(temp)>0):
  k,v = temp.pop()
  if v>=2:
    w = k
    break
    
print(h*w)
# Judge status: Wrong Answer
N = int(input())
if N < 1000:
  print('ABC'+str(N))
else:
  print('ABD'+str(N))
# Judge status: Wrong Answer
list1 = list(map(int, input().split()))
list2= []
list2.append(list1[2])
list2.append(list1[0])
list2.append(list1[1])
print(list2)
# Judge status: Wrong Answer
l=int(input())
ans=[]
for i in range(l//2+1):
    for j in range(l//2+1):
        ans.append(i*j*(l-i-j))
print(max(ans))
# Judge status: Accepted
n = int(input())
ans = 'No'
for i in str(n):
    if int(i) == 7:
        ans = 'Yes'
print(ans)
# Judge status: Accepted
N = int(input())

print((N-N//2)/N)
# Judge status: Accepted
K = int(input())
A, B = map(int, input().split())
if A % K == 0 or ((A // K) + 1)* K <= B:
    print('OK')
else:
    print('NG')
# Judge status: Accepted
A,B=map(int,input().split())

count=0

for i in range(A,B+1):
    i_str=str(i)
    ri_str=i_str[::-1]
    ri=int(ri_str)
    if i==ri:
        count+=1

print(count)