CodeEff/ECCO huggingface dataset:
# Original solution
def find_power(n,mod):
    # 0!からn!までのびっくりを出してくれる関数(ただし、modで割った値に対してである）
    powlist=[0]*(n+1)
    powlist[0]=1
    powlist[1]=1
    for i in range(2,n+1):
        powlist[i]=powlist[i-1]*i%(mod)
    return powlist

def find_inv_power(n):
    #0!からn!までの逆元を素数10**9+7で割ったあまりリストを作る関数
    powlist=find_power(n,10**9+7)
    check=powlist[-1]
    first=1
    uselist=[0]*(n+1)
    secondlist=[0]*30
    secondlist[0]=check
    secondlist[1]=check**2
    for i in range(28):
        secondlist[i+2]=(secondlist[i+1]**2)%(10**9+7)
    a=format(10**9+5,"b")
    for j in range(30):
        if a[29-j]=="1":
            first=(first*secondlist[j])%(10**9+7)
    uselist[n]=first
    for i in range(n,0,-1):
        uselist[i-1]=(uselist[i]*i)%(10**9+7)
    return uselist

def combi(a,b,n,r,mod):
    if n<r:
        return 0
    elif n>=r:
        return (a[n]*b[r]*b[n-r])%(mod)
aa=find_power(10**5,10**9+7)
bb=find_inv_power(10**5)
mod=10**9+7

n,k=list(map(int,input().split()))
lists=list(map(int,input().split()))
import collections 
L=collections.Counter(lists)
L=dict(L)
uselist=[]
for a,v in list(L.items()):
    uselist.append((a,v))
uselist=sorted(uselist,key=lambda x:x[0])
maxlist=[(0,0)]

counter=0
for some in uselist:
    counter+=some[1]
    maxlist.append((some[0],counter))

MAX=0

for j in range(1,len(maxlist)):
    MAX+=(combi(aa,bb,maxlist[j][1],k,mod)-combi(aa,bb,maxlist[j-1][1],k,mod))*maxlist[j][0]
    MAX=MAX%mod

  
uselist=uselist[::-1]

maxlist=[(0,0)]

counter=0
for some in uselist:
    counter+=some[1]
    maxlist.append((some[0],counter))

MIN=0

for j in range(1,len(maxlist)):
    MIN+=(combi(aa,bb,maxlist[j][1],k,mod)-combi(aa,bb,maxlist[j-1][1],k,mod))*maxlist[j][0]
    MIN=MIN%mod

print(((MAX-MIN)%mod))


# Optimized solution
class Combi():
    def __init__(self, N, mod):
        self.power = [1 for _ in range(N+1)]
        self.rev = [1 for _ in range(N+1)]
        self.mod = mod
        for i in range(2, N+1):
            self.power[i] = (self.power[i-1]*i) % self.mod
        self.rev[N] = pow(self.power[N], self.mod-2, self.mod)
        for j in range(N, 0, -1):
            self.rev[j-1] = (self.rev[j]*j) % self.mod

    def com(self, K, R):
        if K < R:
            return 0
        else:
            return ((self.power[K])*(self.rev[K-R])*(self.rev[R])) % self.mod

    def pom(self, K, R):
        if K < R:
            return 0
        else:
            return (self.power[K])*(self.rev[K-R]) % self.mod


def main():
    mod = 10**9+7
    N, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    A.sort()
    c = Combi(N, mod)
    res = 0
    for i, v in enumerate(A):
        res += c.com(i, K-1)*v
        res -= c.com(N-1-i, K-1)*v
        res %= mod
    print(res)
    return


if __name__ == "__main__":
    main()
# Original solution
MOD = 10 ** 9 + 7

def mymodBinomial(n, k, p):
	if k < 0 or k > n:
		return 0
	else:
		numerator = 1
		for i in range(k):
			numerator = (numerator * (n - i)) % p
		denominator = 1
		for i in range(1, k + 1):
			denominator = (denominator * i) % p
		return (numerator * pow(denominator, p - 2, p)) % p


if __name__ == "__main__":
	N, K = list(map(int, input().split()))
	A = list(map(int, input().split()))
	A.sort()
	# print(A)
	l = [0]*(N + 1)
	for i in range(1, N+1):
		l[i] = mymodBinomial(i-1, K-1, MOD)
	ans = 0
	# print(l)
	for i in range(N):
		ans += (A[i] - A[N-1-i])* l[i+1] % MOD
	print((ans % MOD))

