! permとfactの前計算は ~/repos/contest/atcoder_ojt/abc156_e/fortran.f08 参照
program main
  implicit none
  integer(8) :: n, k, i, res
  integer(8), parameter :: m = 10 ** 9 + 7
  integer(8), allocatable :: a(:)
  integer(8), allocatable :: fact(:), ifact(:)
  read *, n, k
  allocate (a(n), fact(0:n), ifact(0:n))
  read *, a
  call quicksort(a)
  call calc_fact

  res = 0

  ! Add sum(max(s)) to res
  do i = 1, n
    res = res + modulo(a(i) * combi(i - 1, k - 1), m)
    res = modulo(res, m)
  end do

  ! Subtract sum(min(s)) from res
  do i = 1, n
    res = res - modulo(a(i) * combi(n - i, k - 1), m)
    res = modulo(res, m)
  end do

  print "(i0)", res
  contains

  recursive subroutine quicksort(a)
    integer(8), intent(inout) :: a(:)
    integer(8) :: pivot, i, j, k, tmp, n
    real(8) :: r
    n = size(a)
    if (n <= 1) return
    i = 1
    j = n
    call random_number(r)
    k = 1 + floor(r * n)
    k = max(1_8, min(k, n))
    pivot = a(k)
    do
      do while (.not. pivot <= a(i))
        i = i + 1
      end do
      do while (.not. a(j) <= pivot)
        j = j - 1
      end do
      if (i >= j) exit
      tmp = a(i)
      a(i) = a(j)
      a(j) = tmp
      i = i + 1
      j = j - 1
    end do
    call quicksort(a(1:i - 1))
    call quicksort(a(j + 1:n))
  end subroutine quicksort

  integer(8) function combi(n, k)
    integer(8), intent(in) :: n, k
    if (n < k) then
      combi = 0
      return
    end if
    combi = fact(n)
    combi = combi * ifact(k)
    combi = modulo(combi, m)
    combi = combi * ifact(n - k)
    combi = modulo(combi, m)
  end function combi

  subroutine calc_fact()
    integer(8) :: i
    fact(0) = 1
    ifact(0) = inv(1_8)
    do i = 1, n
      fact(i) = modulo(fact(i - 1) * i, m)
      ifact(i) = inv(fact(i))
    end do
  end subroutine calc_fact

  function inv(n)
    integer(8), intent(in) :: n
    integer(8) :: inv
    inv = pow(n, m - 2)
  end function inv

  recursive function pow(n, p) result(res)
    integer(8), intent(in) :: n, p
    integer(8) :: res
    if (p == 0) then
      res = 1
    else if (modulo(p, 2_8) == 0) then
      res = modulo(pow(n, p / 2) ** 2, m)
    else
      res = modulo(pow(n, p - 1) * n, m)
    end if
  end function pow
end program main
