import sys



input = sys.stdin.readline

P = 10 ** 9 + 7





def make_fac_tables_mod_p(n, p):

    fac = [0] * (n + 1)

    fac_inv = [0] * (n + 1)

    mod_inv = [0] * (n + 1)

    fac[0] = fac[1] = 1

    fac_inv[0] = fac_inv[1] = 1

    mod_inv[1] = 1

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

        fac[i] = (fac[i - 1] * i) % p

        mod_inv[i] = p - mod_inv[p % i] * (p // i) % p

        fac_inv[i] = fac_inv[i - 1] * mod_inv[i] % p

    return fac, fac_inv





def nCk_mod_p(fac, fac_inv, n, k, p):

    return ((fac[n] * fac_inv[n - k]) % p) * fac_inv[k] % p





def main():

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

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



    if K == 1:

        print((0))

        exit()

    if N == 2:

        A.sort()

        print(((A[1] - A[0]) % P))

        exit()



    A.sort()



    fac, fac_inv = make_fac_tables_mod_p(N - 2, P)



    n_f = N - K + 1

    f = [0] * (n_f + 1)

    k = K - 2

    for i, n in enumerate(list(range(k, N - 2 + 1)), 1):

        f[i] = (f[i - 1] + nCk_mod_p(fac, fac_inv, n, k, P)) % P



    ans = 0

    for i in range(1, n_f + 1):

        ans = (ans - (f[i] * A[n_f - i]) % P) % P



    for i in range(1, n_f + 1):

        ans = (ans + (f[i] * A[N - n_f + i - 1]) % P) % P



    print(ans)





if __name__ == "__main__":

    main()

import sys



input = sys.stdin.readline

P = 10 ** 9 + 7





class MODCombination:

    def __init__(self, n, p):

        self.n = n

        self.p = p  # MOD

        self.fac, self.ifac = self.make_fac_tables_mod_p(n, p)



    @staticmethod

    def make_fac_tables_mod_p(n, p):

        assert n >= 1

        fac = [0] * (n + 1)   # _______ factorial: n!

        ifac = [0] * (n + 1)  # inverse factorial: n!^{-1}

        inv = [0] * (n + 1)   # inverse element  : n ^{-1}

        fac[0] = fac[1] = 1

        ifac[0] = ifac[1] = 1

        inv[1] = 1

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

            fac[i] = fac[i - 1] * i % p

            inv[i] = p - inv[p % i] * (p // i) % p

            ifac[i] = ifac[i - 1] * inv[i] % p

        return fac, ifac



    def nCk(self, n, k):

        # nCk = n! * k!^{-1} * (n-k)!^{-1}

        return ((self.fac[n] * self.ifac[n - k]) % self.p) * self.ifac[k] % self.p





def main():

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

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



    A.sort()

    mod_comb = MODCombination(N - 1, P)



    ans = 0

    for n in range(K - 1, N):

        max_A = A[n]

        min_A = A[-n - 1]

        ans += (max_A - min_A) * mod_comb.nCk(n, K - 1)

        ans %= P



    print(ans)





if __name__ == "__main__":

    main()

import sys

input = sys.stdin.readline
P = 10**9 + 7


def make_fac_tables_mod_p(n, p):
    fac = [0] * (n + 1)
    fac_inv = [0] * (n + 1)
    mod_inv = [0] * (n + 1)
    fac[0] = fac[1] = 1
    fac_inv[0] = fac_inv[1] = 1
    mod_inv[1] = 1
    for i in range(2, n + 1):
        fac[i] = (fac[i - 1] * i) % p
        mod_inv[i] = p - mod_inv[p % i] * (p // i) % p
        fac_inv[i] = fac_inv[i - 1] * mod_inv[i] % p
    return fac, fac_inv


def nCk_mod_p(fac, fac_inv, n, k, p):
    return ((fac[n] * fac_inv[n - k]) % p) * fac_inv[k] % p


def main():
    N, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    if K == 1:
        print((0))
        exit()
    if N == 2:
        A.sort()
        print(((A[1] - A[0]) % P))
        exit()
    A.sort()
    fac, fac_inv = make_fac_tables_mod_p(N - 2, P)
    n_f = N - K + 1
    f = [0] * (n_f + 1)
    k = K - 2
    for i, n in enumerate(list(range(k, N - 2 + 1)), 1):
        f[i] = (f[i - 1] + nCk_mod_p(fac, fac_inv, n, k, P)) % P
    ans = 0
    for i in range(1, n_f + 1):
        ans = (ans - (f[i] * A[n_f - i]) % P) % P
    for i in range(1, n_f + 1):
        ans = (ans + (f[i] * A[N - n_f + i - 1]) % P) % P
    print(ans)


if __name__ == "__main__":
    main()

import sys

input = sys.stdin.readline
P = 10**9 + 7


class MODCombination:
    def __init__(self, n, p):
        self.n = n
        self.p = p  # MOD
        self.fac, self.ifac = self.make_fac_tables_mod_p(n, p)

    @staticmethod
    def make_fac_tables_mod_p(n, p):
        assert n >= 1
        fac = [0] * (n + 1)  # _______ factorial: n!
        ifac = [0] * (n + 1)  # inverse factorial: n!^{-1}
        inv = [0] * (n + 1)  # inverse element  : n ^{-1}
        fac[0] = fac[1] = 1
        ifac[0] = ifac[1] = 1
        inv[1] = 1
        for i in range(2, n + 1):
            fac[i] = fac[i - 1] * i % p
            inv[i] = p - inv[p % i] * (p // i) % p
            ifac[i] = ifac[i - 1] * inv[i] % p
        return fac, ifac

    def nCk(self, n, k):
        # nCk = n! * k!^{-1} * (n-k)!^{-1}
        return ((self.fac[n] * self.ifac[n - k]) % self.p) * self.ifac[k] % self.p


def main():
    N, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    A.sort()
    mod_comb = MODCombination(N - 1, P)
    ans = 0
    for n in range(K - 1, N):
        max_A = A[n]
        min_A = A[-n - 1]
        ans += (max_A - min_A) * mod_comb.nCk(n, K - 1)
        ans %= P
    print(ans)


if __name__ == "__main__":
    main()

-def make_fac_tables_mod_p(n, p): -    fac = [0] * (n + 1) -    fac_inv = [0] * (n + 1) -    mod_inv = [0] * (n + 1) -    fac[0] = fac[1] = 1 -    fac_inv[0] = fac_inv[1] = 1 -    mod_inv[1] = 1 -    for i in range(2, n + 1): -        fac[i] = (fac[i - 1] * i) % p -        mod_inv[i] = p - mod_inv[p % i] * (p // i) % p -        fac_inv[i] = fac_inv[i - 1] * mod_inv[i] % p -    return fac, fac_inv +class MODCombination: +    def __init__(self, n, p): +        self.n = n +        self.p = p  # MOD +        self.fac, self.ifac = self.make_fac_tables_mod_p(n, p) +    @staticmethod +    def make_fac_tables_mod_p(n, p): +        assert n >= 1 +        fac = [0] * (n + 1)  # _______ factorial: n! +        ifac = [0] * (n + 1)  # inverse factorial: n!^{-1} +        inv = [0] * (n + 1)  # inverse element  : n ^{-1} +        fac[0] = fac[1] = 1 +        ifac[0] = ifac[1] = 1 +        inv[1] = 1 +        for i in range(2, n + 1): +            fac[i] = fac[i - 1] * i % p +            inv[i] = p - inv[p % i] * (p // i) % p +            ifac[i] = ifac[i - 1] * inv[i] % p +        return fac, ifac -def nCk_mod_p(fac, fac_inv, n, k, p): -    return ((fac[n] * fac_inv[n - k]) % p) * fac_inv[k] % p +    def nCk(self, n, k): +        # nCk = n! * k!^{-1} * (n-k)!^{-1} +        return ((self.fac[n] * self.ifac[n - k]) % self.p) * self.ifac[k] % self.p -    if K == 1: -        print((0)) -        exit() -    if N == 2: -        A.sort() -        print(((A[1] - A[0]) % P)) -        exit() -    fac, fac_inv = make_fac_tables_mod_p(N - 2, P) -    n_f = N - K + 1 -    f = [0] * (n_f + 1) -    k = K - 2 -    for i, n in enumerate(list(range(k, N - 2 + 1)), 1): -        f[i] = (f[i - 1] + nCk_mod_p(fac, fac_inv, n, k, P)) % P +    mod_comb = MODCombination(N - 1, P) -    for i in range(1, n_f + 1): -        ans = (ans - (f[i] * A[n_f - i]) % P) % P -    for i in range(1, n_f + 1): -        ans = (ans + (f[i] * A[N - n_f + i - 1]) % P) % P +    for n in range(K - 1, N): +        max_A = A[n] +        min_A = A[-n - 1] +        ans += (max_A - min_A) * mod_comb.nCk(n, K - 1) +        ans %= P