n,k = gets.chomp.split.map(&:to_i)
a = gets.chomp.split.map(&:to_i).sort
sum = 0
dif = []

for i in 0..n-1-(k-1)
    d = a[i+k-1]-a[i]
    dif << d
end

l = dif.length
e = l
for i in 0..l/2
    sum += dif[i]*e
    if i != l-i-1
        sum += dif[l-1-i]*e
    end
    sum %= 10**9+7
    e += e-(k*(i+1))
end

puts sum