def modinv2(a,m):

    return pow(a,m-2,m)



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

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

A.sort()

P = 10**9+7



cominv = [0 for i in range(N-1)]

for i in range(N-1):

    if i+2 == K:

        cominv[i] = 1

    elif i+1 == K:

        cominv[i] = (i+1)%P

    elif i+1 > K:

        a = modinv2(i-K+2,P)

        cominv[i] = cominv[i-1]*(i+1)*a%P



#print(cominv)

ans = 0



for i in range(N):

    if i <= N-K:

        b = A[i]*cominv[N-i-2]%P

        ans = (ans-b+P)%P

    if i >= K-1:

        c = A[i]*cominv[i-1]%P

        ans = (ans+c)%P



print(ans)

def modinv2(a,m):

    return pow(a,m-2,m)



def modcomn(n,r,m):

    modcom = [0 for _ in range(n)]

    for i in range(n):

        if i < r-1:

            continue

        if i == r-1:

            modcom[i] = 1

        elif i == r:

            modcom[i] = (i+1)%m

        else:

            div = modinv2(i-r+1,m)

            modcom[i] = (modcom[i-1]*div%m)*(i+1)%m

    return modcom



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

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

A.sort()

P = 10**9+7



com = modcomn(N-1,K-1,P)



#print(com)

ans = 0



for i in range(N):

    if i >= K-1:

        ans = (ans+A[i]*com[i-1]%P)%P

    if i <= N-K:

        ans = (ans-A[i]*com[N-i-2]%P+P)%P



print(ans)

def modinv2(a, m):
    return pow(a, m - 2, m)


N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
P = 10**9 + 7
cominv = [0 for i in range(N - 1)]
for i in range(N - 1):
    if i + 2 == K:
        cominv[i] = 1
    elif i + 1 == K:
        cominv[i] = (i + 1) % P
    elif i + 1 > K:
        a = modinv2(i - K + 2, P)
        cominv[i] = cominv[i - 1] * (i + 1) * a % P
# print(cominv)
ans = 0
for i in range(N):
    if i <= N - K:
        b = A[i] * cominv[N - i - 2] % P
        ans = (ans - b + P) % P
    if i >= K - 1:
        c = A[i] * cominv[i - 1] % P
        ans = (ans + c) % P
print(ans)

def modinv2(a, m):
    return pow(a, m - 2, m)


def modcomn(n, r, m):
    modcom = [0 for _ in range(n)]
    for i in range(n):
        if i < r - 1:
            continue
        if i == r - 1:
            modcom[i] = 1
        elif i == r:
            modcom[i] = (i + 1) % m
        else:
            div = modinv2(i - r + 1, m)
            modcom[i] = (modcom[i - 1] * div % m) * (i + 1) % m
    return modcom


N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
P = 10**9 + 7
com = modcomn(N - 1, K - 1, P)
# print(com)
ans = 0
for i in range(N):
    if i >= K - 1:
        ans = (ans + A[i] * com[i - 1] % P) % P
    if i <= N - K:
        ans = (ans - A[i] * com[N - i - 2] % P + P) % P
print(ans)

+ + +def modcomn(n, r, m): +    modcom = [0 for _ in range(n)] +    for i in range(n): +        if i < r - 1: +            continue +        if i == r - 1: +            modcom[i] = 1 +        elif i == r: +            modcom[i] = (i + 1) % m +        else: +            div = modinv2(i - r + 1, m) +            modcom[i] = (modcom[i - 1] * div % m) * (i + 1) % m +    return modcom -cominv = [0 for i in range(N - 1)] -for i in range(N - 1): -    if i + 2 == K: -        cominv[i] = 1 -    elif i + 1 == K: -        cominv[i] = (i + 1) % P -    elif i + 1 > K: -        a = modinv2(i - K + 2, P) -        cominv[i] = cominv[i - 1] * (i + 1) * a % P -# print(cominv) +com = modcomn(N - 1, K - 1, P) +# print(com) +    if i >= K - 1: +        ans = (ans + A[i] * com[i - 1] % P) % P -        b = A[i] * cominv[N - i - 2] % P -        ans = (ans - b + P) % P -    if i >= K - 1: -        c = A[i] * cominv[i - 1] % P -        ans = (ans + c) % P +        ans = (ans - A[i] * com[N - i - 2] % P + P) % P