# Optimized solution
MOD = 10 ** 9 + 7

# def mymodBinomial(n, k, p):
# 	if k < 0 or k > n:
# 		return 0
# 	else:
# 		numerator = 1
# 		for i in range(k):
# 			numerator = (numerator * (n - i)) % p
# 		denominator = 1
# 		for i in range(1, k + 1):
# 			denominator = (denominator * i) % p
# 		return (numerator * pow(denominator, p - 2, p)) % p

def modBinomiallist(n, k, p):
	l = [0 for i in range(n)]
	for i in range(n):
		if i < k:
			l[i] = 0
		elif i == k:
			l[i] = 1
		else:
			l[i] = l[i - 1] * i * pow(i-k, p-2, p) % p
	return l


if __name__ == "__main__":
	N, K = list(map(int, input().split()))
	A = list(map(int, input().split()))
	A.sort()
	# print(A)
	# l = [0]*(N + 1)
	# for i in range(1, N+1):
	# 	l[i] = mymodBinomial(i-1, K-1, MOD)
	# print(l)
	l = modBinomiallist(N, K-1, MOD)
	# print(l)
	ans = 0
	# print(l)
	for i in range(N):
		ans += (A[i] - A[N-1-i])* l[i] % MOD
	print((ans % MOD))
# Original solution
import itertools

n, k = list(map(int, input().split()))
alist = sorted(list(map(int, input().split())))
alist_rev = alist[::-1]
divide = 10**9 + 7

def comb(s, n):
    return len(list(itertools.combinations(s, n)))

amax = 0
i = 0
while i <= n-k:
    amax += alist_rev[i] * comb(alist_rev[i+1:], k-1)
    i += 1

amin = 0
i = 0
while i <= n-k:
    amin += alist[i] * comb(alist[i+1:], k-1)
    i += 1

print(((amax - amin) % divide))


# Optimized solution
import itertools
import math

n, k = list(map(int, input().split()))
alist = sorted(list(map(int, input().split())))
alist_rev = alist[::-1]
divide = 10**9 + 7

def comb(n, k):
    return math.factorial(n) // (math.factorial(n-k) * math.factorial(k))



amax = 0
i = n-1
while i >= k-1:
    amax += alist[i] * comb(i, k-1)
    i -= 1

amin = 0
i = 0
while i <= n-k:
    amin += alist[i] * comb(n-i-1, k-1)
    i += 1

print(((amax - amin) % divide))
# Original solution
#!/usr/bin/env python3

