Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

#!/usr/bin/env python3
#ABC128 E

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,q = LI()
stx = [LI() for _ in range(n)]
stx.sort(key = itemgetter(2))
d = [I() for _ in range(q)]
ans = [-1]*q
for s,t,x in stx:
    l,r = bl(d,s-x),bl(d,t-x)
    #l≦d<rを満たすdがxでぶつかる
    for j in range(l,r):
        if ans[j] == -1:
            ans[j] = x
for i in ans:
    print(i)


### FIXED CODE ###

#!/usr/bin/env python3
#ABC128 E

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,q = LI()
stx = [LI() for _ in range(n)]
stx.sort(key = itemgetter(2))
d = [I() for _ in range(q)]
ans = [-1]*(q+1)
right = [0]*q
for s,t,x in stx:
    l,r = bl(d,s-x),bl(d,t-x)
    #l≦d<rを満たすdがxでぶつかる
    #各dにおいて一番最初にぶつかるxを求めたい
    while l < r:
        while ans[l] != -1:
            l = right[l]
        if r <= l:
            break
        ans[l] = x
        right[l] = r
        l += 1
for i in ans[:-1]:
    print(i)
### BUGGY CODE ###

S = input()
Sr = S[::-1] # 一の位から考える

T = 0 # 部分文字列
mod = [0] * 2019 # mod数え上げ配列
mod[0] += 1 # 「部分文字列T = S」の場合の、 「0 % 2019 = 0」を予めカウント
for i, s in enumerate(Sr):
  T += int(s) * ((10 ** (i+1)) % 2019 % 2019)
  mod[T%2019] += 1
  
# ペアを合計
mod = [m//2 for m in mod]
print(sum(mod))

### FIXED CODE ###

S = input()
Sr = S[::-1] # 一の位から考える

T = 0 # 部分文字列
mod = [0] * 2019 # mod数え上げ配列
mod[0] += 1 # 「部分文字列T = S」の場合の、 「0 % 2019 = 0」を予めカウント
d = 1 # 桁数
for i, s in enumerate(Sr):
  T += int(s) * d
  T %= 2019
  d = (d * 10) % 2019
  
  mod[T] += 1
  
# ペアを合計
# n個から2通り選ぶ（nC2）
mod = [n * (n-1) // 2 for n in mod]
print(sum(mod))
### BUGGY CODE ###

import sys
sys.setrecursionlimit(1000000)

N, Q = map(int, input().split())
edges = [[] for i in range(N+1)]
for i in range(N-1):
    a, b = map(int, input().split())
    edges[a].append(b)
    edges[b].append(a)

tally = [0 for i in range(N+1)]
for i in range(Q):
    p, x = map(int, input().split())
    tally[p] += x

count = [0 for i in range(N + 1)]
visited = [False for i in range(N+1)]
def dfs(root, curCount):
    visited[root] = True
    curCount += tally[root]
    count[root] = curCount
    for neighbour in edges[root]:
        if visited[neighbour]: continue
        dfs(neighbour, curCount)

dfs(1, 0)

print(*count[1:])


### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)

N, Q = map(int, input().split())
edges = [[] for i in range(N+1)]
for i in range(N-1):
    a, b = map(int, input().split())
    edges[a].append(b)
    edges[b].append(a)

tally = [0 for i in range(N+1)]
for i in range(Q):
    p, x = map(int, input().split())
    tally[p] += x

count = [0 for i in range(N + 1)]
visited = [False for i in range(N+1)]

stack = [(1, 0)]
while stack:
    root, curCount = stack.pop()
    
    visited[root] = True
    curCount += tally[root]
    count[root] = curCount
    for neighbour in edges[root]:
        if visited[neighbour]: continue
        stack.append((neighbour, curCount))

print(*count[1:])
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
A_set = set(A)

count_dic = {}
for i in A_set:
    C = A.count(i)
    count_dic[i] = C*(C-1)/2
    
sum_dic = sum(count_dic.values())
    
for i in A:
    print(int(sum_dic-(A.count(i)-1)))

### FIXED CODE ###


from collections import Counter
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))
A_set = np.unique(A)
count_dict= Counter(A)
count_sum = np.sum([count_dict[i]*(count_dict[i]-1)/2 for i in A_set])

