import sys

input = sys.stdin.buffer.readline

import copy



def main():

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

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

    MOD = 10**9+7

    A.sort()

    fac = [0 for _ in range(N+1)]

    fac[0],fac[1] = 1,1

    inv = copy.deepcopy(fac)

    invfac = copy.deepcopy(fac)

    

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

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

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

        invfac[i] = (invfac[i-1]*inv[i])%MOD

        

    def coef(x,y):

        num = (((fac[x]*invfac[y])%MOD)*invfac[x-y]%MOD)

        return num



    up = 0

    down = 0

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

        up += A[i]*coef(i,K-1)

        down += A[i-(K-1)]*coef(N-i+K-2,K-1)



    print(((up-down)%MOD))

    

if __name__ == "__main__":

    main()
import sys

input = sys.stdin.buffer.readline

import copy



def main():

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

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

    a.sort()

    

    MOD = 10**9+7

    fac = [0 for _ in range(N+1)]

    fac[0],fac[1] = 1,1

    invfac = copy.deepcopy(fac)

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

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

        

    invfac[-1] = pow(fac[-1],MOD-2,MOD)

    for i in range(N,0,-1):

        invfac[i-1] = (invfac[i]*i)%MOD

    

    def coef(x,y):

        num = (((fac[x]*invfac[y])%MOD)*invfac[x-y]%MOD)

        return num

        

    p,m = 0,0

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

        comb = coef(N-i-1,M-1)

        p += a[-i-1]*comb

        m += a[i]*comb



    print(((p-m)%MOD))

    

if __name__ == "__main__":

    main()

import sys

input = sys.stdin.buffer.readline
import copy


def main():
    N, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    MOD = 10**9 + 7
    A.sort()
    fac = [0 for _ in range(N + 1)]
    fac[0], fac[1] = 1, 1
    inv = copy.deepcopy(fac)
    invfac = copy.deepcopy(fac)
    for i in range(2, N + 1):
        fac[i] = (fac[i - 1] * i) % MOD
        inv[i] = MOD - (MOD // i) * inv[MOD % i] % MOD
        invfac[i] = (invfac[i - 1] * inv[i]) % MOD

    def coef(x, y):
        num = ((fac[x] * invfac[y]) % MOD) * invfac[x - y] % MOD
        return num

    up = 0
    down = 0
    for i in range(K - 1, N):
        up += A[i] * coef(i, K - 1)
        down += A[i - (K - 1)] * coef(N - i + K - 2, K - 1)
    print(((up - down) % MOD))


if __name__ == "__main__":
    main()

import sys

input = sys.stdin.buffer.readline
import copy


def main():
    N, M = list(map(int, input().split()))
    a = list(map(int, input().split()))
    a.sort()
    MOD = 10**9 + 7
    fac = [0 for _ in range(N + 1)]
    fac[0], fac[1] = 1, 1
    invfac = copy.deepcopy(fac)
    for i in range(2, N + 1):
        fac[i] = (fac[i - 1] * i) % MOD
    invfac[-1] = pow(fac[-1], MOD - 2, MOD)
    for i in range(N, 0, -1):
        invfac[i - 1] = (invfac[i] * i) % MOD

    def coef(x, y):
        num = ((fac[x] * invfac[y]) % MOD) * invfac[x - y] % MOD
        return num

    p, m = 0, 0
    for i in range(N - M + 1):
        comb = coef(N - i - 1, M - 1)
        p += a[-i - 1] * comb
        m += a[i] * comb
    print(((p - m) % MOD))


if __name__ == "__main__":
    main()

-    N, K = list(map(int, input().split())) -    A = list(map(int, input().split())) +    N, M = list(map(int, input().split())) +    a = list(map(int, input().split())) +    a.sort() -    A.sort() -    inv = copy.deepcopy(fac) -        inv[i] = MOD - (MOD // i) * inv[MOD % i] % MOD -        invfac[i] = (invfac[i - 1] * inv[i]) % MOD +    invfac[-1] = pow(fac[-1], MOD - 2, MOD) +    for i in range(N, 0, -1): +        invfac[i - 1] = (invfac[i] * i) % MOD -    up = 0 -    down = 0 -    for i in range(K - 1, N): -        up += A[i] * coef(i, K - 1) -        down += A[i - (K - 1)] * coef(N - i + K - 2, K - 1) -    print(((up - down) % MOD)) +    p, m = 0, 0 +    for i in range(N - M + 1): +        comb = coef(N - i - 1, M - 1) +        p += a[-i - 1] * comb +        m += a[i] * comb +    print(((p - m) % MOD))