n, k, *a = $stdin.read.split.map(&:to_i)
M = 10**9 + 7

CMB = Array.new(n, 1)
(k - 1).times do |i|
  x = 0
  CMB.map! { |z| x = (x + z) % M }
  CMB.pop
end
p CMB.reverse!

def fsum(n, k, a)
  x = Array.new(n)
  CMB.lazy.zip(a).inject(0) { |sum, (cmb, a_k)| x.pop; (sum + a_k * cmb) % M }
end

min_sum = fsum(n, k, a.sort!)
max_sum = fsum(n, k, a.reverse!)

puts (max_sum - min_sum) % M
