Harryxun/stf_run huggingface dataset:
import math

n = int(input())
k = int(input())
xs = [int(input()) for i in range(n)]

print(2*sum(min([x, k - x])))

### FIXED CODE ###

import math

n = int(input())
k = int(input())
xs = list(map(int, input().strip().split()))

print(2*sum([min([x, k - x]) for x in xs]))
N = int(input())
A = list(map(int,input().split()))
A.insert(0,0)
A.append(0)
cost = [abs(A[i+1] - A[i]) for i in range(N+1)]
for i in range(1,N+1):
    if A[i-1] <= A[i] <= A[i+1] or A[i+1] <= A[i] <= A[i-1]:
        sub = 0
    elif A[i-1] < A[i+1] < A[i]:
        sub = 2*(A[i]-A[i+1])
    elif A[i] < A[i-1] < A[i+1]:
        sub = 2*(A[i-1]-A[i])
    elif A[i+1] < A[i-1] < A[i]:
        sub = 2*(A[i] -A[i-1])
    elif A[i] < A[i+1]< A[i-1]:
        sub = 2*(A[i+1]-A[i])
    print(sum(cost) - sub)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
A.insert(0,0)
A.append(0)
cost = 0
for i in range(N+1):
    cost += abs(A[i+1]-A[i])
for i in range(1,N+1):
    sub = abs(A[i] - A[i+1]) + abs(A[i] - A[i-1]) - abs(A[i+1] - A[i-1])
    print(cost - sub)
import heapq
from collections import Counter
import math

n, a, b = map(int, input().split())
hs = map(int, (input() for _ in range(n)))
counter = [[-x, c] for x, c in Counter(hs).items()]

cum = 0
p = 0

heapq.heapify(counter)

def f(m, c, a, b):
    ans = 0
    ans += math.floor(m / (a + b*(c-1))) * c
    m -= math.floor(m / (a + b*(c-1))) * (a + b*(c-1))
    ans += min(math.ceil(m / b), math.ceil(m / (a + b*(c-1)))*c)
    return ans

while(True):
    x, y = heapq.heappop(counter)
    if len(counter) == 0:
        print(p + f(-x-cum, y, a, b))
        break
    v, _ = counter[0]
    if x==v:
        counter[0][1] += y
        continue
    m = math.ceil((v-x) / (a-b))
    if (-x) - (m*a + m*(y-1)*b + cum) <= 0 and (-v) - m*y*b <=0:
        print(p + f(-x-cum, y, a, b))
        break
    p += m*y
    cum += b*m*y
    heapq.heappush(counter, [x + m*(a-b), y])

### FIXED CODE ###

n = int(input())
ss = list(map(int, (input() for _ in range(n))))

full = sum(ss)
non0s = list(s for s in ss if s%10!=0)

if full%10!=0:
    print(full)
else:
    if len(non0s)==0:
        print(0)
    else:
        print(full - min(non0s))
python src/train.py --dataset cifar10 --comet --ct 0.5 --at 0.5

### FIXED CODE ###

a = int(input())
b = int(input())

ans = [1, 2, 3]
ans.remove(a)
ans.remove(b)

print(ans[0])
# coding: utf-8
import math
a, b, x = map(int, input().split())
print(90 - math.degrees(math.atan(a**3/(2*a**2*b-2*x))))

### FIXED CODE ###

# coding: utf-8
import math
a, b, x = map(int, input().split())
if x >= a**2*b/2:
    ans = 90 - math.degrees(math.atan2(a**3, (2*a**2*b-2*x)))
else:
    # ans = 90 - math.degrees(math.atan2(2*x, (a**2*b-2*x)))
    # ans = 90 - math.degrees(math.asin((2*x*a) / (b*math.sqrt(4*x**2 + a**2*b**4))))
    ans = 90 - math.degrees(math.asin(2*x/math.sqrt(a**2*b**4 + 4*x**2)))
print(ans)
a,b=map(int,input().split())
print(max(a+b,mac(a,b)+max(a-1,b-1)))


### FIXED CODE ###