out = [int(count_sum-count_dict[i]+1) for i in A]
for i in out:
    print(i)
### BUGGY CODE ###

H,W=map(int, input().split())

A=[]
for i in range(H):
  A.append(list(input()))
q=[]
for i in range(H):
  for j in range(W):
    if A[i][j] == '#':
      q.append((i, j))

cnt=0
for _ in range(W*H):
  if not q: break
  r=[]
  for i, j in q:
    if i > 0 and A[i-1][j] == '.':
      A[i-1][j] = '#'
      r.append((i-1, j))
    if i < H-1 and A[i+1][j] == '.':
      A[i+1][j] = '#'
      r.append((i+1, j))
    if j > 0 and A[i][j-1] == '.':
      A[i][j-1] = '#'
      q=r.append((i, j-1))
    if j < W-1 and A[i][j+1] == '.':
      A[i][j+1] = '#'
      r.append((i, j+1))
  q=r
  cnt = cnt + 1
print(cnt-1)

### FIXED CODE ###

def f(h, w):
    dt = [[-1, 0], [0, -1], [0, 1], [1, 0]]
    t = [[True] * (w + 2)]
    for _ in range(h):
        t += [[True] + [(c == "#") for c in input()] + [True]]
    t += [[True] * (w + 2)]
    kuro = []
    for i, ti in enumerate(t[1:-1]):
        for j, tij in enumerate(ti[1:-1]):
            if tij:
                kuro+=[(i + 1, j + 1)]
    cnt = -1
    while kuro:
        cnt += 1
        nxt = []
        for i, j in kuro:
            ti=t[i]
            if not ti[j+1]:
                ti[j + 1]=True
                nxt += [(i, j+1)]
            if not ti[j-1]:
                ti[j - 1]=True
                nxt += [(i, j-1)]
            if not t[i - 1][j]:
                t[i - 1][j]=True
                nxt += [(i - 1, j)]
            if not t[i + 1][j]:
                t[i + 1][j]=True
                nxt += [(i + 1, j)]
        kuro = nxt
    print(cnt)
 
 
h, w = map(int, input().split())
f(h, w)
### BUGGY CODE ###

S = str(input())
T = str(input())



for i in range(len(S)+1):
	s = str(S[i:i+1])
	t = str(T[i:i+1])
	S = S.replace(s,'A').replace(t,s).replace('A',t)

answer = 'No'

if S == T:
	answer = 'Yes'
	
print(answer)

### FIXED CODE ###

#coding:utf-8

"""
自分の解答。これだとTLEになってしまったので、復習をします
from collections import Counter
S = str(input())
T = str(input())

for i in range(len(S)+1):
	s = str(S[i:i+1])
	t = str(T[i:i+1])
	S = S.replace(s,'A').replace(t,s).replace('A',t)

answer = 'No'

if S == T:
	answer = 'Yes'
	
print(answer)
"""

"""
対応表を作るイメージ。
azzel→appleにするのには
a a
z p
e i
l e
という変化を回せればおっけー

#初期値-1で、要素26コの対応表をつくる
start = [-1]*26
goal = [-1]*26
print(start)

"""


S = str(input())
T = str(input())

#辞書型を使ってみる。defaultdictは便利らしい。どこがかはちょっとよく分からなかった。
from collections import defaultdict
s = defaultdict(int)
t = defaultdict(int)


for i in S:
	s[i] += 1

for j in T:
	t[j] += 1

#辞書型をソートできるsoted()を使う。
#values()で辞書型のkey valueのvalueだけを取り出している。