def extgcd(a, b):
    if b == 0:
        return [1, 0, a]
    x, y, g = extgcd(b, a%b)
    return [y, x - a//b * y, g]


def mod_inverse(a, m):
    x, y, _ = extgcd(a, m)
    return (m+x%m) % m


def mod_comb(n, k, mod):
    mul, div = 1, 1
    for i in range(k):
        mul *= (n-i)
        div *= (i+1)
        mul %= mod
        div %= mod
    return mul * mod_inverse(div, mod) % mod


n, k = list(map(int, input().split()))
a = [ int(x) for x in input().split() ]
a.sort(reverse=True)

mod = int(1e9)+7
ans = 0

for i, v in enumerate(a):
    ans += v*mod_comb(n-i-1, k-1, mod)
    ans %= mod
    ans -= v*mod_comb(i, k-1, mod)
    ans %= mod
    
print(ans)


# Optimized solution
#!/usr/bin/env python3

MOD = int(1e9)+7

def extgcd(a, b):
    if b == 0:
        return [1, 0, a]
    x, y, g = extgcd(b, a%b)
    return [y, x - a//b * y, g]


def mod_inverse(a, m):
    x, y, _ = extgcd(a, m)
    return (m+x%m) % m


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

maxf = 2*n + 10
f = [1 for _ in range(maxf)]
invf = [1 for _ in range(maxf)]

for i in range(1, maxf):
    f[i] = (i * f[i - 1]) % MOD
 
invf[maxf-1] = pow(f[maxf - 1], MOD-2, MOD)
for i in range(maxf-1, 0, -1):
    invf[i-1] = (i*invf[i]) % MOD
 
def comb(a, b):
    if b > a:
        return 0
    return (((f[a]*invf[b]) % MOD) * invf[a-b]) % MOD

a = [ int(x) for x in input().split() ]
a.sort(reverse=True)

ans = 0

for i, v in enumerate(a):
    ans += v*comb(n-i-1, k-1)
    ans %= MOD
    ans -= v*comb(i, k-1)
    ans %= MOD
    
print(ans)
# Original solution
import bisect
import collections


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 = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
mod = 10**9 + 7

table = collections.defaultdict(int)

for x in A:
    table[x] += 1
ans = 0
for x in table:
    # print(x)
    i = bisect.bisect_left(A, x)
    if i+table[x] >= K:
        for j in range(1, table[x] + 1):
            ans += cmb(i, K-j, mod)*x*cmb(table[x], j, mod)
            # print(ans, j)

    i = bisect.bisect_right(A, x)

    if N - (i-table[x]) >= K:
        for j in range(1, table[x] + 1):
            ans -= cmb(N-i, K-j, mod)*x*cmb(table[x], j, mod)
            # print(ans, j)
    ans %= mod
print(ans)


# Optimized solution
def main():
  import collections
  import bisect


  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**5
  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 = list(map(int, input().split()))
  A = list(map(int, input().split()))
  table = collections.defaultdict(int)
  A.sort()
  for x in A:
      table[x] += 1
  ans = 0
  for x in table:
      left = bisect.bisect_left(A, x)
      for i in range(1, table[x]+1):
          if left >= K - i:
              ans += x * cmb(left, K - i, mod) * cmb(table[x], i, mod)

      right = left + table[x] - 1
      for i in range(1, table[x]+1):
          if N - 1 - right >= K - i:
              ans -= x * cmb(N - 1 - right, K-i, mod) * cmb(table[x], i, mod)
      ans %= mod
  print(ans)
main()
# Original solution
def solve():
    from sys import stdin
    f_i = stdin
    
    mod = 10 ** 9 + 7
    
    N, K = list(map(int, f_i.readline().split()))
    A = sorted(map(int, f_i.readline().split()))
    
    num = [1] * (N - K + 1)
    for i, j in zip(list(range(K, N)), list(range(1, N))):
        num[j] = num[j-1] * i // j
    
    ans = sum(a * n % mod for a, n in zip(A[K-1:], num))
    ans -= sum(a * n % mod for a, n in zip(A, num[::-1]))
    
    print((ans % mod))

solve()

# Optimized solution
def solve():
    from sys import stdin
    f_i = stdin
    
    mod = 10 ** 9 + 7
    
    N, K = list(map(int, f_i.readline().split()))
    A = sorted(map(int, f_i.readline().split()))
    
    comb = 1
    ans = A[K-1] - A[N-K]
    for i, j, A_s, A_t in zip(list(range(K, N)), list(range(1, N)), A[K:], A[N-K-1::-1]):
        comb = comb * i // j
        ans += (A_s - A_t) * comb
    
    print((ans % mod))

solve()
# Original solution
#----------------------------------------------------------
P = 10**9 + 7
N = 500000 #使える最大値、値に注意
inv = [0] + [1] # 1/x
finv = [1] + [1] # 1/x!
fac = [1] + [1] # x!
for i in range(2,N):
  inv += [inv[P % i] * (P - int(P / i)) % P]
  fac += [(fac[i-1] * i) % P]
  finv += [(finv[i-1] * inv[i]) % P]

def comb(a, b):
    if a<b:
        return -1 # error
    return (fac[a] * ((finv[b] * finv[a-b]) % P)) %P
#----------------------------------------------------------

n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
a = sorted(a, key=lambda x: x, reverse=False)
ans = 0
# a[i]が最小値になる場合の数
for i in range(len(a)):
    tmp = comb(n-1-i, k-1)
    if tmp<0:
        continue
    if a[i] < 0:
        ans = (ans + (abs(a[i])*tmp)%P)%P
    else:
        ans = (ans - (abs(a[i])*tmp)%P + P)%P

# a[i]が最大値になる場合の数
for i in range(len(a)):
    tmp = comb(n-1-i, k-1)
    if tmp<0:
        continue
    if a[n-1-i] < 0:
        ans = (ans - (abs(a[n-1-i])*tmp)%P + P)%P
    else:
        ans = (ans + (abs(a[n-1-i])*tmp)%P)%P
print(ans)


# Optimized solution
#----------------------------------------------------------
P = 10**9 + 7
N = 200000 #使える最大値、値に注意
inv = [0] + [1] # 1/x
finv = [1] + [1] # 1/x!
fac = [1] + [1] # x!
for i in range(2,N):
  inv += [inv[P % i] * (P - int(P / i)) % P]
  fac += [(fac[i-1] * i) % P]
  finv += [(finv[i-1] * inv[i]) % P]

def comb(a, b):
    if a<b:
        return -1 # error
    return (fac[a] * ((finv[b] * finv[a-b]) % P)) %P
#----------------------------------------------------------

n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
a = sorted(a, key=lambda x: x, reverse=False)
ans = 0
# a[i]が最小値になる場合の数
for i in range(len(a)):
    tmp = comb(n-1-i, k-1)
    if tmp<0:
        continue
    if a[i] < 0:
        ans = (ans + (abs(a[i])*tmp)%P)%P
    else:
        ans = (ans - (abs(a[i])*tmp)%P + P)%P

# a[i]が最大値になる場合の数
for i in range(len(a)):
    tmp = comb(n-1-i, k-1)
    if tmp<0:
        continue
    if a[n-1-i] < 0:
        ans = (ans - (abs(a[n-1-i])*tmp)%P + P)%P
    else:
        ans = (ans + (abs(a[n-1-i])*tmp)%P)%P
print(ans)
# Original solution
#----------------------------------------------------------
P = 10**9 + 7
N = 200000 #使える最大値、値に注意
inv = [0] + [1] # 1/x
finv = [1] + [1] # 1/x!
fac = [1] + [1] # x!
for i in range(2,N):
  inv += [inv[P % i] * (P - int(P / i)) % P]
  fac += [(fac[i-1] * i) % P]
  finv += [(finv[i-1] * inv[i]) % P]

def comb(a, b):
    if a<b:
        return -1 # error
    return (fac[a] * ((finv[b] * finv[a-b]) % P)) %P
#----------------------------------------------------------

n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
a = sorted(a, key=lambda x: x, reverse=False)
ans = 0
# a[i]が最小値になる場合の数
for i in range(len(a)):
    tmp = comb(n-1-i, k-1)
    if tmp<0:
        continue
    if a[i] < 0:
        ans = (ans + (abs(a[i])*tmp)%P)%P
    else:
        ans = (ans - (abs(a[i])*tmp)%P + P)%P

# a[i]が最大値になる場合の数
for i in range(len(a)):
    tmp = comb(n-1-i, k-1)
    if tmp<0:
        continue
    if a[n-1-i] < 0:
        ans = (ans - (abs(a[n-1-i])*tmp)%P + P)%P
    else:
        ans = (ans + (abs(a[n-1-i])*tmp)%P)%P
print(ans)


# Optimized solution
#----------------------------------------------------------
P = 10**9 + 7
N = 100001 #使う最大値+1以上にする、値に注意3*10^5とかにしとくと安心
inv = [0] + [1] # 1/x
finv = [1] + [1] # 1/x!
fac = [1] + [1] # x!
for i in range(2,N):
  inv += [inv[P % i] * (P - int(P / i)) % P]
  fac += [(fac[i-1] * i) % P]
  finv += [(finv[i-1] * inv[i]) % P]

def comb(a, b):
    if a<b:
        return -1 # error
    return (fac[a] * ((finv[b] * finv[a-b]) % P)) %P
#----------------------------------------------------------

n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
a = sorted(a, key=lambda x: x, reverse=False)
ans = 0
# a[i]が最小値になる場合の数
for i in range(len(a)):
    tmp = comb(n-1-i, k-1)
    if tmp<0:
        continue
    if a[i] < 0:
        ans = (ans + (abs(a[i])*tmp)%P)%P
    else:
        ans = (ans - (abs(a[i])*tmp)%P + P)%P

# a[i]が最大値になる場合の数
for i in range(len(a)):
    tmp = comb(n-1-i, k-1)
    if tmp<0:
        continue
    if a[n-1-i] < 0:
        ans = (ans - (abs(a[n-1-i])*tmp)%P + P)%P
    else:
        ans = (ans + (abs(a[n-1-i])*tmp)%P)%P
print(ans)
# Original solution
import math
from functools import lru_cache
from operator import mul
from functools import reduce


def resolve():
    import sys
    input = sys.stdin.readline
    MOD = 10**9 + 7
    N, K = list(map(int, input().split()))
    A = list(map(int, input().split()))

    A.sort()
    B = A[::-1]

    @lru_cache(maxsize=None)
    def combinations_count__(n, r):
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

    @lru_cache(maxsize=None)
    def combinations_count____(n, r):
        r = min(r, n - r)
        numer = reduce(mul, list(range(n, n - r, -1)), 1)
        denom = reduce(mul, list(range(1, r + 1)), 1)
        return numer // denom

    def combinations_count_(n, r):
        if n - r < r: r = n - r
        if r == 0: return 1
        if r == 1: return n

        numerator = [n - r + k + 1 for k in range(r)]
        denominator = [k + 1 for k in range(r)]

        for p in range(2,r+1):
            pivot = denominator[p - 1]
            if pivot > 1:
                offset = (n - r) % p
                for k in range(p-1,r,p):
                    numerator[k - offset] /= pivot
                    denominator[k] /= pivot

        result = 1
        for k in range(r):
            if numerator[k] > 1:
                result *= int(numerator[k])

        return result

    def modinv(a, mod=10**9+7):
        return pow(a, mod-2, mod)

    def combinations_count(n, r, mod=10**9+7):
        if (r < 0) or (n < r):
            return 0
        r = min(r, n-r)
        return fact[n] * factinv[r] * factinv[n-r] % mod
    
    fact = [1, 1]
    factinv = [1, 1]
    inv = [0, 1]
    for i in range(2, N + 1):
        fact.append((fact[-1] * i) % MOD)
        inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
        factinv.append((factinv[-1] * inv[-1]) % MOD)

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

    print((sum % MOD))


if __name__ == "__main__":
    resolve()

# Optimized solution
import math
from functools import lru_cache
from operator import mul
from functools import reduce


def resolve():
    import sys
    input = sys.stdin.readline
    MOD = 10**9 + 7
    N, K = list(map(int, input().split()))
    A = list(map(int, input().split()))

    def combinations_count(n, r, mod=10**9+7):
        if (r < 0) or (n < r):
            return 0
        r = min(r, n-r)
        return fact[n] * factinv[r] * factinv[n-r] % mod
    
    fact = [1, 1]
    factinv = [1, 1]
    inv = [0, 1]
    for i in range(2, N + 1):
        fact.append((fact[-1] * i) % MOD)
        inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
        factinv.append((factinv[-1] * inv[-1]) % MOD)

    A.sort()
    B = A[::-1]

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

    print((sum % MOD))


if __name__ == "__main__":
    resolve()
# Original solution
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7

A.sort()

factorial = [1]
for i in range(1, N + 1):
    factorial.append(factorial[-1] * i)
inv_factorial = [-1] * (N + 1)
inv_factorial[-1] = pow(factorial[-1], MOD - 2, MOD)
for i in reversed(list(range(N))):
    inv_factorial[i] = inv_factorial[i + 1] * (i + 1) % MOD


ans = 0
for i in range(N - K + 1):
    c = factorial[N - 1 - i] * inv_factorial[K - 1] * inv_factorial[N - K - i]
    ans += c * (A[-1 - i] - A[i])
    ans %= MOD

print(ans)


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

A.sort()

factorial = [1]
for i in range(1, N + 1):
    factorial.append(factorial[-1] * i  % MOD)
inv_factorial = [-1] * (N + 1)
inv_factorial[-1] = pow(factorial[-1], MOD - 2, MOD)
for i in reversed(list(range(N))):
    inv_factorial[i] = inv_factorial[i + 1] * (i + 1) % MOD


ans = 0
for i in range(N - K + 1):
    c = factorial[N - 1 - i] * inv_factorial[K - 1] * inv_factorial[N - K - i]
    ans += c * (A[-1 - i] - A[i])
    ans %= MOD

print(ans)
# Original solution
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
A = sorted(A)

def ncr(n, r, p):
  num = den = 1
  for i in range(r):
    num = (num * (n - i)) % p
    den = (den * (i + 1)) % p
  return (num * pow(den, p - 2, p)) % p
p=10**9+7

ans = 0
for i in range(N-K+1):
  j = N-1-i
  ans += A[j] * ncr(j, K-1, p)
  ans %= p

for i in range(N-K+1):
  ans -= A[i] * ncr(N-i-1, K-1, p)
  ans %= p

print(ans)

# Optimized solution
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
A = sorted(A)

def ncr(n, r, p):
  num = den = 1
  for i in range(r):
    num = (num * (n - i)) % p
    den = (den * (i + 1)) % p
  return (num * pow(den, p - 2, p)) % p

Mod = 10**9+7
fac = [1, 1]
finv = [1, 1]
inv = [0, 1]
def COMinit():
  #N_C_kのN
  for i in range(2, N+10):
    fac.append(fac[-1]*i%Mod)
    inv.append((-inv[Mod%i] * (Mod//i)) % Mod)
    finv.append(finv[-1] * inv[-1] % Mod)


def COM(n, k):
  if n < 0 or k < 0 or n < k:
    return 0
  return fac[n] * (finv[k] * finv[n-k] % Mod) % Mod


COMinit()
p=10**9+7

ans = 0
for i in range(N-K+1):
  j = N-1-i
  #ans += A[j] * ncr(j, K-1, p)
  ans += A[j] * COM(j, K-1)
  ans %= p

for i in range(N-K+1):
  #ans -= A[i] * ncr(N-i-1, K-1, p)
  ans -= A[i] * COM(N-i-1, K-1)
  ans %= p

print(ans)
# Original solution
N,K = (int(x) for x in input().split())
mod = 10**9+7 #出力の制限
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

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

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 )

K2 = K-2
a = list(map(int, input().split()))
a.sort()
ans = 0
for i in range(N):
    for j in range(i):
        ans += (a[i]-a[j])*(cmb(i-j-1,K2,mod))
        ans = ans % mod
print(ans)

# Optimized solution
N,K = (int(x) for x in input().split())
mod = 10**9+7 #出力の制限
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

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

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 )

K1 = K-1
NK = N-K+1
a = list(map(int, input().split()))
a.sort()
ans = 0
maxs = 0
mins = 0
for i in range(N):
    if i < K1:continue
    maxs += a[i] * cmb(i,K1,mod)
    maxs = maxs%mod
for i in range(NK):
    mins += a[i] * cmb(N-i-1,K1,mod)
    mins = mins%mod
print(((maxs - mins)%mod))
# Original solution
N, K = list(map(int, input().split()))
A = [int(x) for x in input().split()]
A.sort()
res = 0
MOD = 10**9+7
nCk_2 = dict()
fact_t = [1]
for n in range(N):
    fact_t.append(fact_t[-1]*(n+1))
def comb(n, k):
    return (fact_t[n]//(fact_t[n-k]*fact_t[k]))%MOD
s = [1,-1]
for m in range(2):
    for i in range(K-1,N):
        res = (res + s[m]*int((A[i])*comb(i,K-1)))%MOD
    A = sorted(A, reverse=True)
print(res)


# Optimized solution
N, K = list(map(int, input().split()))
A = [int(x) for x in input().split()]
A.sort()
res = 0
MOD = 10**9+7
nCk_2 = dict()
fac, finv, inv = [0]*(N+1), [0]*(N+1), [0]*(N+1)
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1
for i in range(2,N+1):
    fac[i] = fac[i-1]*i%MOD
    inv[i] = MOD-inv[MOD%i]*(MOD//i)%MOD
    finv[i] = finv[i-1]*inv[i]%MOD
def comb(n, k):
    return (fac[n]*((finv[k]*finv[n-k])%MOD))%MOD
s = [1,-1]
for m in range(2):
    for i in range(K-1,N):
        res = (res + s[m]*int((A[i])*comb(i,K-1)))%MOD
    A = sorted(A, reverse=True)
print(res)
# Original solution
n, k = (int(x) for x in input().split())
a = [int(x) for x in input().split()]
a = sorted(a)
fact = [1]
for i in range(1, n + 1):
    fact.append(fact[-1] * i % 1000000007)
max_a = 0
for i in range(k - 1, n):
    max_a += a[i] * fact[i] * pow(fact[i - k + 1], 1000000005, 1000000007) * pow(fact[k - 1], 1000000005, 1000000007) % 1000000007
a = a[::-1]
min_a = 0
for i in range(k - 1, n):
    min_a += a[i] * fact[i] * pow(fact[i - k + 1], 1000000005, 1000000007) * pow(fact[k - 1], 1000000005, 1000000007) % 1000000007
print((int((max_a - min_a) % 1000000007)))

# Optimized solution
n, k = (int(x) for x in input().split())
a = [int(x) for x in input().split()]
a = sorted(a)
MOD = 1000000007
fact = [1]
for i in range(1, n + 1):
    fact.append(fact[-1] * i % MOD)
def inv(i):
    return pow(fact[i], MOD - 2, MOD)
def max_min_a():
    a_sum = 0
    for i in range(k - 1, n):
        a_sum += a[i] * fact[i] * inv(i - k + 1) * inv(k - 1) % MOD
    return a_sum
max_a = max_min_a()
a = a[::-1]
min_a = max_min_a()
print((int((max_a - min_a) % MOD)))