a,b=map(int,input().split())
print(max(a+b,max(a,b)+max(a-1,b-1)))
num = raw_input()
num_list = raw_input()
num_list = num_list.split()
print "???".join(num_list)
 
for i in range(1, len(num_list)):
        temp = num_list[i]
        j = i - 1
        while (j >= 0 and num_list[j] > temp):
                num_list[j+1] = num_list[j]
                j -= 1
        num_list[j+1] = temp
        print "???".join(num_list)

### FIXED CODE ###

num = raw_input()
num_list = raw_input()
num_list = num_list.split()
print " ".join(num_list)

 
for i in range(1, len(num_list)):
        num_list = map(int, num_list)
        temp = num_list[i]
        j = i - 1
        while (j >= 0 and num_list[j] > temp):
                num_list[j+1] = num_list[j]
                j -= 1
        num_list[j+1] = temp
        num_list = map(str, num_list)
        print " ".join(num_list)
s = input()
weather = ["Sunny", "Cloudy", "Rainy"]
print(weather[(s.index(weather) + 1) % 3])

### FIXED CODE ###

s = input()
weather = ["Sunny", "Cloudy", "Rainy"]
print(weather[(weather.index(s) + 1) % 3])
S,K=input().split()
k=int(K)
for i in range(0,k):
    if S[i]!="1":
        print(S[i])
        break
else:
    print("1")


### FIXED CODE ###

S=input()
k=int(input())
for i in range(0,k):
    if S[i]!="1":
        print(S[i])
        break
else:
    print("1")
dxy = [[1,0],[0,1],[-1,0],[0,-1],[1,1],[-1,1],[-1,-1],[1,-1]]
def solve(field,w,h):
	if 0 <= w < W and 0 <= h < H and field[h][w] == 1:
		field[h][w] = 0
		for dx,dy in dxy:
			solve(field,w+dx,h+dy)

while 1:
	W,H = map(int,raw_input().split())
	if W == 0: break
	field = [map(int,raw_input().split()) for i in range(H)]
	ans = 0
	for h in range(H):
		for w in range(W):
			if field[h][w] == 1:
				solve(field,w,h)
				ans += 1
	print ans

### FIXED CODE ###

import sys
sys.setrecursionlimit(100000)

def dfs(x, y):
    C[y][x] = 0
    for dx,dy in zip([1,1,0,-1,-1,-1,0,1],[0,1,1,1,0,-1,-1,-1]):
        if 0 <= x+dx < w and 0 <= y+dy < h and C[y+dy][x+dx] == 1:
            dfs(x+dx, y+dy)

while 1:
    w,h = map(int,raw_input().split())
    if w == h == 0: break
    C = [map(int,raw_input().split()) for _ in xrange(h)]

    ans = 0
    for y in range(h):
        for x in range(w):
            if C[y][x] == 1:
                dfs(x, y)
                ans += 1
    print ans
data = list(map(int,input().split()))
if(data[0] < data[1]): data[0],data[1] = data[1],data[0]
z = data[0] % data[1]

def gcd(x,y):
    return x if y == 0 else gcd(y,x%y)

else: print(gcd)


### FIXED CODE ###

data = list(map(int,input().split()))
if(data[0] < data[1]): data[0],data[1] = data[1],data[0]

def gcd(x,y):
    return x if y == 0 else gcd(y,x%y)

print(gcd(data[0],data[1]))
R = int(raw_input())
G = int(raw_input())
print 2 * G - R

### FIXED CODE ###

R = int(raw_input())
G = int(raw_input())
print(2 * G - R)
x =int(input())
for n in range(x, 0, -1):
    for b in range(1, n + 1):
        for p in range(2, n + 1):
            if b ** p == n:
                print(n)
                exit()
            elif b ** p > n:
                break
print(1)


### FIXED CODE ###

a, b, c, d = map(int,input().split())
if abs(a - c) <= d:
    print('Yes')
elif abs(a - b) <= d and abs(b - c) <= d:
    print('Yes')
else:
    print('No')
N, Q = map(int, input().split(" "))
 