ss = sorted(s.values())
tt = sorted(t.values())

if ss == tt:
	print('Yes')
else:
	print('No')
### BUGGY CODE ###


import numpy as np

from scipy.sparse.csgraph import connected_components
from scipy.sparse import csr_matrix

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

cities = [[0] * N for i in range(N)]
# print(cities)

cities = np.array(cities)

for i in range(M):
    i1, i2 = map(int, input().split())
    cities[i1-1][i2-1] = 1
    cities[i2-1][i1-1] = 1
#     print(cities)
    
# print(cities)

n, labels = connected_components(csr_matrix(cities))
print(n-1)

### FIXED CODE ###


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

# cities = [[0] * N for i in range(N)]
# print(cities)
cities = {}
 
for a in range(N):
    cities[a+1] = []
# print(cities)
 
for i in range(M):
    i1, i2 = map(int, input().split())
    cities[i1].append(i2)
    cities[i2].append(i1)
# print(cities)
def connected_components(graph):
    seen = set()
    def component(n):
        nodes = set([n])
        while nodes:
            n = nodes.pop()
            seen.add(n)
            nodes |= set(graph[n]) - seen
            yield n
    for n in graph:
        if n not in seen:
            yield component(n)
print(len([list(x) for x in connected_components(cities)])-1)
### BUGGY CODE ###

import numpy as np
room, route_count = map(int,input().split())
route = np.array([list(map(int,input().split())) for _ in range(route_count)])
 
object_nums = [1]
ans = np.array([0]*(room-1))
 
def mem_ans(ans, object_num, next_nums):
    mask_array = np.zeros(room-1, dtype=bool)
    mask_array[next_nums-2] = True
    ans[(ans==0) & mask_array] = object_num
    return ans
 
for object_num in object_nums:
 
    object_rows = route[np.any(route==object_num, axis=1)]
    route[np.any(route==object_num, axis=1)] = 0
    next_nums = object_rows[object_rows!=object_num]
    if next_nums is not None:
        ans = mem_ans(ans, object_num, next_nums)
        object_nums.extend(next_nums)
    else:
        break
 
if 0 in set(ans):
  print('No')
else:
  print('Yes')
  for i in ans:
    print(i)

### FIXED CODE ###

import networkx as nx
room, route_count = map(int,input().split())
route = [list(map(int,input().split())) for _ in range(route_count)]

G = nx.Graph()
G.add_nodes_from(range(1,room+1))
G.add_edges_from(route)
pre = nx.predecessor(G, 1)

print('Yes')
for i in range(2,room+1):
  print(pre[i][0])
### BUGGY CODE ###

N = int(input())
A = [int(i) for i in input().split()]

ball = [0 for _ in range(N)]

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

#print("ball", ball)
for k in range(N):
    ans = 0
    ball_new = [b for b in ball]
    ball_new[A[k] - 1] -= 1

    #print("ball_n", ball_new)
    for i in range(N):
        ball_num = ball_new[i]
        ans += ball_num*(ball_num-1)//2
    print(ans)

### FIXED CODE ###

N = int(input())
A = [int(i) for i in input().split()]

ball = [0 for _ in range(N)]

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

all = 0
for i in range(N):
    all += ball[i]*(ball[i] - 1)//2


#print("ball", ball)
for k in range(N):
    ans = all
    ball_new = ball[A[k] - 1] - 1
    #ball_new[A[k] - 1] -= 1

    ans -= ball[A[k] - 1]*(ball[A[k] - 1] - 1)//2
    ans += ball_new*(ball_new - 1)//2

    print(ans)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
#
import math
import sys
import itertools
import numpy as np

h,w = map(int, input().split())

ch,cw = map(int, input().split())
dh,dw = map(int, input().split())

x = np.zeros((h,w))
y = np.zeros((h,w))

z = [list(input()) for i in range(h)]
x = z
#print(x)
x[ch-1][cw-1]='a'

