def cmb1(n, r, mod):

    if ( r<0 or r>n ):

        return 0

    r = min(r, n-r)

    return g1[n] * g2[r] * g2[n-r] % mod



mod = 10**9+7 #出力の制限

N = 10**6

g1 = [1, 1] # 元テーブル

g2 = [1, 1] #逆元テーブル

inverse = [0, 1] #逆元テーブル計算用テーブル



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

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

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

    g2.append( (g2[-1] * inverse[-1]) % mod )



n, k = list(map(int, input().split()))

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

mod = 10**9+7



A.sort(reverse=True)



max_ = 0

for i in range(n):

    max_ += cmb1(n-1-i, k-1, mod)*A[i]

max_ %= mod



min_ = 0

for i in range(n):

    min_ += cmb1(n-1-i, k-1, mod)*A[n-1-i]

min_ %= mod

ans = max_-min_

ans %= mod

print(ans)    

n, k =list(map(int, input().split()))

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



mod = 10**9+7

N = 10**5+50

fac = [1]*(N+1)

finv = [1]*(N+1)

for i in range(N):

    fac[i+1] = fac[i] * (i+1) % mod

finv[-1] = pow(fac[-1], mod-2, mod)

for i in reversed(list(range(N))):

    finv[i] = finv[i+1] * (i+1) % mod



def cmb1(n, r, mod):

    if r <0 or r > n:

        return 0

    r = min(r, n-r)

    return fac[n] * finv[r] * finv[n-r] % mod





A.sort()

ans = 0

for i, a in enumerate(A):

    M = n-1-i

    m = i

    if m >= 0:

        ans += a*cmb1(m, k-1, mod)

    if M >= 0:

        ans -= a*cmb1(M, k-1, mod)

ans %= mod

print(ans)

def cmb1(n, r, mod):
    if r < 0 or r > n:
        return 0
    r = min(r, n - r)
    return g1[n] * g2[r] * g2[n - r] % mod


mod = 10**9 + 7  # 出力の制限
N = 10**6
g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  # 逆元テーブル
inverse = [0, 1]  # 逆元テーブル計算用テーブル
for i in range(2, N + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod // i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)
n, k = list(map(int, input().split()))
A = list(map(int, input().split()))
mod = 10**9 + 7
A.sort(reverse=True)
max_ = 0
for i in range(n):
    max_ += cmb1(n - 1 - i, k - 1, mod) * A[i]
max_ %= mod
min_ = 0
for i in range(n):
    min_ += cmb1(n - 1 - i, k - 1, mod) * A[n - 1 - i]
min_ %= mod
ans = max_ - min_
ans %= mod
print(ans)

n, k = list(map(int, input().split()))
A = list(map(int, input().split()))
mod = 10**9 + 7
N = 10**5 + 50
fac = [1] * (N + 1)
finv = [1] * (N + 1)
for i in range(N):
    fac[i + 1] = fac[i] * (i + 1) % mod
finv[-1] = pow(fac[-1], mod - 2, mod)
for i in reversed(list(range(N))):
    finv[i] = finv[i + 1] * (i + 1) % mod


def cmb1(n, r, mod):
    if r < 0 or r > n:
        return 0
    r = min(r, n - r)
    return fac[n] * finv[r] * finv[n - r] % mod


A.sort()
ans = 0
for i, a in enumerate(A):
    M = n - 1 - i
    m = i
    if m >= 0:
        ans += a * cmb1(m, k - 1, mod)
    if M >= 0:
        ans -= a * cmb1(M, k - 1, mod)
ans %= mod
print(ans)

+n, k = list(map(int, input().split())) +A = list(map(int, input().split())) +mod = 10**9 + 7 +N = 10**5 + 50 +fac = [1] * (N + 1) +finv = [1] * (N + 1) +for i in range(N): +    fac[i + 1] = fac[i] * (i + 1) % mod +finv[-1] = pow(fac[-1], mod - 2, mod) +for i in reversed(list(range(N))): +    finv[i] = finv[i + 1] * (i + 1) % mod + + -    return g1[n] * g2[r] * g2[n - r] % mod +    return fac[n] * finv[r] * finv[n - r] % mod -mod = 10**9 + 7  # 出力の制限 -N = 10**6 -g1 = [1, 1]  # 元テーブル -g2 = [1, 1]  # 逆元テーブル -inverse = [0, 1]  # 逆元テーブル計算用テーブル -for i in range(2, N + 1): -    g1.append((g1[-1] * i) % mod) -    inverse.append((-inverse[mod % i] * (mod // i)) % mod) -    g2.append((g2[-1] * inverse[-1]) % mod) -n, k = list(map(int, input().split())) -A = list(map(int, input().split())) -mod = 10**9 + 7 -A.sort(reverse=True) -max_ = 0 -for i in range(n): -    max_ += cmb1(n - 1 - i, k - 1, mod) * A[i] -max_ %= mod -min_ = 0 -for i in range(n): -    min_ += cmb1(n - 1 - i, k - 1, mod) * A[n - 1 - i] -min_ %= mod -ans = max_ - min_ +A.sort() +ans = 0 +for i, a in enumerate(A): +    M = n - 1 - i +    m = i +    if m >= 0: +        ans += a * cmb1(m, k - 1, mod) +    if M >= 0: +        ans -= a * cmb1(M, k - 1, mod)