ns= [list(map(int, input().split(" ")))  for _ in range(N-1)]
vs = [list(map(int, input().split(" ")))  for _ in range(Q)]
#ns = sorted(ns)
 
flags = [False]*N
dic = [[] for _ in range(N)]
rlt = [0]*N
 
for i in range(N-1):
  dic[ns[i][1]-1] += [ns[i][0]-1]
  dic[ns[i][0]-1] += [ns[i][1]-1]
  
for j in range(Q):
  rlt[vs[j][0]-1] += vs[j][1]
  
for k in range(N):
  flags[k] = Ture
  for l in dic[k]:
    if flags[l]:
      continue
    else:
      rlt[l] += rlt[k]
      flags[l] = Ture
    
print(" ".join(map(str, rlt)))

### FIXED CODE ###

N, Q = map(int, input().split(" "))
 
ns= [list(map(int, input().split(" ")))  for _ in range(N-1)]
vs = [list(map(int, input().split(" ")))  for _ in range(Q)]

dic = [[] for _ in range(N)]
rlt = [0]*N


for i in range(N-1):
  dic[ns[i][0]-1] += [ns[i][1]-1]
  
for j in range(Q):
  rlt[vs[j][0]-1] += vs[j][1]
  
for k in range(N):
  for l in dic[k]:
    rlt[l] += rlt[k]
    
print(" ".join(map(str, rlt)))
N,K = map(int,input().split())
A = list(map(int,input().split()))

cnt = 1
result = []
AA = len(A[K-1:])

rresult = []
for i in range(AA):
    result_a = 1
    result = A[i:i+K]
    for t in result:
        result_a *= t
    rresult.append(result_a)

for t in range(len(rresult)):
    if t == 0:
        continue
    else:
        if rresult[t] > rresult[t-1]:
            print("Yes")
        else:
            print("No")


### FIXED CODE ###

M = int(input())

if 400<= M <=599:
    print("8")
elif 600<= M <=799:
    print("7")
elif 800<= M <=999:
    print("6")
elif 1000<= M <=1199:
    print("5")
elif 1200<= M <=1399:
    print("4")
elif 1400<= M <=1599:
    print("3")
elif 1600<= M <=1799:
    print("2")
elif 1800<= M <=1999:
    print("1")
numberOfMange= int(input()) % 10

if numberOfMange in [2,4,5,7,9]:
  print('hon')
elif numberOfMange in [0,1,6,8]:
  print('pon')
else numberOfMange:
  print('bon')

### FIXED CODE ###

numberOfMange= int(input()) % 10
 
if numberOfMange in [2,4,5,7,9]:
  print('hon')
elif numberOfMange in [0,1,6,8]:
  print('pon')
else:
  print('bon')
b = input()
if b ='A': print('T')
if b = 'T': print('A')
if b = 'C': print('G')
if b = 'G': print('C')

### FIXED CODE ###

b = input()
if b =='A': print('T')
if b == 'T': print('A')
if b == 'C': print('G')
if b == 'G': print('C')
X, N = map(int, input().split())  
A = [int(x) for x in input().split()]

index = 0
value = abs(A[0] - X)
up_list = [0]*(N+1)
down_list = [0]*(N+1)

for i in range(N):
  if abs(A[i] - X ) < N+1:
    if A[i] - X >= 0:
      up_list[A[i]-X] = 1
    if A[i] - X <= 0:
      down_list[abs(A[i]- X)] = 1

j = 0
while True:
  if up_list[j] ==0:
    print(X+j)
    break
  if down_list[j] == 0:
    print(X-j)
    break
  if j>N+1:
    print('fail')
    break
  j+=1
  

### FIXED CODE ###

X, N = map(int, input().split())
if not N ==0:
  A = [int(x) for x in input().split()]
  index = 0
  value = abs(A[0] - X)
  up_list = [0]*(N+1)
  down_list = [0]*(N+1)

  for i in range(N):
    if abs(A[i] - X ) < N+1:
      if A[i] - X >= 0:
        up_list[A[i]-X] = 1
      if A[i] - X <= 0:
        down_list[abs(A[i]- X)] = 1

  j = 0
  while True:
    if down_list[j] == 0:
      print(X-j)
      break
    if up_list[j] ==0:
      print(X+j)
      break
    if j>N+1:
      print('fail')
      break
    j+=1

