Harryxun/stf_run huggingface dataset:
#abc_155_d
#versions of not using numpy
n,k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a = np.array(a)
a.sort()

left = -10**18
right = 10**18

while left+1 < right:
    mid = (left+right)//2
    cnt = 0
    
    #run about each element as the first choice
    for i in range(n):
        #count possible pairs that satisfies the condition      
        if(a[i] >= 0):
            #hold the sorted order
            l = -1 
            r = n
            while l+1<r:
                m = (l+r)//2
                if(a[i]*a[m] <= mid):
                    l = m
                else:
                    r = m
            
            cnt += l+1
        
        if(a[i] < 0):
            #reverse the sorted order
            l = -1 
            r = n
            while l+1<r:
                m = (l+r)//2
                if(a[i]*a[m] <= mid):
                    r = m
                else:
                    l = m
                    
            cnt += n - r
        
        if(a[i]**2 <= mid):
            cnt -= 1
        
    cnt /= 2
        
            
    
    """
    if mid >=0:
        cnt += len(zero) * n
    
    cnt += a.searchsorted(mid//plus, side="right").sum()
    cnt += (n - a.searchsorted(-(-mid//minus), side="left")).sum()
    cnt -= np.count_nonzero(a*a <= mid)
    cnt /= 2
    """
    
    if cnt >= k:
        right = mid
    if cnt < k:
        left=mid
   
        
print(right)

### FIXED CODE ###

#abc_155_d
import numpy as np
n,k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a = np.array(a)
a.sort()

plus = a[a>0]
zero = a[a==0]
minus= a[a<0]

left = -10**18
right = 10**18