def tansaku():
    nu = 0
    while 1:
        nutta=0 # 塗ったマス
        for i in range(h):
            for j in range(w):
                if x[i][j] == 'a':
                    if i>0:
                        if x[i-1][j]=='.':
                            nutta += 1
                            x[i-1][j]='a'
                    if j>0:
                        if x[i][j-1]=='.':
                            nutta += 1
                            x[i][j-1]='a'
                    if i<h-1:
                        if x[i+1][j]=='.':
                            nutta += 1
                            x[i+1][j]='a'
                    if j<w-1:
                        if x[i][j+1]=='.':
                            nutta += 1
                            x[i][j+1]='a'
        if nutta==0:
            return nu
        else:
            nu += nutta

def warp():
    y=[[0 for j in range(w)] for i in range(h)]
    nu = 0
    for i in range(h):
        for j in range(w):
            if x[i][j] == 'a':
                for p in range(max(i-2,0),min(i+3,h)):
                    for q in range(max(j-2,0),min(j+3,w)):
                        if x[p][q] == '.':
                            y[p][q]='a'
                            #print("a",p,q)
                            nu += 1
    for i in range(h):
        for j in range(w):
            if y[i][j]=='a':
                x[i][j]='a'
                #print("b")
    return nu # これは塗った数よりは多いがnuが1なら0ではない


answer = 0
while(1):
    #print(x,ch,cw,dh,dw)
    nurioe = tansaku()
    #print(x,nurioe)
    if x[dh-1][dw-1]=='a':
        print(answer)
        break
    nurioe = warp()
    answer += 1
    #print(x,nurioe)
    if nurioe == 0:
        print(-1)
        break
    


### FIXED CODE ###

# -*- coding: utf-8 -*-
#
import math
import sys

from collections import deque

h,w = map(int, input().split())

ch,cw = map(int, input().split())
dh,dw = map(int, input().split())

maze =["#"*(w+4) for i in range(2)] + ["##"+input()+"##" for i in range(h)] + ["#"*(w+4) for i in range(2)]
temp = [[-1]*(w+4) for i in range(h+4)]

#print(maze)

q = deque([(ch+1,cw+1)])
temp[ch+1][cw+1]=0

opt = [(0,1),(0,-1),(1,0),(-1,0)]

while q:
    y,x = q.popleft()
#    print(y,x)
    # aruki
    for i in opt:
        ty,tx = y+i[0], x+i[1]
        if maze[ty][tx]=='#':
            continue
        if (temp[ty][tx] == -1 or temp[ty][tx] > temp[y][x]):
            temp[ty][tx] = temp[y][x] # ikeru
            q.appendleft((ty,tx)) # new ikeru basho tuika
    # warp
    for i in range(-2,3):
        for j in range(-2,3):
            ty,tx = y+i, x+j
            if maze[ty][tx] == "#":
                continue
            if temp[ty][tx] == -1 or temp[ty][tx] > temp[y][x]+1:
                temp[ty][tx] =  temp[y][x]+1
                q.append((ty,tx))  # 
#    print(q)


print(temp[dh+1][dw+1])
### BUGGY CODE ###

n=int(input())
a=[0]+[int(i) for i in input().split()]+[0]
cost=[abs(a[i+1]-a[i]) for i in range(n+1)]
#print(cost)
for i in range(n):
    Cost=cost[:i]+cost[i+2:]+[abs(a[i+2]-a[i])]
    #print(Cost)
    print(sum(Cost))



### FIXED CODE ###

n=int(input())
a=[0]+[int(i) for i in input().split()]+[0]
cost=[abs(a[i+1]-a[i]) for i in range(n+1)]
C=sum(cost)
#print(cost)
for i in range(1,n+1):
    Co=C-(abs(a[i+1]-a[i]))-abs((a[i]-a[i-1]))+abs(a[i+1]-a[i-1])
    print(Co)