else:
  print(X)
#input
n, k = map(int, input().split())

#output
mod = pow(10, 9) + 7

n_ = 2*10**5
fun = [1]*(n_+1)
for i in range(1,n_+1):
    fun[i] = fun[i-1]*i%mod
rev = [1]*(n_+1)
rev[n_] = pow(fun[n_],mod-2,mod)
for i in range(n_-1,0,-1):
    rev[i] = rev[i+1]*(i+1)%mod
def cmb(n,r):
    if n <= 0 or r < 0 or r > n: return 0
    return fun[n]*rev[r]%mod*rev[n-r]%mod

if n <= k-1:
    print(cmb(2*n-1, n))
else:
    answer = 0
    for m in range(k+1):
        answer += cmb(n, m)*cmb(n-1, m) % mod
        answer %= mod
    print(answer)

### FIXED CODE ###

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

#output
mod = pow(10, 9) + 7

n_ = 4*10**5 + 5
fun = [1]*(n_+1)
for i in range(1,n_+1):
    fun[i] = fun[i-1]*i%mod
rev = [1]*(n_+1)
rev[n_] = pow(fun[n_],mod-2,mod)
for i in range(n_-1,0,-1):
    rev[i] = rev[i+1]*(i+1)%mod
def cmb(n,r):
    if n <= 0 or r < 0 or r > n: return 0
    return fun[n]*rev[r]%mod*rev[n-r]%mod

if n <= k-1:
    print(cmb(2*n-1, n))
else:
    answer = 0
    for m in range(k+1):
        answer += cmb(n, m)*cmb(n-1, m) % mod
        answer %= mod
    print(answer)
pi =　3.14159265359
r = int(input())
print(r*2*pi)

### FIXED CODE ###

pi = 3.1415926536
r = int(input())
print(2*pi*r)
s = input()
if s[2] == s[3] && s[4] == s[5]:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

s = input()
if s[2] == s[3] and s[4] == s[5]:
  print("Yes")
else:
  print("No")
n = int(input())
A = list(map(int,input().split()))

L = [0]*(n+2)
R = [0]*(n+2)

for i in range(n,-1,-1):
  L[i] = A[i] + (L[i+1]+1)//2
  R[i] = A[i] + R[i+1]
  
if L[0] > 1:
  print(-1)
else:
  ans = 0
  tmp = 1
  for i in range(n+1):
    ans += tmp          
    tmp -= A[i]    
    tmp = min(tmp*2,R[i+1])
    
print(ans)    

### FIXED CODE ###

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

L = [0]*(n+2)
R = [0]*(n+2)
L[n] = A[n]
R[n] = A[n]

for i in range(n,-1,-1):
  L[i] = A[i] + (L[i+1]+1)//2
  R[i] = A[i] + R[i+1]
  
if L[0]>1:
  print(-1)
else:
  tmp = 1
  ans = 0
  for i in range(n+1):
    ans += tmp
    tmp -= A[i]
    tmp = min(tmp*2,R[i+1])    
  print(ans)
import numpy as np
#import copy
N = int(input())
#time=list(map(int,input().split()))
time=np.array(input().split(),dtype=np.int64)
M = int(input())

p={}
x={}
for i in range(M):
    p[i],x[i] = map(int, input().split())
#print(x[1])
sumT=np.sum(time)
for i in range(M):
    PP = p[i]
#    print(np.sum(time_new))
    print(sumT - time[PP-1] + x[PP-1])

### FIXED CODE ###

import numpy as np
N = int(input())
#time=list(map(int,input().split()))
time=np.array(input().split(),dtype=np.int64)
M = int(input())

p={}
x={}
for i in range(M):
    p[i],x[i] = map(int, input().split())
#print(x[1])

sumT=np.sum(time)
for i in range(M):
    PP = p[i]
#    print(np.sum(time_new))
    tot = sumT - time[PP-1] + x[i]
    print(tot)
