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

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

A.sort()



MOD = 10**9+7



MAXN = N+5

fac = [1,1] + [0]*MAXN

finv = [1,1] + [0]*MAXN

inv = [0,1] + [0]*MAXN

for i in range(2,MAXN+2):

    fac[i] = fac[i-1] * i % MOD

    inv[i] = -inv[MOD%i] * (MOD // i) % MOD

    finv[i] = finv[i-1] * inv[i] % MOD



def ncr(n,r):

    if n < r: return 0

    if n < 0 or r < 0: return 0

    return fac[n] * (finv[r] * finv[n-r] % MOD) % MOD



combs = []

l = N-K+1

for i in range(l):

    combs.append(ncr(N-l+i,i))



cmax = [0]*(N-l) + combs

cmin = combs[::-1]



from collections import Counter

mins = Counter()

maxs = Counter()



for a,c in zip(A,cmax):

    maxs[a] += c

for a,c in zip(A,cmin):

    mins[a] += c



mx = A[-1]

mn = A[0]

ans = ncr(N,K) * (mx-mn)

for k,v in list(maxs.items()):

    ans -= v * (mx-k)

    ans %= MOD

for k,v in list(mins.items()):

    ans -= v * (k-mn)

    ans %= MOD

print(ans)
N,K = list(map(int,input().split()))

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

A.sort()

MOD = 10**9+7



MAXN = N+5

fac = [1,1] + [0]*MAXN

finv = [1,1] + [0]*MAXN

inv = [0,1] + [0]*MAXN

for i in range(2,MAXN+2):

    fac[i] = fac[i-1] * i % MOD

    inv[i] = -inv[MOD%i] * (MOD // i) % MOD

    finv[i] = finv[i-1] * inv[i] % MOD



def comb(n,r):

    if n < r: return 0

    if n < 0 or r < 0: return 0

    return fac[n] * (finv[r] * finv[n-r] % MOD) % MOD



ans = 0

for n in range(K-1,N):

    c = comb(n,K-1)

    mx = A[n]

    mn = A[-1-n]

    ans += (mx-mn)*c

    ans %= MOD

print(ans)
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
MOD = 10**9 + 7
MAXN = N + 5
fac = [1, 1] + [0] * MAXN
finv = [1, 1] + [0] * MAXN
inv = [0, 1] + [0] * MAXN
for i in range(2, MAXN + 2):
    fac[i] = fac[i - 1] * i % MOD
    inv[i] = -inv[MOD % i] * (MOD // i) % MOD
    finv[i] = finv[i - 1] * inv[i] % MOD


def ncr(n, r):
    if n < r:
        return 0
    if n < 0 or r < 0:
        return 0
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD


combs = []
l = N - K + 1
for i in range(l):
    combs.append(ncr(N - l + i, i))
cmax = [0] * (N - l) + combs
cmin = combs[::-1]
from collections import Counter

mins = Counter()
maxs = Counter()
for a, c in zip(A, cmax):
    maxs[a] += c
for a, c in zip(A, cmin):
    mins[a] += c
mx = A[-1]
mn = A[0]
ans = ncr(N, K) * (mx - mn)
for k, v in list(maxs.items()):
    ans -= v * (mx - k)
    ans %= MOD
for k, v in list(mins.items()):
    ans -= v * (k - mn)
    ans %= MOD
print(ans)

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
MOD = 10**9 + 7
MAXN = N + 5
fac = [1, 1] + [0] * MAXN
finv = [1, 1] + [0] * MAXN
inv = [0, 1] + [0] * MAXN
for i in range(2, MAXN + 2):
    fac[i] = fac[i - 1] * i % MOD
    inv[i] = -inv[MOD % i] * (MOD // i) % MOD
    finv[i] = finv[i - 1] * inv[i] % MOD


def comb(n, r):
    if n < r:
        return 0
    if n < 0 or r < 0:
        return 0
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD


ans = 0
for n in range(K - 1, N):
    c = comb(n, K - 1)
    mx = A[n]
    mn = A[-1 - n]
    ans += (mx - mn) * c
    ans %= MOD
print(ans)

-def ncr(n, r): +def comb(n, r): -combs = [] -l = N - K + 1 -for i in range(l): -    combs.append(ncr(N - l + i, i)) -cmax = [0] * (N - l) + combs -cmin = combs[::-1] -from collections import Counter - -mins = Counter() -maxs = Counter() -for a, c in zip(A, cmax): -    maxs[a] += c -for a, c in zip(A, cmin): -    mins[a] += c -mx = A[-1] -mn = A[0] -ans = ncr(N, K) * (mx - mn) -for k, v in list(maxs.items()): -    ans -= v * (mx - k) -    ans %= MOD -for k, v in list(mins.items()): -    ans -= v * (k - mn) +ans = 0 +for n in range(K - 1, N): +    c = comb(n, K - 1) +    mx = A[n] +    mn = A[-1 - n] +    ans += (mx - mn) * c