Buggy python submission (verdict: Time Limit Exceeded):
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

def cmb(n, r, p):
    r = min(n - r, r)
    if r == 0:
        return 1
    over = 1
    for i in range(n, n - r, -1):
        over = over * i % p
    under = 1
    for i in range(1, r + 1):
        under = under * i % p
    inv = pow(under, p - 2, p)
    return over * inv % p

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

minus = 0
plus = 0

d = defaultdict(int)
for i in range(N):
    d[i] = cmb(i, K-1, MOD)

for i, a in enu(A):
    mval = d[N-i-1]
    pval = d[i]
    if i<=K-2:
        pval = 0
    if N-K+1<=i:
        mval = 0
#    print(mval, pval)
    minus -= a*mval
    plus += a*pval


print((plus+minus)%MOD)



Fixed submission:
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))


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

fact = [1]
for i in range(1, N+10):
    fact.append(fact[-1] * i % MOD)
def rev(x):
    return pow(x, MOD-2, MOD)
def cmb(i, k):
    if(i < k): return 0
    return fact[i] * rev(fact[k]) * rev(fact[i-k]) % MOD

minus = 0
plus = 0

for i, a in enu(A):
    mval = cmb(N-i-1, K-1)
    pval = cmb(i, K-1)
    if i<=K-2:
        pval = 0
    if N-K+1<=i:
        mval = 0
#    print(mval, pval)
    minus -= a*mval
    plus += a*pval

print((plus+minus)%MOD)

Buggy python submission (verdict: Time Limit Exceeded):
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

def cmb(n, r, p):
    r = min(n - r, r)
    if r == 0:
        return 1
    over = 1
    for i in range(n, n - r, -1):
        over = over * i % p
    under = 1
    for i in range(1, r + 1):
        under = under * i % p
    inv = pow(under, p - 2, p)
    return over * inv % p

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

minus = 0
plus = 0

for i, a in enu(A):
    mval = cmb(N-i-1, K-1, MOD)
    pval = cmb(i, K-1, MOD)
    if i<=K-2:
        pval = 0
    if N-K+1<=i:
        mval = 0
#    print(mval, pval)
    minus -= a*mval
    plus += a*pval

print((plus+minus)%MOD)



Fixed submission:
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))


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

fact = [1]
for i in range(1, N+10):
    fact.append(fact[-1] * i % MOD)
def rev(x):
    return pow(x, MOD-2, MOD)
def cmb(i, k):
    if(i < k): return 0
    return fact[i] * rev(fact[k]) * rev(fact[i-k]) % MOD

minus = 0
plus = 0

for i, a in enu(A):
    mval = cmb(N-i-1, K-1)
    pval = cmb(i, K-1)
    if i<=K-2:
        pval = 0
    if N-K+1<=i:
        mval = 0
#    print(mval, pval)
    minus -= a*mval
    plus += a*pval

print((plus+minus)%MOD)

Buggy python submission (verdict: Time Limit Exceeded):
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

def cmb(n, r, p):
    r = min(n - r, r)
    if r == 0:
        return 1
    over = 1
    for i in range(n, n - r, -1):
        over = over * i % p
    under = 1
    for i in range(1, r + 1):
        under = under * i % p
    inv = pow(under, p - 2, p)
    return over * inv % p

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

minus = 0
plus = 0

for i, a in enu(A):
    mval = cmb(N-i-1, K-1, MOD)
    pval = cmb(i, K-1, MOD)
    if i<=K-2:
        pval = 0
    if N-K+1<=i:
        mval = 0
#    print(mval, pval)
    minus -= a*mval
    plus += a*pval

print((plus+minus)%MOD)



Fixed submission:
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))


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

fact = [1]
for i in range(1, N+10):
    fact.append(fact[-1] * i % MOD)
def rev(x):
    return pow(x, MOD-2, MOD)
def cmb(i, k):
    if(i < k): return 0
    return fact[i] * rev(fact[k]) * rev(fact[i-k]) % MOD

minus = 0
plus = 0

for i, a in enu(A):
    mval = cmb(N-i-1, K-1)
    pval = cmb(i, K-1)
    if i<=K-2:
        pval = 0
    if N-K+1<=i:
        mval = 0
#    print(mval, pval)
    minus -= a*mval
    plus += a*pval

print((plus+minus)%MOD)