program max_min_sums
    implicit none
    integer(8):: n, k, i, smax, smin
    integer(8), parameter:: mod_ = 1000000007
    integer(8), allocatable:: a(:), fac(:), finv(:), inv(:)

    ! import --------------------------
    read*, n, k
    allocate(a(n), fac(0:n), finv(0:n), inv(0:n))
    read*, a(:)
    ! init_combination table
    call com_init(fac(:), finv(:), inv(:), mod_)

    ! sort a --------------------------
    call marge_sort(a(:), 1_8, n)
    smax = 0; smin = 0
    do i=1,n; block; integer(8):: mi, cof
        mi = n-i+1
        cof = comb(i-1, k-1)
        smax = mod(smax + cof*a(i), mod_)
        smin = mod(smin + cof*a(mi), mod_)
    end block; end do

    print*, mod(smax - smin, mod_)

contains
recursive subroutine marge_sort(arr, first, last)
    integer(8):: arr(:), first, last
    integer(8):: mean, tmp

    if (last - first <= 1) then
        ! sort
        if (arr(last) < arr(first)) then
            tmp = arr(last)
            arr(last) = arr(first)
            arr(first) = tmp
        end if
        return
    end if

    !  only : (last - first) > 1
    mean = (first + last) / 2
    call marge_sort(arr, first, mean)
    call marge_sort(arr, mean+1, last)
    call marge(arr, first, last, mean)
end subroutine


subroutine marge(arr, first, last, mean)
    integer(8):: arr(:), first, last, mean
    integer(8):: il, ir, i
    integer(8), allocatable:: tmp(:)

    allocate(tmp(last-first+1))
    il = first
    ir = mean+1
    i = 1

    do while (il <= mean .and. ir <= last)
        if (arr(il) <= arr(ir)) then
            tmp(i) = arr(il)
            i = i+1
            il = il+1
        else
            tmp(i) = arr(ir)
            i = i+1
            ir = ir+1
        end if        
    end do

    if (il > mean)then
        tmp(i:) = arr(ir:last)
    else
        tmp(i:) = arr(il:mean)
    end if
    arr(first:last) = tmp(:)
    end subroutine


    subroutine com_init(fac, finv, inv, mod_)
        integer(8):: fac(0:), finv(0:), inv(0:), mod_
        integer(8):: i

        fac(0:1) = 1
        finv(0:1) = 1
        inv(1) = 1

        do i=2, size(fac(1:))
            fac(i) = mod(fac(i-1)*i, mod_)
            inv(i) = calc_inv(i,mod_)
            finv(i) = mod(finv(i-1) * inv(i), mod_)             
        end do
    end subroutine


    function comb(n, k) result(ret)
        integer(8):: ret, n, k
        if(n<k) then
            ret = 0
        else if(n < 0 .or. k < 0) then
            ret = 0
        else
            ret = mod(fac(n)*mod(finv(k)*finv(n-k), mod_), mod_)
        end if        
    end function

    
    function calc_inv(i,mod_) result(inv)
        integer(8):: i, mod_, inv
        integer(8):: lev, a
        lev = mod_ - 2
        inv = 1
        a = i

        do while(lev /= 0)
            if(mod(lev, 2)/=0) inv = mod(inv*a, mod_)
            lev = lev/2
            a = mod(a*a, mod_)
        end do
    end function


end program max_min_sums