atcoder#ABC151E. [ABC151E] Max-Min Sums

[ABC151E] Max-Min Sums

Score : 500500 points

Problem Statement

For a finite set of integers XX, let f(X)=maxXminXf(X)=\max X - \min X.

Given are NN integers A1,...,ANA_1,...,A_N.

We will choose KK of them and let SS be the set of the integers chosen. If we distinguish elements with different indices even when their values are the same, there are NCK{}_N C_K ways to make this choice. Find the sum of f(S)f(S) over all those ways.

Since the answer can be enormous, print it mod(109+7)\bmod (10^9+7).

Constraints

  • 1N1051 \leq N \leq 10^5
  • 1KN1 \leq K \leq N
  • Ai109|A_i| \leq 10^9

Input

Input is given from Standard Input in the following format:

NN KK

A1A_1 ...... ANA_N

Output

Print the answer mod(109+7)\bmod (10^9+7).

4 2
1 1 3 4
11

There are six ways to choose SS: {1,1},{1,3},{1,4},{1,3},{1,4},{3,4}\{1,1\},\{1,3\},\{1,4\},\{1,3\},\{1,4\}, \{3,4\} (we distinguish the two 11s). The value of f(S)f(S) for these choices are 0,2,3,2,3,10,2,3,2,3,1, respectively, for the total of 1111.

6 3
10 10 10 -10 -10 -10
360

There are 2020 ways to choose SS. In 1818 of them, f(S)=20f(S)=20, and in 22 of them, f(S)=0f(S)=0.

3 1
1 1 1
0
10 6
1000000000 1000000000 1000000000 1000000000 1000000000 0 0 0 0 0
999998537

Print the sum mod(109+7)\bmod (10^9+7).