def cmb(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

 

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

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

l=[]

l2=[]

for i in range(n):

  l.append([a[i],i])

l.sort()

for i in range(n):

  l2.append([l[i][1],i])

l2.sort()

mod=10**9+7



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)



ans=0

for i in range(n):

  ans+=a[i]*cmb(l2[i][1],k-1,mod)

  ans%=mod

for i in range(n):

  ans-=a[i]*cmb(n-l2[i][1]-1,k-1,mod)

  ans+=mod

  ans%=mod

print(ans)
def cmb(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

 

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

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

a.sort()

mod=10**9+7

 

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)

 

ans=0

for i in range(n):

  ans+=a[i]*cmb(i,k-1,mod)

  ans%=mod

for i in range(n):

  ans-=a[i]*cmb(n-i-1,k-1,mod)

  ans+=mod

  ans%=mod

print(ans)
def cmb(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


n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
l = []
l2 = []
for i in range(n):
    l.append([a[i], i])
l.sort()
for i in range(n):
    l2.append([l[i][1], i])
l2.sort()
mod = 10**9 + 7
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)
ans = 0
for i in range(n):
    ans += a[i] * cmb(l2[i][1], k - 1, mod)
    ans %= mod
for i in range(n):
    ans -= a[i] * cmb(n - l2[i][1] - 1, k - 1, mod)
    ans += mod
    ans %= mod
print(ans)

def cmb(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


n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
mod = 10**9 + 7
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)
ans = 0
for i in range(n):
    ans += a[i] * cmb(i, k - 1, mod)
    ans %= mod
for i in range(n):
    ans -= a[i] * cmb(n - i - 1, k - 1, mod)
    ans += mod
    ans %= mod
print(ans)

-l = [] -l2 = [] -for i in range(n): -    l.append([a[i], i]) -l.sort() -for i in range(n): -    l2.append([l[i][1], i]) -l2.sort() +a.sort() -    ans += a[i] * cmb(l2[i][1], k - 1, mod) +    ans += a[i] * cmb(i, k - 1, mod) -    ans -= a[i] * cmb(n - l2[i][1] - 1, k - 1, mod) +    ans -= a[i] * cmb(n - i - 1, k - 1, mod)