luogu#P5087. 数学

数学

Background

On the magical land of Xiaoben, there is an infamous coach Xiaoben.

Solution write-up: https://blog.csdn.net/kkkksc03/article/details/84928333.

Problem Description

Xiaoben loves multiplication. His favorite thing to do is: choose KK numbers from a sequence with NN elements (note: you cannot choose the same element multiple times, but choosing different elements with the same value is allowed), and then take the product of these KK numbers as the score of this combination.

Xiaoben wants to try all such combinations and compute the sum of the scores of all combinations. But he also needs to run a mock contest to crush us newbies, so he has to hand this task to you.

Xiaoben (in some ways) is still very kind, so you do not need to use big integers. You only need to output the answer modulo 109+710^9+7.

Input Format

The first line contains two integers NN and KK.

The second line contains NN integers AiA_i describing the sequence.

Output Format

Output one integer in one line, representing the answer.

3 3
1 1 1
1
4 3
1 1 1 2
7

Hint

Explanation for Sample #2:

Xiaoben can choose four combinations: {A[1],A[2],A[3]},{A[1],A[2],A[4]},{A[1],A[3],A[4]},{A[2],A[3],A[4]}. Their scores are 1,2,2,21,2,2,2 respectively. The total is 77.

Constraints:

For 10%10\% of the testdata, N5000,K2N\le 5000, K\le 2.

For 30%30\% of the testdata, N105,K3N\le 10^5, K\le 3.

For 50%50\% of the testdata, N105,K5N\le 10^5, K\le 5.

For 100%100\% of the testdata, $1\le N\le 10^5, 1\le K \le 300 \& \& K\le N, 1\le A[i]\le 10^8$.

Translated by ChatGPT 5