N, K, *A = list(map(int, open(0).read().split()))



MOD = 10 ** 9 + 7



fac = [0] * (N + 1)

fac[0] = 1

fac[1] = 1

for i in range(2, N + 1):

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



finv = [0] * (N + 1)

finv[N] = pow(fac[N], MOD - 2, MOD)

for i in reversed(list(range(1, N + 1))):

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



def comb(n, k):

    if n < k:

        return 0

    return fac[n] * finv[k] * finv[n - k] % MOD



ans = 0

for i, a in enumerate(sorted(A, reverse=True)):

    ans += a * comb(N - i - 1, K - 1)

    ans -= a * comb(i, K - 1)

    ans %= MOD

    

print(ans)

N, K, *A = list(map(int, open(0).read().split()))



MAX = 10 ** 5 + 1

MOD = 10 ** 9 + 7



# Factorial

fac = [0] * (MAX + 1)

fac[0] = 1

fac[1] = 1

for i in range(2, MAX + 1):

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

    

# Inverse factorial

finv = [0] * (MAX + 1)

finv[MAX] = pow(fac[MAX], MOD - 2, MOD)

for i in reversed(list(range(1, MAX + 1))):

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



def comb(n, k):

    if n < k or k < 0:

        return 0

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





A.sort()

ans = 0

for i in range(N):

    if i >= K - 1:

        ans += comb(i, K - 1) * A[i]

    if i + K - 1 < N:

        ans -= comb(N - i - 1, K - 1) * A[i]

    ans %= MOD

print(ans)



N, K, *A = list(map(int, open(0).read().split()))
MOD = 10**9 + 7
fac = [0] * (N + 1)
fac[0] = 1
fac[1] = 1
for i in range(2, N + 1):
    fac[i] = fac[i - 1] * i % MOD
finv = [0] * (N + 1)
finv[N] = pow(fac[N], MOD - 2, MOD)
for i in reversed(list(range(1, N + 1))):
    finv[i - 1] = finv[i] * i % MOD


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


ans = 0
for i, a in enumerate(sorted(A, reverse=True)):
    ans += a * comb(N - i - 1, K - 1)
    ans -= a * comb(i, K - 1)
    ans %= MOD
print(ans)

N, K, *A = list(map(int, open(0).read().split()))
MAX = 10**5 + 1
MOD = 10**9 + 7
# Factorial
fac = [0] * (MAX + 1)
fac[0] = 1
fac[1] = 1
for i in range(2, MAX + 1):
    fac[i] = fac[i - 1] * i % MOD
# Inverse factorial
finv = [0] * (MAX + 1)
finv[MAX] = pow(fac[MAX], MOD - 2, MOD)
for i in reversed(list(range(1, MAX + 1))):
    finv[i - 1] = finv[i] * i % MOD


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


A.sort()
ans = 0
for i in range(N):
    if i >= K - 1:
        ans += comb(i, K - 1) * A[i]
    if i + K - 1 < N:
        ans -= comb(N - i - 1, K - 1) * A[i]
    ans %= MOD
print(ans)

+MAX = 10**5 + 1 -fac = [0] * (N + 1) +# Factorial +fac = [0] * (MAX + 1) -for i in range(2, N + 1): +for i in range(2, MAX + 1): -finv = [0] * (N + 1) -finv[N] = pow(fac[N], MOD - 2, MOD) -for i in reversed(list(range(1, N + 1))): +# Inverse factorial +finv = [0] * (MAX + 1) +finv[MAX] = pow(fac[MAX], MOD - 2, MOD) +for i in reversed(list(range(1, MAX + 1))): -    if n < k: +    if n < k or k < 0: -    return fac[n] * finv[k] * finv[n - k] % MOD +    return (fac[n] * finv[k] * finv[n - k]) % MOD +A.sort() -for i, a in enumerate(sorted(A, reverse=True)): -    ans += a * comb(N - i - 1, K - 1) -    ans -= a * comb(i, K - 1) +for i in range(N): +    if i >= K - 1: +        ans += comb(i, K - 1) * A[i] +    if i + K - 1 < N: +        ans -= comb(N - i - 1, K - 1) * A[i]