### BUGGY CODE ###

n,k,q=map(int,input().split())
a=[int(input()) for _ in range(q)]
for i in range(1,n+1):
  p=k-q+1*(a.count(i))
  if p>=1:
    print('Yes')
  else:
    print('No')


### FIXED CODE ###

n,k,q=map(int,input().split())
a=[]
for i in range(n):
  a.append(k-q)
for i in range(q):
  a[int(input())-1]+=1
for i in range(n):
  print('Yes' if a[i]>0 else 'No')
### BUGGY CODE ###

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    g = [1]
    for i in range(len(A)-1):
        prev_p = g[-1]
        g.append(A[prev_p-1])
        
    if K <= N - 1:
        print(g[K])
    else:
        prev_ = g[-1]
        new_g = []
        while True:
            if new_g[:len(new_g)//2] == new_g[len(new_g)//2:] and len(new_g) > 0:
                break
            new_g.append(A[prev_-1])
            prev_ = new_g[-1]
        new_g = new_g[:len(new_g)//2]
        
        K_ = (K - N) % len(new_g)
        print(new_g[K_])
        


if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    prev_p = 1
    g = []
    seen = [0]*N
    i = 0
    while True:
        if seen[prev_p-1]:
            break
        seen[prev_p-1] = i
        g.append(A[prev_p-1])
        prev_p = g[-1]
        i += 1
    g_periodic = g[seen[prev_p-1]:]  
    g_before = g[:seen[prev_p-1]]

    if K <= len(g_before):
        print(g_before[K-1])
    else:
        K_new = (K - len(g_before)) % len(g_periodic)
        print(g_periodic[K_new-1])
if __name__ == '__main__':
    main()
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
i = 0
while i<N:
    j = 0
    count = 0
    while j<N-1:
        if A[j]==i+1:
            count+=1
        j+=1
    print(count)
    i+=1

### FIXED CODE ###

import collections
 
N = int(input())
A = list(map(int, input().split()))
 
c = collections.Counter(A)
 
for i in range(1, N+1):
    print(c[i])
### BUGGY CODE ###

nn = '0' + input()
ans = 0
dp = [[0 for i in range(2)] for j in range(len(nn))]
dp[0][1] = 1

for i,c in enumerate(nn[1:]):
    cc = int(c)
    zero = dp[i][0] + cc
    one = dp[i][1] + 10 - cc
    dp[i+1][0] = min(zero, one)
    dp[i+1][1] = min(zero + 1, one - (1 if i < len(nn) - 2 else 0))
print(min(dp[len(nn)-1]))
# print(dp)
 

### FIXED CODE ###

nn = '0' + input()
ans = 0
dp = [[0 for i in range(2)] for j in range(len(nn))]
dp[0][1] = 1

for i,c in enumerate(nn[1:]):
    cc = int(c)
    zero = dp[i][0] + cc
    one = dp[i][1] + 10 - cc
    dp[i+1][0] = min(zero, one)
    dp[i+1][1] = min(zero + 1, one - (1 if i < len(nn) - 2 else 0))
print(min(dp[len(nn)-1]))
# print(dp)
### BUGGY CODE ###

import sys
 
a = []
for l in sys.stdin:
    a.append(l)
 
target = a[int(a[0])]
num = 0

sortedA = []

for i in a:
    sortedA.append(''.join(sorted(i)))
sortedA.pop(0)

end = len(a) - 1

for i in range(0, end):
    for j in range(i + 1, end):
        if sortedA[i] == sortedA[j]:
            num = num + 1
print(num)

### FIXED CODE ###

import sys
import collections

n=int(input())
a=[''.join(sorted(input())) for _ in range(n)]

ans = 0
for v in collections.Counter(a).values():
    if v != 1:
        ans += v * (v - 1) // 2
print(ans)
### BUGGY CODE ###

from collections import deque

n = int(input())

nodes = [set() for i in range(n+1)]
dis = [dict() for i in range(n+1)]
ans = [-1 for i in range(n+1)]

for _ in range(n-1):
    a,b,c = map(int,input().split())
    nodes[a].add(b)
    nodes[b].add(a)
    dis[a][b] = c
    dis[b][a] = c

#print(nodes)
#print(dis)

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

q = [K]
d = 0
ans[K] = 0
c = 0
while True:
    now = q[-1]
    nex = -1
    for x in nodes[now]:
        if ans[x] == -1:
            nex = x
            break
    if nex == -1:
        if c >= n-1:
            break
        else:
            q.remove(now)
            d -= dis[now][q[-1]]

    else:
        nodes[now].remove(nex)
        nodes[nex].remove(now)
        d += dis[now][nex]
        q.append(nex)
        ans[nex] = d
        c += 1

#print(ans)

for _ in range(Q):
    x,y = map(int,input().split())
    print(ans[x] + ans[y])


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**8)

N = int(input())

vertex = [{} for _ in range(N)]

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

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

d = [0 for i in range(N)]

def dfs(v1,v2):
    d[v2] = d[v1] + vertex[v1][v2]
    for v in vertex[v2]:
        if v == v1:
            continue
        dfs(v2,v)

for v in vertex[K-1].keys():
    dfs(K-1,v)

for q in range(Q):
    x,y = map(int,input().split())
    print(d[x-1] + d[y-1])
### BUGGY CODE ###

N,Ma,Mb=map(int,input().split())
abc = list(list(map(int,input().split()))for i in range(N))
DP = [[[10**9]*(10*N+1) for i in range(10*N+1)]for i in range(N+1)]
DP[0][0][0] = 0
for i in range(N):
    for j in range(10*N+1):
        for k in range(10*N+1):
            if j >= abc[i][0] and k >= abc[i][1]:
                DP[i+1][j][k] = min(DP[i][j][k],DP[i][j-abc[i][0]][k-abc[i][1]]+abc[i][2])
            else:
                DP[i+1][j][k] = DP[i][j][k]
ans = 10**9
for i in range(1,10*N//max(Ma,Mb)+1):
    ans = min(DP[-1][i*Ma][i*Mb],ans)
if ans >= 10**8:
    print(-1)
else:
    print(ans)

### FIXED CODE ###

N,Ma,Mb=map(int,input().split())
abc = list(list(map(int,input().split()))for i in range(N))
DP = [[[10**9]*(10*N+1) for i in range(10*N+1)]for i in range(N+1)]
DP[0][0][0] = 0
for i in range(N):
    for j in range(10*N+1):
        for k in range(10*N+1):
            if j >= abc[i][0] and k >= abc[i][1]:
                DP[i+1][j][k] = min(DP[i][j][k],DP[i][j-abc[i][0]][k-abc[i][1]]+abc[i][2])
            else:
                DP[i+1][j][k] = DP[i][j][k]
ans = 10**9
for i in range(1,10*N//max(Ma,Mb)+1):
    ans = min(DP[-1][i*Ma][i*Mb],ans)
if ans >= 10**8:
    print(-1)
else:
    print(ans)
### BUGGY CODE ###

pattern = "AC"
N, Q = map(int, input().split(" "))
S = input()

ACIndex = []
findFrom = 0
while(1) :
    i = S[findFrom:].find("AC")
    if i == -1 :
        break
    else :
        ACIndex.append(i+findFrom)
        findFrom = i+1+findFrom


for i in range(Q) :
    count = 0
    l, r = map(int, input().split(" "))
    for j in ACIndex :
        if j>=l-1 and j<r-1 :
            count+= 1
    
    print(count)


### FIXED CODE ###

N, Q = map(int, input().split(" "))
S = input()

ACIndex = [0] * (N+1)
for i in range(N) :
    ACIndex[i+1] = ACIndex[i] + (1 if S[i:i+2] == "AC" else 0)

for i in range(Q) :
    l,r = map(int, input().split(" "))
    print(ACIndex[r-1] - ACIndex[l-1])
### BUGGY CODE ###

import numpy as np
N,M=map(int,input().split(" "))
A=list(sorted(map(int,input().split(" "))))
L=np.array([A[s]-A[s+1] for s in range(M-1)])

if M>N:
    for s in range(N-1):
        L[np.argmin(L)]=0
    print(abs(sum(L)))
else:
    print(0)

### FIXED CODE ###

N,M=map(int,input().split(" "))
A=list(sorted(map(int,input().split(" "))))
L=[A[s]-A[s+1] for s in range(M-1)]
if M>N:
    print(abs(sum(sorted(L)[N-1:])))
else:
    print(0)
### BUGGY CODE ###

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

fac = [0 for _ in range(n+1)]
inv = [0 for _ in range(n+1)]
finv = [0 for _ in range(n+1)]

fac[0] =fac[1]= 1
inv[0] =inv[1]= 1
finv[0] = finv[1] = 1

p = 10**9 + 7
#p = 31
#inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
for i in range(2,n+1):
    fac[i] = (fac[i-1]*i)%p
    inv[i] = (p - inv[p%i]*int(p/i)%p)%p
    finv[i] = (finv[i-1]*inv[i])%p
    
#print(fac)
#print(inv)
#print(finv)

def cal(m,k):
    return fac[m]*(finv[k]*finv[m-k]%p)%p

ans=pow(2,n,p) - 1
ans = (ans - cal(n,a) - cal(n,b))%p

if(ans<0):
    ans = -1*ans

print(ans)

### FIXED CODE ###

import math

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

p = 10**9 + 7


def cmb(n, r):
    total = 1
    for i in range(r):
        total = total * (n - i) % p
        
    return total * pow(math.factorial(r), p - 2, p) % p

total = pow(2, n, p)-1
a_total = cmb(n, a)
b_total = cmb(n, b)
print((total - a_total - b_total) % p)
### BUGGY CODE ###

n, bu, re = list(map(int, input().split(" ")))
 
ttlBu, ttlRe = 0, 0
 
while True:
    for _ in range(bu):
        if ttlBu + ttlRe == n:
            print(ttlBu)
            exit()
        ttlBu += 1
    for _ in range(re):
        if ttlBu + ttlRe == n:
            print(ttlBu)
            exit()
        ttlRe += 1

### FIXED CODE ###

import math

n, a, b = map(int, input().split(" "))

ans = (n // (a + b)) * a
ans += min((n % (a + b)), a)
print(ans)
### BUGGY CODE ###

from collections import deque

N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

c1 = list(0 for i in range(N))
c2 = deque()
c3 = deque()
c4 = deque()
c5 = deque()
c6 = deque()

counter = 0
def transfer(start, end, capacity):
    for i in range(capacity):
        if len(start) != 0:
            end.append(start.pop())
        else:
            break

while len(c6) != N:
    counter += 1
    transfer(c5, c6, E)
    transfer(c4, c5, D)
    transfer(c3, c4, C)
    transfer(c2, c3, B)
    transfer(c1, c2, A)
print(counter)


### FIXED CODE ###

import math
from collections import deque

N = int(input())
X = deque()
for i in range(5):
        X.append(int(input()))
m = min(X)
print(math.ceil(N/m)+4)
### BUGGY CODE ###

a = 7
b = 0
K = int(input())
for i in range(K):
  if a % K == 0:
    b = 1
    break
  else:
    a = 10 * a +7
if b == 0:
  print(-1)
else:
  print(i + 1)

### FIXED CODE ###

b = 0
K = int(input())
a = 7 % K
for i in range(K):
  if a == 0:
    b = 1
    break
  else:
    a = (10 * a +7) % K
if b == 0:
  print(-1)
else:
  print(i + 1)