while left+1 < right:
    mid = (left+right)//2
    cnt = 0
    
    if mid >=0:
        cnt += len(zero) * n
    
    cnt += a.searchsorted(mid//plus, side="right").sum()
    cnt += (n - a.searchsorted(-(-mid//minus), side="left")).sum()
    cnt -= np.count_nonzero(a*a <= mid)
    cnt /= 2
    
    if cnt >= k:
        right = mid
    if cnt < k:
        left=mid
        
print(right)
n = int(input())
s = input()
output = "No"

for i in range(1, n - 1):
    if n % i != 0:
        continue

    else:
        tmp = s[:i:]
        if tmp * (n // i) == s:
            output = "Yes"


print(output)


### FIXED CODE ###

r = int(input())

print(r ** 2)
K,S = map(int,input().split())
count = 0
for i in range(K+1):
    for j in range(K+1):
        if 0 <= S - (i+j) <= K:
            count += 1
print(count)

### FIXED CODE ###

K,S = map(int,input().split())
count = 0
for i in range(K+1):
    for j in range(K+1):
        if 0 <= S - (i+j) <= K:
            count += 1
print(count)
N = int(input())
A = sorted(list(map(int, input().split())))
if N == 1:
    print(1)
elif A[0] == 1 and A[1] == 1:
    print(0)
elif A[0] == 1:
    print(1)
else:
    Eratos = [False]*1000001
    ans = 0
    for i in range(N):
        if Eratos[A[i]]:
            ans += 1
        else:
            for j in range(A[i], 1000001, A[i]):
                Eratos[j] = True
print(N-ans)

### FIXED CODE ###

N = int(input())
A = sorted(list(map(int, input().split())))
if N == 1:
    print(1)
elif A[0] == 1 and A[1] == 1:
    print(0)
elif A[0] == 1:
    print(1)
else:
    Eratos = [False]*1000001
    ans = 0
    for i in range(N):
        if Eratos[A[i]]:
            ans += 1
        else:
            if i < N-1 and A[i] == A[i+1]:
                ans += 1
            for j in range(A[i], 1000001, A[i]):
                Eratos[j] = True
    print(N-ans)
a,b=map(int,input().split())
print(int((a-1)*(b-1))

### FIXED CODE ###

a,b=map(int,input().split())
print(int((a-1)*(b-1)))
N,M = map(int,input().split())
l=[]
r=[]
for i in range(N):
  a,b=map(int,input().split())
  l.append(a)
  r.append(b)
  
  
ans=min(r)-max(l)+1
print(ans)

### FIXED CODE ###

n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
L=[]
R=[]
for i in range(m):
  L.append(l[i][0])
  R.append(l[i][1])
print(max(min(R)-max(L)+1,0))
if __name__ == "__main__":
    n = int(input())
    l_a = list(map(int, input().split()))
    s_a = list(set(l_a))

    s_a.sort()

    dub_a = [0]*(max(s_a)+1)

    for i in l_a:
        dub_a[i] += 1

    dp = [1]*(max(s_a)+1)

    for i in s_a:
        if dp[i] == 0:
            pass
        else:
            for j in range(2*i, len(dp), i):
                dp[j] = 0


    count = 0
    for i in s_a:
        if dp[i]==1 and dub_a[i]==1:
            count += 1
    print(count)

### FIXED CODE ###

if __name__ == "__main__":
    s = input().split()
    for i, num in enumerate(s):
        if num == "0":
            print(i+1)
n,m,x = map(int,input().split())
A = [[] for _ in range(n)]
for i in range(n):
    A[i] = list( map(int,input().split()) )
    
flag = 0
min_charge = 10**7

for i in range(2**n):
    which = format(i, '#010b')[-n:]
    
    #print(which,end = ':')
    
    charge = 0
    skill = [0 for _ in range(m)]
    for j in range(n):
        if which[j]=='1':
            charge += A[j][0]
            for k in range(m):
                skill[k]+=A[j][k+1]
    flag_skill = 1
    for l in range(m):
        if skill[l] < x:
            flag_skill = 0
    
    
    #print(skill,end=':')
    #print(charge,end=':')    
    
    if flag_skill ==1:
        min_charge = min(min_charge,charge)
    
    #print(flag_skill)

if min_charge == 10**7:
    print(-1)
else:
    print(min_charge)

### FIXED CODE ###

n,m,x = map(int,input().split())
A = [[] for _ in range(n)]
for i in range(n):
    A[i] = list( map(int,input().split()) )
    
flag = 0
min_charge = 10**7

for i in range(2**n):
    which = format(i, '#020b')[-n:]
    
    #print(which,end = ':')
    
    charge = 0
    skill = [0 for _ in range(m)]
    for j in range(n):
        if which[j]=='1':
            charge += A[j][0]
            for k in range(m):
                skill[k]+=A[j][k+1]
    flag_skill = 1
    for l in range(m):
        if skill[l] < x:
            flag_skill = 0
    
    
    #print(skill,end=':')
    #print(charge,end=':')    
    
    if flag_skill ==1:
        min_charge = min(min_charge,charge)
    
    #print(flag_skill)

if min_charge == 10**7:
    print(-1)
else:
    print(min_charge)
n=int(input())
a=[int(v) for v in input().split(' ')]

sum =0
for v in a:
  sum+=1/v

print("%f" % 1/sum)


### FIXED CODE ###

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

s = 0
for a in A:
    s += 1 / a

print("%.5f" % (1/s))
s=input()
if AAA or BBB:
  print("No")
else:
  print("Yes")

### FIXED CODE ###

s=input()
if s=="AAA" or s=="BBB":
  print("No")
else:
  print("Yes")
x,y = input().split(),input().split()
h,w,hh,ww = x[0],x[1],y[0],y[1]
print((h - hh) * (w - ww))

### FIXED CODE ###

x,y = input().split(),input().split()
h,w,hh,ww = int(x[0]),int(x[1]),int(y[0]),int(y[1])
print((h - hh) * (w - ww))
N=int(input())
h=list(map(int,input().split()))

mi=min(h)
h0=h[0]
c=h0-mi
ans=mi
for i in range(1,N):
    if h0<h[i]:
        c+=h[i]-h0
    elif h0>h[i]:
        ans+=c
        mi = min(h[i:])
        c=h[i]-mi
    h0=h[i]

if h[-2]<h[-1]:
    ans+=c
print(ans)


### FIXED CODE ###

N=int(input())
h=list(map(int,input().split()))

if N==1:
    print(h[0])
    exit()

mi=min(h)
p=0
h0=h[0]
c=h0-mi
ans=mi+h0
for i in range(1,N):
    if h0<h[i]:
        c+=h[i]-h0
    elif h0>h[i]:
        c=h0-min(h[p:i])
        ans+=c
        p = i
        c=h[i]-mi
    h0=h[i]

ans+=c-min(h[p:])
print(ans)
from collections import defaultdict
from math import gcd
MOD = 10**9 + 7
n = int(input())
zero = 0
cnt = dict()
for i in range(n):
    x, y = map(int, input().split())
    if x == 0 and y == 0:
        zero += 1
        continue
    g = gcd(x, y)
    x //= g
    y //= g
    if y < 0 or (y == 0 and x < 0):
        x *= -1
        y *= -1
    rot_90 = 1 if x <= 0 else 0
    if rot_90:
        x, y = y, -x
        cnt[(x, y)][rot_90] += 1

ans = 1
for s, t in cnt.values():
    now = 1
    now += (pow(2, s, MOD) - 1) % MOD
    now += (pow(2, t, MOD) - 1) % MOD
    ans *= now
ans -= 1
ans += zero
print(ans % MOD)

### FIXED CODE ###

from math import gcd
MOD = 10**9 + 7
n = int(input())
zero = 0
cnt = dict()
for i in range(n):
    x, y = map(int, input().split())
    if x == 0 and y == 0:
        zero += 1
        continue
    g = gcd(x, y)
    x //= g
    y //= g
    if y < 0 or (y == 0 and x < 0):
        x *= -1
        y *= -1
    rot_90 = 1 if x <= 0 else 0
    if rot_90:
        x, y = y, -x
    try:
        cnt[(x, y)][rot_90] += 1
    except KeyError:
        cnt[(x, y)] = [int(not rot_90), rot_90]

ans = 1
for s, t in cnt.values():
    now = 1
    now += (pow(2, s, MOD) - 1) % MOD
    now += (pow(2, t, MOD) - 1) % MOD
    ans *= now
ans -= 1
ans += zero
print(ans % MOD)
W = input()

count = 0
while True:
    line = input()
    if line == 'END_OF_TEXT':
        break
    
    for s in line.lower.split():
        if s == W:
            count += 1
            
        
    
print(count)

### FIXED CODE ###

W = input().lower()

count = 0
while True:
    line = input()
    if line == 'END_OF_TEXT':
        break
    
    for s in line.lower().split():
        if s == W:
            count += 1
            
        
    
print(count)
input()
rates = sorted([int(x) for x in input().split()])
counts = []
for boundary in [399, 799, 1199, 1599, 1999, 2399, 2799, 3199]:
    counts.append(1 if rates[0] <= boundary else 0)
    rates = [rate for rate in rates if rate > boundary]
higher = len(rates)
least = sum(counts)
print("{} {}".format(1 if least == 0 else least, least+higher))

### FIXED CODE ###

# -* encode: utf-8 *-

N = int(input())
rates = [int(x) for x in input().split()]

rates.sort()
uppers = [399, 799, 1199, 1599, 1999, 2399, 2799, 3199, 4800]
accum = list()
counts = list()

for upper in uppers:
    accum.append(len([x for x in rates if x <= upper]))

counts.append(accum[0])
for i in range(1, 9):
    counts.append(accum[i] - accum[i-1])

_least = sum([1 for count in counts[:-1] if count > 0])
max_scorerer = counts[-1]

if _least == 0:
    least = 1
    most = max_scorerer
else:
    least = _least
    most = least + max_scorerer

print("{} {}".format(least, most))
import sys
input = sys.stdin.readline

n, c = map(int, input().split())
sushi = [tuple(map(int, input().split())) for _ in range(n)]

ans = 0

cand1 = [0] * n
v_sum = 0
for i in range(n):
    v_sum += sushi[i][1]
    cand1[i] = v_sum - sushi[i][0]
    if i > 0:
        cand1[i] = max(cand1[i], cand1[i-1])

cand2 = [0] * n
v_sum = 0
for i in reversed(range(n)):
    v_sum += sushi[i][1]
    cand2[i] = v_sum - (c - sushi[i][0])
    if i != n - 1:
        cand2[i] = max(cand2[i], cand2[i+1])

ans = max(ans, *cand1, *cand2)

v_sum = 0
for i in reversed(range(1, n)):
    v_sum += sushi[i][1]
    ans = max(ans, v_sum - (c - sushi[i][0]) * 2 + cand1[i-1])

v_sum = 0
for i in range(n-1):
    v_sum += sushi[i][1]
    ans = max(ans, v_sum - sushi[i][0] * 2 + cand2[i+1])

print(ans)


### FIXED CODE ###

import sys
input = sys.stdin.readline

n, c = map(int, input().split())
sushi = [tuple(map(int, input().split())) for _ in range(n)]

ans = 0

cand1 = [0] * n
v_sum = 0
for i in range(n):
    v_sum += sushi[i][1]
    cand1[i] = v_sum - sushi[i][0]
    if i > 0:
        cand1[i] = max(cand1[i], cand1[i-1])

cand2 = [0] * n
v_sum = 0
for i in reversed(range(n)):
    v_sum += sushi[i][1]
    cand2[i] = v_sum - (c - sushi[i][0])
    if i != n - 1:
        cand2[i] = max(cand2[i], cand2[i+1])

ans = max(ans, max(cand1), max(cand2))

v_sum = 0
for i in reversed(range(1, n)):
    v_sum += sushi[i][1]
    ans = max(ans, v_sum - (c - sushi[i][0]) * 2 + cand1[i-1])

v_sum = 0
for i in range(n-1):
    v_sum += sushi[i][1]
    ans = max(ans, v_sum - sushi[i][0] * 2 + cand2[i+1])

print(ans)
[print("".join(sorted(input() for _ in range(l)))) for n, l in [map(int, input().split())]]


### FIXED CODE ###

n, l = map(int, input().rstrip("\n").split())
strings = sorted([input().rstrip() for _ in range(n)])

print("".join(strings))
n = int(input())
print((800 * n) - (200 * (n//15))

### FIXED CODE ###

n = int(input())
print((800 * n) - (200 * (n//15)))
import math
A, B = map(int, input().split())
g = math.gcd(A, B)
ans = (A // g) * B
print(ans)

### FIXED CODE ###

import fractions as f
A, B = map(int, input().split())
g = f.gcd(A, B)
ans = (A // g) * B
print(ans)
def check(s):
    if s=="":
        return True
    else:
        if len(s)>=7:
            if s[-5:]=="dream" or s[-5:]=="erase":
                    s=s[:-5]
                    print(s)
                    return check(s)
                
            elif s[-7:]=="dreamer":
                    s=s[:-7]
                    print(s)
                    return check(s)
            
            elif s[-6:]=="eraser":
                    s=s[:-6]
                    print(s)
                    return check(s) 
            else:
              return False


                
        elif len(s)==6:
            if s[-6:]=="eraser":
                return True
            
            else:
                return False

            
        elif len(s)==5:
            if s[-5:]=="dream" or s[-5:]=="erase":
                return True
            else:
                return False

        else:
            return False
  
s=input()
if check(s):
    print("Yes")
else:
    print("No")

### FIXED CODE ###

s=input()
length=len(s)

s=s[::-1]

s=s+"WWWWWWW"

index=0
flag=True
while index<length:
    if s[index]=="m" and s[index+1]=="a" and s[index+2]=="e" and s[index+3]=="r" and s[index+4]=="d":
        index+=5
    elif s[index]=="e" and s[index+1]=="s" and s[index+2]=="a" and s[index+3]=="r" and s[index+4]=="e":
        index+=5   
    elif s[index]=="r" and s[index+1]=="e" and s[index+2]=="m" and s[index+3]=="a" and s[index+4]=="e" and s[index+5]=="r" and s[index+6]=="d":
        index+=7   
    elif s[index]=="r" and s[index+1]=="e" and s[index+2]=="s" and s[index+3]=="a" and s[index+4]=="r" and s[index+5]=="e":
        index+=6
    else:
        flag=False
        break
if flag:
    print("YES")
else:
    print("NO")
n = int(input())
an = []
max_1 = 1
max_2 = 1
count = 1
for i in range(n):
    a = int(input())
    if a > max_1:
        max_1 = a
        count = 1
        max1_index = [i]
    elif a == max_1:
        count += 1
        max1_index.append(i)
    elif max_1 > a and a > max_2:
        max_2 = a
        max2_index = i
    an.append(a)
    
    
if count == 1:
    for i in range(n):
        if i in max1_index:
            print(max_2)
        else:
            print(max_1)
else:
    for i in range(n):
        print(max_1)

### FIXED CODE ###

n = int(input())
an = []
max_1 = 1
max_2 = 1
count = 1
max1_index = [0]
for i in range(n):
    a = int(input())
    if a > max_1:
        tmp = max_1
        max_1 = a
        count = 1
        max1_index = [i]
        max_2 = tmp
    elif a == max_1:
        count += 1
        max1_index.append(i)
    elif max_1 >  a > max_2:
        max_2 = a
    an.append(a)
if count == 1:
    for i in range(n):
        if i in max1_index:
            print(max_2)
        else:
            print(max_1)
else:
    for i in range(n):
        print(max_1)
import re
def main():
	S = input().split()[0]
	T = input().split()[0]
	repatter = re.compile(S)
	result = repatter.match(T)
	if len(S) + 1 != len(T):
		return 'No'
	if S == result.group():
		ans = 'Yes'
	else:
		ans ='No'
	return ans


     
if __name__ == '__main__':
	print(main())

### FIXED CODE ###

def main():
	S = input().split()[0]
	T = input().split()[0]
	T = T[:-1]
	if S == T:
		ans = 'Yes'
	else:
		ans ='No'
	return ans
     
if __name__ == '__main__':
	print(main())
import sys
n,m = map(int,input().split(" "))
nums = [0] * m
for _ in range(m):
    s,c = map(int,input().split(" "))
    if c >= 10 or c < 0:
        print(-1)
        sys.exit(0)
    if s >= n:
        print(-1)
        sys.exit(0)
    if s == 1 and c == 0:
        print(-1)
        sys.exit(0)
    if nums[s-1] != 0 and c != nums[s-1]:
        print(-1)
        sys.exit(0)
    nums[s-1] = c
if nums[0] == 0:
    nums[0] = 1
print("".join(map(str,nums)))

### FIXED CODE ###

import sys
n,m = map(int,input().split(" "))
nums = [-1] * n
for _ in range(m):
    s,c = map(int,input().split(" "))
    if n > 1 and s == 1 and c == 0:
        print(-1)
        sys.exit(0)
    if nums[s-1] != -1 and c != nums[s-1]:
        print(-1)
        sys.exit(0)
    nums[s-1] = c
nums = [0 if num == -1 else num for num in nums]
if n == 1:
    print(nums[0])
    sys.exit(0)
if nums[0] == 0:
    nums[0] = 1
print("".join(map(str,nums)))
import sys
import math
import heapq
from collections import defaultdict, deque
from decimal import *
def r():
    return int(input())
def rm():
    return map(int,input().split())
def rl():
    return list(map(int,input().split()))
mod=1000000007

'''E Multiplication 4'''
n,k=rm()
a=rl()
pos=[]
neg=[]
for i in a:
    if i>=0:
        pos.append(i)
    elif i<0:
        neg.append(i)

pos.sort(reverse=True)
neg.sort()
negg=[::-1]

for i in range(1,len(pos)):
    pos[i]=(pos[i-1]*pos[i])
for j in range(1,len(neg)):
    neg[j]=(neg[j-1]*neg[j])
    negg[j]=(negg[j-1]*negg[j])

if len(pos)==0:
    if k%2==0:
        print(neg[k-1]%mod)
    else:
        print(negg[k-1]%mod)
elif len(neg)==0:
    print(pos[k-1]%mod)
else:
    maxi=-math.inf
    for i in range(0,k+1,2):
        if i==0:
            if k-i<=len(pos):
                maxi=max(maxi,pos[k-i-1])
        elif k-i==0:
            if i<=len(neg):
                maxi=max(maxi,neg[i-1])
        elif i<=len(neg) and k-i<=len(pos):
            maxi=max(maxi,neg[i-1]*pos[k-i-1])
    print(maxi)

### FIXED CODE ###

MOD = 10**9+7
N,K = map(int, input().split())
A = list(map(int, input().split()))

A.sort(reverse = True)
ans = 1
if A[-1] >= 0:
    for i in range(K):
        ans *= A[i]
        ans %= MOD
elif A[0] < 0:
    if K % 2 == 0:
        for i in range(K):
            ans *= A[N-1-i]
            ans %= MOD
    else:
        for i in range(K):
            ans *= A[i]
            ans %= MOD
else:
    r,l = N-1,0
    n = 0
    while n < K:
        if K-n == 1:
            ans *= A[l]
            ans %= MOD
            n += 1
        else:
            if A[r]*A[r-1] > A[l]*A[l+1]:
                ans *= (A[r]*A[r-1])
                ans %= MOD
                r -= 2
                n += 2
            else:
                ans *= A[l]
                ans %= MOD
                l += 1
                n += 1
print(ans)
S=input()
h=S//3600
m=(S%3600)//60
s=S-((h*3600)+(m*60))
print(h,':',m,':',s)



### FIXED CODE ###

S=int(input())
h=S//3600
m=(S%3600)//60
s=S-((h*3600)+(m*60))
print(h,m,s, sep=':')
a = int(input())
print a.count("1")

### FIXED CODE ###

a = input()
if a == "000":
  print("0")
elif a == "001" or a == "010" or a == "100":
  print("1")
elif a == "111":
  print("3")
else:
  print("2")
import numpy as np
n, m = (int(i) for i in input().split())
a = np.sort(np.array([float(i) for i in input().split()]))
b, c = np.zeros(m), np.zeros(m)
for i in range(m):
    b[i], c[i] = (float(i) for i in input().split())

b = b[np.argsort(-c)]
c = c[np.argsort(-c)]
i = 0
for bb, cc in zip(b, c):
    for cnt in range(int(bb)):
        if a[i] < cc:
            a[i] = cc
        else:
            break
        i = i + 1
    else:
        continue
    break
print(int(sum(a)))

### FIXED CODE ###

import numpy as np
n, m = (int(i) for i in input().split())
a = np.sort(np.array([int(i) for i in input().split()], dtype='int64'))
b, c = np.zeros(m, dtype='int64'), np.zeros(m, dtype='int64')
for i in range(m):
    b[i], c[i] = (int(i) for i in input().split())

b = b[np.argsort(-c)]
c = c[np.argsort(-c)]
i = 0
for bb, cc in zip(b, c):
    for cnt in range(bb):
        if a[i] < cc:
            a[i] = cc
        else:
            break
        i = i + 1
        if i >= len(a):
            break
    else:
        continue
    break
print(int(sum(a)))
s=input()
n=int(s)
c=0
for i in range(len(s)):
    for j in range(i,len(s)):
        z = s[i:j]
        if int(z)%2019 == 0:
            c += 1

print(c)
        

### FIXED CODE ###

S = input()
N = len(S)
A = [int(S[i]) for i in range(N)]
A = A[::-1]

MOD = 2019

p10 = [1] * N
for i in range(1, N):
	p10[i] = (p10[i - 1] * 10) % MOD

for i in range(N):
	A[i] = (A[i] * p10[i]) % MOD

cumsum = [A[0]] * N
for i in range(1, N):
	cumsum[i] = (cumsum[i - 1] + A[i]) % MOD

cnt = [0] * MOD
cnt[0] = 1
for i in range(N):
	cnt[cumsum[i]] += 1

ans = 0
for i in range(MOD):
	ans += cnt[i] * (cnt[i] - 1) // 2

print(ans)
import numpy as np
n, k, q = map(int, input().split())
points = np.full(n, k)
minus = np.full(n)
for i in range(q):
    a = int(input())
    points = np.array(points) + np.array(minus)
    points[a - 1] += 1
for point in points:
    if point > 0:
        print("Yes")
    else:
        print("No")

### FIXED CODE ###

import numpy as np
n, k, q = map(int, input().split())
points = np.full(n, k)
z = np.full(n, 0)
points = points - q
for i in range(q):
    a = int(input())
    z[a - 1] += 1
points = points + z
for point in points:
    if point > 0:
        print("Yes")
    else:
        print("No")
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**4
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


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

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

A.sort()

ans = 0

for i in range(K-1,N_):
    ans += cmb(i,K-1,mod) * A[i]
    ans %= mod
    #print(ans)

for i in range(K-1,N_):
    ans -= cmb(i,K-1,mod) * A[N_-i-1]
    ans %= mod
    #print(ans)

print(ans)

### FIXED CODE ###

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


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

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

A.sort()

ans = 0

for i in range(K-1,N_):
    ans += cmb(i,K-1,mod) * A[i]
    ans %= mod
    #print(ans)

for i in range(K-1,N_):
    ans -= cmb(i,K-1,mod) * A[N_-i-1]
    ans %= mod
    #print(ans)

print(ans)
a=input()
b=input()
c=input()

print(max(c - (a-b), 0))

### FIXED CODE ###

l=list(map(int,input().split()))
a = l[0]
b = l[1]
c = l[2]


print(max(c - (a-b), 0))
L, R = map(int, input().split())
if R - L >= 2018 :
    print(0)
list = []
else :
    for i in range(L, R+1):
    k = i % 2019
    list.append(k)
    k = 0
list_sort = sorted(list())
l = list_sort[0] * list_sort[1]
print(l % 2019)


### FIXED CODE ###

L, R = map(int, input().split())
if R - L >= 2019 :
    print(0)

else :
    t = []
    for i in range(L, R):
        for j in range(i + 1, R + 1) :
            t.append((i * j) % 2019)
    print(min(t))