Buggy python submission (verdict: Runtime Error):
import sys
import copy
import bisect
import numpy as np
from scipy.special import comb
N,K = map(int,input().split())
a = list(map(int,input().split()))
a = sorted(a)
res = 0
fact = [0]*(N+1)
ifact = [0]*(N+1)
inv = [0]*(N+1)
p=10**9+7

def combination(n,fact,ifact):
    fact[0] = 1
    fact[1] = 1
    ifact[0] = 1
    ifact[1] = 1
    inv[1] = 1
    for i in range(2,n+1):
        fact[i] = (fact[i-1]*i)%p
        inv[i] = p - inv[p%i]*(p//i)%p
        ifact[i] = (ifact[i-1]*inv[i])%p
def op(n,k,fact,ifact):
    if k<0 or k>n or n<0:
        return 0
    return int(fact[n]*ifact[k]*ifact[n-k])%(10**9+7)

combination(N,fact,ifact)
for i in range(N):
    res += (a[i]*op(i,K-1,fact,ifact))%p
#a = list(-np.array(a))
a = [-elem for elem in a]
a = sorted(a)
for i in range(N):
    res += (a[i]*op(i,K-1,fact,ifact))%p
print(res%p)


Fixed submission:
import sys
import copy
import bisect
import numpy as np
N,K = map(int,input().split())
a = list(map(int,input().split()))
a = sorted(a)
res = 0
fact = [0]*(N+1)
ifact = [0]*(N+1)
inv = [0]*(N+1)
p=10**9+7

def combination(n,fact,ifact):
    fact[0] = 1
    fact[1] = 1
    ifact[0] = 1
    ifact[1] = 1
    inv[1] = 1
    for i in range(2,n+1):
        fact[i] = (fact[i-1]*i)%p
        inv[i] = p - inv[p%i]*(p//i)%p
        ifact[i] = (ifact[i-1]*inv[i])%p
def op(n,k,fact,ifact):
    if k<0 or k>n or n<0:
        return 0
    return int(fact[n]*ifact[k]*ifact[n-k])%(10**9+7)

combination(N,fact,ifact)
for i in range(N):
    res += (a[i]*op(i,K-1,fact,ifact))%p
#a = list(-np.array(a))
a = [-elem for elem in a]
a = sorted(a)
for i in range(N):
    res += (a[i]*op(i,K-1,fact,ifact))%p
print(res%p)

Buggy python submission (verdict: Runtime Error):
import sys
import copy
import bisect
import numpy as np
from scipy.special import comb
N,K = map(int,input().split())
a = list(map(int,input().split()))
a = sorted(a)
res = 0
fact = [0]*(N+1)
ifact = [0]*(N+1)
inv = [0]*(N+1)
p=10**9+7

def combination(n,fact,ifact):
    fact[0] = 1
    fact[1] = 1
    ifact[0] = 1
    ifact[1] = 1
    inv[1] = 1
    for i in range(2,n+1):
        fact[i] = (fact[i-1]*i)%p
        inv[i] = p - inv[p%i]*(p//i)%p
        ifact[i] = (ifact[i-1]*inv[i])%p
def op(n,k,fact,ifact):
    if k<0 or k>n or n<0:
        return 0
    return int(fact[n]*ifact[k]*ifact[n-k])%(10**9+7)

combination(N,fact,ifact)
for i in range(N):
    res += (a[i]*op(i,K-1,fact,ifact))%p
#a = list(-np.array(a))
a = [-elem for elem in a]
a = sorted(a)
for i in range(N):
    res += (a[i]*op(i,K-1,fact,ifact))%p
print(res%p)


Fixed submission:
import sys
import copy
import bisect
import numpy as np
N,K = map(int,input().split())
a = list(map(int,input().split()))
a = sorted(a)
res = 0
fact = [0]*(N+1)
ifact = [0]*(N+1)
inv = [0]*(N+1)
p=10**9+7

def combination(n,fact,ifact):
    fact[0] = 1
    fact[1] = 1
    ifact[0] = 1
    ifact[1] = 1
    inv[1] = 1
    for i in range(2,n+1):
        fact[i] = (fact[i-1]*i)%p
        inv[i] = p - inv[p%i]*(p//i)%p
        ifact[i] = (ifact[i-1]*inv[i])%p
def op(n,k,fact,ifact):
    if k<0 or k>n or n<0:
        return 0
    return int(fact[n]*ifact[k]*ifact[n-k])%(10**9+7)

combination(N,fact,ifact)
for i in range(N):
    res += (a[i]*op(i,K-1,fact,ifact))%p
#a = list(-np.array(a))
a = [-elem for elem in a]
a = sorted(a)
for i in range(N):
    res += (a[i]*op(i,K-1,fact,ifact))%p
print(res%p)