MOD = 10**9 + 7



def getInvs(n, MOD):

    invs = [1] * (n+1)

    for x in range(2, n+1):

        invs[x] = (-(MOD//x) * invs[MOD%x]) % MOD

    return invs



def getCombKs(n, k, invs, MOD):

    combKs = [0] * (n+1)

    combKs[k] = 1

    for x in range(k+1, n+1):

        combKs[x] = (combKs[x-1] * x * invs[x-k]) % MOD

    return combKs



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

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



As.sort()



invs = getInvs(N, MOD)

combKs = getCombKs(N, K-1, invs, MOD)



ans = 0

for i, A in enumerate(As):

    numMax = combKs[i]

    numMin = combKs[N-1-i]

    ans += A * (numMax - numMin) % MOD

    ans %= MOD



print(ans)

MOD = 10**9 + 7



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

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



def getInvs(n, MOD):

    invs = [1] * (n+1)

    for x in range(2, n+1):

        invs[x] = (-(MOD//x) * invs[MOD%x]) % MOD

    return invs

invs = getInvs(N, MOD)

def getCombKs(n, k, invs, MOD):

    combKs = [0] * (n+1)

    combKs[k] = 1

    for x in range(k+1, n+1):

        combKs[x] = (combKs[x-1] * x * invs[x-k]) % MOD

    return combKs

combKs = getCombKs(N, K-1, invs, MOD)



As.sort()



ans = 0

for i, A in enumerate(As):

    if i >= K-1:

        ans += combKs[i] * A

    if N-1-i >= K-1:

        ans -= combKs[N-1-i] * A

    ans %= MOD



print(ans)

MOD = 10**9 + 7


def getInvs(n, MOD):
    invs = [1] * (n + 1)
    for x in range(2, n + 1):
        invs[x] = (-(MOD // x) * invs[MOD % x]) % MOD
    return invs


def getCombKs(n, k, invs, MOD):
    combKs = [0] * (n + 1)
    combKs[k] = 1
    for x in range(k + 1, n + 1):
        combKs[x] = (combKs[x - 1] * x * invs[x - k]) % MOD
    return combKs


N, K = list(map(int, input().split()))
As = list(map(int, input().split()))
As.sort()
invs = getInvs(N, MOD)
combKs = getCombKs(N, K - 1, invs, MOD)
ans = 0
for i, A in enumerate(As):
    numMax = combKs[i]
    numMin = combKs[N - 1 - i]
    ans += A * (numMax - numMin) % MOD
    ans %= MOD
print(ans)

MOD = 10**9 + 7
N, K = list(map(int, input().split()))
As = list(map(int, input().split()))


def getInvs(n, MOD):
    invs = [1] * (n + 1)
    for x in range(2, n + 1):
        invs[x] = (-(MOD // x) * invs[MOD % x]) % MOD
    return invs


invs = getInvs(N, MOD)


def getCombKs(n, k, invs, MOD):
    combKs = [0] * (n + 1)
    combKs[k] = 1
    for x in range(k + 1, n + 1):
        combKs[x] = (combKs[x - 1] * x * invs[x - k]) % MOD
    return combKs


combKs = getCombKs(N, K - 1, invs, MOD)
As.sort()
ans = 0
for i, A in enumerate(As):
    if i >= K - 1:
        ans += combKs[i] * A
    if N - 1 - i >= K - 1:
        ans -= combKs[N - 1 - i] * A
    ans %= MOD
print(ans)

+N, K = list(map(int, input().split())) +As = list(map(int, input().split())) + + +invs = getInvs(N, MOD) -N, K = list(map(int, input().split())) -As = list(map(int, input().split())) +combKs = getCombKs(N, K - 1, invs, MOD) -invs = getInvs(N, MOD) -combKs = getCombKs(N, K - 1, invs, MOD) -    numMax = combKs[i] -    numMin = combKs[N - 1 - i] -    ans += A * (numMax - numMin) % MOD +    if i >= K - 1: +        ans += combKs[i] * A +    if N - 1 - i >= K - 1: +        ans -= combKs[N - 1 - i] * A