import numpy as np

mod = 10 ** 9 + 7



def f(n,k):

    

    ans = 1

    for i in range(k):

        ans = ans * n % mod

        n -= 1

    return ans





def cmb(n, r, p):

    if (r < 0) or (n < r):

        return 0

    r = min(r, n - r)

    return fact[n] * factinv[r] * factinv[n-r] % p

fact = [1, 1]  # fact[n] = (n! mod p)

factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)

inv = [0, 1]  # factinv 計算用

p = mod 

for i in range(2, 10**5 + 1):

    fact.append((fact[-1] * i) % p)

    inv.append((-inv[p % i] * (p // i)) % p)

    factinv.append((factinv[-1] * inv[-1]) % p)



# print( cmb(4, 2, mod) )



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

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

R = sorted(A, reverse=True)



sum = 0



for i in range(N-K+1):

    

    t = cmb( N-i-1, K-1, mod)

    k = A[i] * t % mod

    # print(A[i], t, k)

    sum = ( sum + k ) % mod



sum = -sum



for i in range(N-K+1):

    

    t = cmb( N-i-1, K-1, mod)

    k = R[i] * t % mod

    # print(R[i], t, k)

    sum = ( sum + k ) % mod



print(sum)



mod = 10 ** 9 + 7



def cmb(n, r, p):

    if (r < 0) or (n < r):

        return 0

    r = min(r, n - r)

    return fact[n] * factinv[r] * factinv[n-r] % p

fact = [1, 1]  # fact[n] = (n! mod p)

factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)

inv = [0, 1]  # factinv 計算用

p = mod 

for i in range(2, 10**5 + 1):

    fact.append((fact[-1] * i) % p)

    inv.append((-inv[p % i] * (p // i)) % p)

    factinv.append((factinv[-1] * inv[-1]) % p)



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

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

R = sorted(A, reverse=True)



ans = 0



for i in range(N-K+1):

    

    t = cmb( N-i-1, K-1, mod)

    mi = A[i] * t % mod

    ma = A[N-(i+1)] * t % mod

    ans = ( ans + ma - mi ) % mod 



print(ans)
import numpy as np

mod = 10**9 + 7


def f(n, k):
    ans = 1
    for i in range(k):
        ans = ans * n % mod
        n -= 1
    return ans


def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n - r] % p


fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
p = mod
for i in range(2, 10**5 + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)
# print( cmb(4, 2, mod) )
N, K = list(map(int, input().split()))
A = sorted(map(int, input().split()))
R = sorted(A, reverse=True)
sum = 0
for i in range(N - K + 1):
    t = cmb(N - i - 1, K - 1, mod)
    k = A[i] * t % mod
    # print(A[i], t, k)
    sum = (sum + k) % mod
sum = -sum
for i in range(N - K + 1):
    t = cmb(N - i - 1, K - 1, mod)
    k = R[i] * t % mod
    # print(R[i], t, k)
    sum = (sum + k) % mod
print(sum)

mod = 10**9 + 7


def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n - r] % p


fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
p = mod
for i in range(2, 10**5 + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)
N, K = list(map(int, input().split()))
A = sorted(map(int, input().split()))
R = sorted(A, reverse=True)
ans = 0
for i in range(N - K + 1):
    t = cmb(N - i - 1, K - 1, mod)
    mi = A[i] * t % mod
    ma = A[N - (i + 1)] * t % mod
    ans = (ans + ma - mi) % mod
print(ans)

-import numpy as np - - - -def f(n, k): -    ans = 1 -    for i in range(k): -        ans = ans * n % mod -        n -= 1 -    return ans -# print( cmb(4, 2, mod) ) -sum = 0 +ans = 0 -    k = A[i] * t % mod -    # print(A[i], t, k) -    sum = (sum + k) % mod -sum = -sum -for i in range(N - K + 1): -    t = cmb(N - i - 1, K - 1, mod) -    k = R[i] * t % mod -    # print(R[i], t, k) -    sum = (sum + k) % mod -print(sum) +    mi = A[i] * t % mod +    ma = A[N - (i + 1)] * t % mod +    ans = (ans + ma - mi) % mod +print(ans)