Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == '__main__':
    import sys
    input = sys.stdin.readline


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

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

    """

    n = 100000
    k = 50000
    aa = [i for i in range(100000)]
    """

    import math

    if k == 1:
        print(0)
    else:
        aa.sort()

        cnt = 0

        c = 1
        large = k+1
        before = 0

        for i, j in zip(aa[k-1:], reversed(aa[:-k+1])):
            cnt += (i-j)*(c-before)
            cnt = cnt%(10**9+7)
            before = c
            c = c*large//(large-k)
            large += 1
            """
            if math.isnan(cnt):
                print(c, large, k, before, i, j)
                break
            """

        print(int(cnt%(10**9+7)))


Fixed submission:
if __name__ == '__main__':
    import sys
    input = sys.stdin.readline


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

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

    """

    n = 100000
    k = 50000
    aa = [i for i in range(100000)]
    """

    import math

    if k == 1:
        print(0)
    else:
        def cmb(n, r, p):
            if (r < 0) or (n < r):
                return 0
            r = min(r, n - r)
            return fact[n] * factinv[r] * factinv[n-r] % p

        p = 10 ** 9 + 7
        N = 10 ** 5  # N は必要分だけ用意する
        fact = [1, 1]  # fact[n] = (n! mod p)
        factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
        inv = [0, 1]  # factinv 計算用

        for i in range(2, N + 1):
            fact.append((fact[-1] * i) % p)
            inv.append((-inv[p % i] * (p // i)) % p)
            factinv.append((factinv[-1] * inv[-1]) % p)

        aa.sort()

        cnt = 0

        c = 1
        large = k
        before = 0

        for i, j in zip(aa[k-1:], reversed(aa[:-k+1])):
            c = cmb(large, k, p)
            cnt += (i-j)*(c-before)
            cnt = cnt%(10**9+7)
            before = c
            large += 1

        print(int(cnt%(10**9+7)))

Buggy python submission (verdict: Runtime Error):
if __name__ == '__main__':
    import sys
    input = sys.stdin.readline

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

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

    if k == 1:
        print(0)
    else:
        aa.sort()

        cnt = 0

        c = 1
        large = k+1
        before = 0

        for i, j in zip(aa[k-1:], reversed(aa[:-k+1])):

            cnt += (i-j)*(c-before)
            cnt = cnt%(10**9+7)
            before = c
            c = c*large/(large-k)

            large += 1
        print(int(cnt%(10**9+7)))


Fixed submission:
if __name__ == '__main__':
    import sys
    input = sys.stdin.readline


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

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

    """

    n = 100000
    k = 50000
    aa = [i for i in range(100000)]
    """

    import math

    if k == 1:
        print(0)
    else:
        def cmb(n, r, p):
            if (r < 0) or (n < r):
                return 0
            r = min(r, n - r)
            return fact[n] * factinv[r] * factinv[n-r] % p

        p = 10 ** 9 + 7
        N = 10 ** 5  # N は必要分だけ用意する
        fact = [1, 1]  # fact[n] = (n! mod p)
        factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
        inv = [0, 1]  # factinv 計算用

        for i in range(2, N + 1):
            fact.append((fact[-1] * i) % p)
            inv.append((-inv[p % i] * (p // i)) % p)
            factinv.append((factinv[-1] * inv[-1]) % p)

        aa.sort()

        cnt = 0

        c = 1
        large = k
        before = 0

        for i, j in zip(aa[k-1:], reversed(aa[:-k+1])):
            c = cmb(large, k, p)
            cnt += (i-j)*(c-before)
            cnt = cnt%(10**9+7)
            before = c
            large += 1

        print(int(cnt%(10**9+7)))

Buggy python submission (verdict: Runtime Error):
if __name__ == '__main__':
    import sys
    input = sys.stdin.readline

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

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

    if k == 1:
        print(0)
    else:
        aa.sort()

        cnt = 0

        c = 1
        large = k+1
        before = 0

        for i, j in zip(aa[k-1:], reversed(aa[:-k+1])):

            cnt += (i-j)*(c-before)
            before = c
            c = c*large/(large-k)

            large += 1
        print(int(cnt%(10**9+7)))


Fixed submission:
if __name__ == '__main__':
    import sys
    input = sys.stdin.readline


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

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

    """

    n = 100000
    k = 50000
    aa = [i for i in range(100000)]
    """

    import math

    if k == 1:
        print(0)
    else:
        def cmb(n, r, p):
            if (r < 0) or (n < r):
                return 0
            r = min(r, n - r)
            return fact[n] * factinv[r] * factinv[n-r] % p

        p = 10 ** 9 + 7
        N = 10 ** 5  # N は必要分だけ用意する
        fact = [1, 1]  # fact[n] = (n! mod p)
        factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
        inv = [0, 1]  # factinv 計算用

        for i in range(2, N + 1):
            fact.append((fact[-1] * i) % p)
            inv.append((-inv[p % i] * (p // i)) % p)
            factinv.append((factinv[-1] * inv[-1]) % p)

        aa.sort()

        cnt = 0

        c = 1
        large = k
        before = 0

        for i, j in zip(aa[k-1:], reversed(aa[:-k+1])):
            c = cmb(large, k, p)
            cnt += (i-j)*(c-before)
            cnt = cnt%(10**9+7)
            before = c
            large += 1

        print(int(cnt%(10**9+7)))

Buggy python submission (verdict: Runtime Error):
if __name__ == '__main__':
    import sys
    input = sys.stdin.readline

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

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

    if k == 1:
        print(0)
        exit()

    aa.sort()

    cnt = 0

    c = 1
    large = k+1
    before = 0

    for i, j in zip(aa[k-1:], reversed(aa[:-k+1])):

        cnt += (i-j)*(c-before)
        before = c
        c = c*large/(large-k)

        large += 1
    print(int(cnt%(10**9+7)))


Fixed submission:
if __name__ == '__main__':
    import sys
    input = sys.stdin.readline


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

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

    """

    n = 100000
    k = 50000
    aa = [i for i in range(100000)]
    """

    import math

    if k == 1:
        print(0)
    else:
        def cmb(n, r, p):
            if (r < 0) or (n < r):
                return 0
            r = min(r, n - r)
            return fact[n] * factinv[r] * factinv[n-r] % p

        p = 10 ** 9 + 7
        N = 10 ** 5  # N は必要分だけ用意する
        fact = [1, 1]  # fact[n] = (n! mod p)
        factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
        inv = [0, 1]  # factinv 計算用

        for i in range(2, N + 1):
            fact.append((fact[-1] * i) % p)
            inv.append((-inv[p % i] * (p // i)) % p)
            factinv.append((factinv[-1] * inv[-1]) % p)

        aa.sort()

        cnt = 0

        c = 1
        large = k
        before = 0

        for i, j in zip(aa[k-1:], reversed(aa[:-k+1])):
            c = cmb(large, k, p)
            cnt += (i-j)*(c-before)
            cnt = cnt%(10**9+7)
            before = c
            large += 1

        print(int(cnt%(10**9+7)))