n=int(input())
s=input().split()
q=int(input())
t=input().split()
cnt=0

left=0
right=n
for i in range(t):
    while left<right:
        mid=(left+right)/2
        if s[mid]==t[i]:
            return cnt+=1
        elif s[mid]>t[i]:
            right=mid
        else:
            left=mid+1
            
            
print(cnt)



### FIXED CODE ###

n=int(input())
S=input().split()
q=int(input())
T=input().split()

S=list(map(int,S))
T=list(map(int,T))

cnt=0

for i in range(q):
	left=0
	right=n-1
	while left<=right:
		mid=int((left+right)/2)
		if S[left]>T[i] and S[right]<T[i]:
			break
		if S[mid]==T[i]:
			cnt+=1
			break
		elif S[mid]>T[i]:
			right=mid-1
		elif S[mid]<T[i]:
			left=mid+1

print(cnt)
import math
n = int(input())

print((2*n)//math.gcd(2,n))

### FIXED CODE ###


def gcd(a, b):
    """Calculate the Greatest Common Divisor of a and b.

    Unless b==0, the result will have the same sign as b (so that when
    b is divided by it, the result comes out positive).
    """
    while b:
        a, b = b, a%b
    return a



n = int(input())

print((2*n)//gcd(2,n))
N,M=map(int,input().split())
S=(range(1,M+1))
for i in range(N):
    K,*A=map(int,input().split())
    S&=set(A)
print(len(S))

### FIXED CODE ###

N,M=map(int,input().split())
S=set(range(1,M+1))
for i in range(N):
    K,*A=map(int,input().split())
    S&=set(A)
print(len(S))
a, b, c, k = map(int,input().split())
sum = 0
if k > 0:
    if a > 0:
        if a > k:
            sum = sum + k
        else:
            sum = sum + a
    k = k - a
if k > 0:
    if b > 0:
        k = k - b
if k > 0:
    if c > 0:
        sum = sum + k (-1)
print(sum)

### FIXED CODE ###

a, b, c, k = map(int, input().split())
ans = 0
if k <= a:
    print(k)
else:
    k -= a
    ans += a
    if k <= b:
        print(ans)
    else:
        k -= b
        ans += -1 * k
        print(ans)
import re
n = input()
s = input()
k = input()
chlist = list(s)
nonreplace = chlist[int(k)]
for num in range(int(n)):
  if chlist[num] == nonreplace:
    pass
  else:
    chlist[num] = "*"
stred = ''.join(chlist)
print(stred)


### FIXED CODE ###

import re
n = input()
s = input()
k = input()
chlist = list(s)
ked = int(k) - 1
nonreplace = chlist[int(ked)]
for num in range(int(n)):
  #numed = num - 1
  if chlist[num] == nonreplace:
    pass
  else:
    chlist[num] = "*"
stred = ''.join(chlist)
print(stred)
n, m = map(int, input().split())
li = []
for i in range(m):
  li.append(list(input().split()))
li_a = [0 for i in range(m)]
li_b = [0 for i in range(m)]
a = 0
b = 0
for j in range(m):
  if li[j][1] == "WA":
    li_b[int(li[j][0])] += 1
  elif li[j][1] == "AC" and li_a[int(li[j][0])] == 0:
    a += 1
    b += li_b[int(li[j][0])]
    li_a[int(li[j][0])] += 1
print(a, b)

### FIXED CODE ###

n, m = map(int, input().split())
li = []
for i in range(m):
  li.append(list(input().split()))
li_a = [0 for i in range(n)]
li_b = [0 for i in range(n)]
a = 0
b = 0
for j in range(m):
  if li[j][1] == "WA":
    li_b[int(li[j][0])-1] += 1
  elif li[j][1] == "AC" and li_a[int(li[j][0])-1] == 0:
    a += 1
    b += li_b[int(li[j][0])-1]
    li_a[int(li[j][0])-1] += 1
print(a, b)
N = int(input())
A = list(map(int, input().split()))

pm = sum(A)
te = 1
if A[0] != 0 or A[N] == 0:
    print(-1)
else:
    for i in A:
        pm -= i
        e = min((e-i) * 2,pm)
        if e < 0:
            break
        te += e
    if e < 0:
        print(-1)
    else:
        print(te)

### FIXED CODE ###

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

pm = sum(A)
e = 1
te = 1
for i in A:
    pm -= i
    e = min((e-i) * 2,pm)
    if e < 0:
        break
    te += e
if e < 0:
    print(-1)
else:
    print(te)
N,A = map(int, input().split())
if N%500=< A:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

N = int(input())
A = int(input())

if N%500 <= A:
    print("Yes")
else:
    print("No")
N, K = 13, 1
S = "0000011100110"

# N, K = 2, 2
# S = "00"


# N, K = 1, 1
# S = "1"
#
#
# N, K = 5, 1
# S = "00010"
#
N, K = map(int,input().split())
S = input()

def calculate(n, k, s):
    s = list(s)

    result = [{'start': 0, 'end': 0}]
    for i in range(n):

        previous = s[i - 1]
        current = s[i]

        if i == 0:
            if s[i] == '1':
                result.append({'start': 0})
        else:
            if (current == '0') and (previous == '1'):
                res = result[-1]
                res.__setitem__('end', i)
                result[-1] = res

            if (current == '1') and (previous == '0'):
                result.append({'start': i})

            if i == n - 1 and s[i] == '1':
                res = result[-1]
                res.__setitem__('end', i + 1)
                result[-1] = res

    result.append({'start': n, 'end': n})
    maxValue = 0
    if len(result) > k:
        for i in range(len(result) - k):
            val = result[i + k]['end'] - result[i]['start']
            maxValue = max(val, maxValue)
    else:
        maxValue = max(maxValue, result[-1]['end'] - result[0]['start'])
    print(result)
    print(maxValue)


calculate(N, K, S)


### FIXED CODE ###

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

def calculate(n, k, s):
    s = list(s)

    result = [{'start': 0, 'end': 0}]
    for i in range(n):

        previous = s[i - 1]
        current = s[i]

        if i == 0:
            if s[i] == '1':
                result.append({'start': 0})
        else:
            if (current == '0') and (previous == '1'):
                res = result[-1]
                res.__setitem__('end', i)
                result[-1] = res

            if (current == '1') and (previous == '0'):
                result.append({'start': i})

        if i == n - 1 and s[i] == '1':
            res = result[-1]
            res.__setitem__('end', i + 1)
            result[-1] = res

    result.append({'start': n, 'end': n})


    # print(result)
    maxValue = 0
    if len(result) > k:
        for i in range(len(result) - k):
            val = result[i + k]['end'] - result[i]['start']
            maxValue = max(val, maxValue)
    else:
        maxValue = max(maxValue, result[-1]['end'] - result[0]['start'])


    print(maxValue)


calculate(N, K, S)
N = int(input())
if N < 10 :
	print(N)
elif N < 100 :
	print(9)
elif N < 1000 :
	print(9 + (N - 100 + 1))
elif N < 10000 :
	print(9 + 900)
elif N < 100000 :
	print(9 + 900 + (N - 10000 + 1))
else :
	print(9 + 900 + 90000)


### FIXED CODE ###

A, B, C = list(map(int, input().split()))
ans = C - (A - B)
if ans >= 0 :
	print(ans)
else :
	print(0)
X,Y,Z,K = list(map(int,input().split()))
A = [(sorted(list(map(int,input().split())))[::-1]) for i in range(3)]

import heapq

heap = []
item = (0,(0,0,0))
heapq.heappush(heap, item)
considered_dict = set(item[1])

ret = []
max_ = A[0][0]+A[1][0]+A[2][0]
while len(ret) < K:
    task  = heapq.heappop(heap)
    score,(x,y,z) =task
    ret.append(score)
    # assign next task
    if x+1 != X-1 and (x+1,y,z) not in considered_dict:
        heapq.heappush(heap, (max_-A[0][x+1]-A[1][y]-A[2][z],(x+1,y,z) ))
        considered_dict |= {(x+1,y,z)}
        
                       
    if y+1 != Y-1 and (x,y+1,z) not in considered_dict:
        heapq.heappush(heap, (max_-A[0][x]-A[1][y+1]-A[2][z],(x,y+1,z) ))
        considered_dict |= {(x,y+1,z)}
                       
    if z+1 != Z-1 and (x,y,z+1) not in considered_dict:
        heapq.heappush(heap, (max_-A[0][x]-A[1][y]-A[2][z+1],(x,y,z+1) ))
        considered_dict |= {(x,y,z+1)}


for i in ret:
    print(max_-i)


### FIXED CODE ###

X,Y,Z,K = list(map(int,input().split()))
A = [(sorted(list(map(int,input().split())))[::-1]) for i in range(3)]
b = sorted([i+j for i in A[0] for j in A[1]])[-K:]
for i in sorted([i+j for i in b for j in A[2]])[-K:][::-1] :
  print(i)
def main():
    n,k = map(int,input().split())
    A = list(map(int,input().split()))
    A.sort()
    mod=10**9+7
    min_sum=max_sum=0    
    def we_want(x):
        ans=1
        for i in range(k-1):
            ans=ans*(x-i)*pow(i+1,mod-2,mod)%mod 
        return ans 
        
    def check_min(i):
        if n-i>=k:
            min_sum+=we_want(n-1-i)*A[i]
            min_sum%=mod
    def check_max(i):
        if i>=k-1:
            max_sum+=we_want(i)*A[i]        
            max_sum%=mod
    for i in range(len(A)):
        check_min(i)
        check_max(i)
    print((max_sum-min_sum)%mod)

if __name__=='__main__':
    main()

### FIXED CODE ###

n, k = map(int, input().split())
a = sorted(list(map(int, input().split())))
mod = 10 ** 9 + 7
b = 1
ans = 0
for i in range(k - 1, n):
    ans += b * (a[i] - a[n - i - 1])
    ans %= mod
    b = (i+1)*pow(i-k+2, mod - 2, mod) * b % mod
print(ans)
k,s = map(int,input().split())
n = 0
for x in range(k+1):
    for y in range(k+1):
        z = s-(x+y)
        if z <= k and z > 0=:
            if x+y+z==s:
                n += 1
                
print(n)
                

### FIXED CODE ###

k,s = map(int,input().split())
n = 0
for x in range(k+1):
    for y in range(k+1):
        z = s-(x+y)
        if z <= k and z >= 0 and x+y+z==s:
            n += 1
print(n)
S=input()
T=input()

if T.startswith(S):
    print(Yes)
else:
    print(No)


### FIXED CODE ###

S=input()
T=input()

if T.startswith(S):
    print("Yes")
else:
    print("No")
def BC132_D():
    n, k = list(map(int, input().split(' ')))
    f = [1] * max(k, n - k + 2)
    for i in range(1, len(f) + 1):
        f[i] = f[i - 1] * i

    def comb(n, r):
        if n < r: return 0
        return f[n] // f[r] // f[n - r]

    for i in range(1, k + 1):
        print(comb(k - 1, i - 1) * comb(n - k + 1, i) % (10**9 + 7))

BC132_D()

### FIXED CODE ###

import math
def bi(x, y):
  if x < y or y < 0 or x < 0: return 0
  if y == 0: return 1
  return math.factorial(x) // math.factorial(y) // math.factorial(x - y)

n, k = list(map(int, input().split(' ')))
for i in range(1, k + 1):
  print(bi(k - 1, i - 1) * bi(n - k + 1, i) % (10**9 + 7))
a, b = map(int, input())
c = input()
print('Yes' if c[a] == '-' and c.count('-') == 1 else 'No')

### FIXED CODE ###

a, b = map(int, input().split())
c = input()
print('Yes' if c[a] == '-' and c.count('-') == 1 else 'No')
a,b,c = input()
n = 0
for i in range(a,b+1):
    if c%i == 0 :
     n = n+1
print(n)


### FIXED CODE ###

a,b,c = map(int,input().split())
n = 0
for i in range(a,b+1):
    if c%i == 0 :
     n = n+1
print(n)