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 in zip(list(range(K, N)), list(range(1, N))):

        comb = comb * i * pow(j, mod - 2, mod) % mod

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

        ans %= mod

    

    print(ans)



solve()
def solve():

    from sys import stdin

    f_i = stdin

    

    N, K = list(map(int, f_i.readline().split()))

    

    # combination

    mod = 10 ** 9 + 7

    fact = [1, 1]

    factinv = [1, 1]

    inv = [0, 1]

    

    for i in range(2, N):

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

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

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

    

    def comb(n, r):

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

    

    A = sorted(map(int, f_i.readline().split()))

    

    ans = A[K-1] - A[N-K]

    for i, j in zip(list(range(K, N)), list(range(1, N))):

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

        ans %= mod

    

    print(ans)



solve()
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 in zip(list(range(K, N)), list(range(1, N))):
        comb = comb * i * pow(j, mod - 2, mod) % mod
        ans += (A[i] - A[N - i - 1]) * comb
        ans %= mod
    print(ans)


solve()

def solve():
    from sys import stdin

    f_i = stdin
    N, K = list(map(int, f_i.readline().split()))
    # combination
    mod = 10**9 + 7
    fact = [1, 1]
    factinv = [1, 1]
    inv = [0, 1]
    for i in range(2, N):
        fact.append((fact[-1] * i) % mod)
        inv.append((-inv[mod % i] * (mod // i)) % mod)
        factinv.append((factinv[-1] * inv[-1]) % mod)

    def comb(n, r):
        return fact[n] * factinv[r] * factinv[n - r] % mod

    A = sorted(map(int, f_i.readline().split()))
    ans = A[K - 1] - A[N - K]
    for i, j in zip(list(range(K, N)), list(range(1, N))):
        ans += (A[i] - A[N - i - 1]) * comb(i, K - 1)
        ans %= mod
    print(ans)


solve()

+    N, K = list(map(int, f_i.readline().split())) +    # combination -    N, K = list(map(int, f_i.readline().split())) +    fact = [1, 1] +    factinv = [1, 1] +    inv = [0, 1] +    for i in range(2, N): +        fact.append((fact[-1] * i) % mod) +        inv.append((-inv[mod % i] * (mod // i)) % mod) +        factinv.append((factinv[-1] * inv[-1]) % mod) + +    def comb(n, r): +        return fact[n] * factinv[r] * factinv[n - r] % mod + -    comb = 1 -        comb = comb * i * pow(j, mod - 2, mod) % mod -        ans += (A[i] - A[N - i - 1]) * comb +        ans += (A[i] - A[N - i - 1]) * comb(i, K - 1)