#P1696H. Maximum Product?

    ID: 1016 Type: RemoteJudge 1000ms 512MiB Tried: 0 Accepted: 0 Difficulty: 10 Uploaded By: Tags>brute forcecombinatoricsdpgreedyimplementationmathtwo pointers*3500

Maximum Product?

Description

You are given a positive integer kk. For a multiset of integers SS, define f(S)f(S) as the following.

  • If the number of elements in SS is less than kk, f(S)=0f(S)=0.
  • Otherwise, define f(S)f(S) as the maximum product you can get by choosing exactly kk integers from SS.

More formally, let S|S| denote the number of elements in SS. Then,

  • If S<k|S|<k, f(S)=0f(S)=0.
  • Otherwise, f(S)=maxTS,T=k(iTi)f(S)=\max\limits_{T\subseteq S,|T|=k}\left(\prod\limits_{i\in T}i\right).

You are given a multiset of integers, AA. Compute BAf(B)\sum\limits_{B\subseteq A} f(B) modulo 109+710^9+7.

Note that in this problem, we distinguish the elements by indices instead of values. That is, a multiset consisting of nn elements always has 2n2^n distinct subsets regardless of whether some of its elements are equal.

The first line of input contains two integers nn and kk, where nn is the number of elements in AA (1kn6001\le k\le n\le 600).

The second line of input contains nn integers a1,a2,,ana_1,a_2,\dots,a_n, describing the elements in AA (109ai109-10^9\le a_i\le 10^9).

Output BAf(B)\sum\limits_{B\subseteq A} f(B) modulo 109+710^9+7.

Input

The first line of input contains two integers nn and kk, where nn is the number of elements in AA (1kn6001\le k\le n\le 600).

The second line of input contains nn integers a1,a2,,ana_1,a_2,\dots,a_n, describing the elements in AA (109ai109-10^9\le a_i\le 10^9).

Output

Output BAf(B)\sum\limits_{B\subseteq A} f(B) modulo 109+710^9+7.

Sample Input 1

3 2
-1 2 4

Sample Output 1

10

Sample Input 2

3 1
1 1 1

Sample Output 2

7

Sample Input 3

10 4
-24 -41 9 -154 -56 14 18 53 -7 120

Sample Output 3

225905161

Sample Input 4

15 5
0 0 2 -2 2 -2 3 -3 -3 4 5 -4 -4 4 5

Sample Output 4

18119684

Note

Consider the first sample. From the definitions we know that

  • f()=0f(\varnothing)=0
  • f({1})=0f(\{-1\})=0
  • f({2})=0f(\{2\})=0
  • f({4})=0f(\{4\})=0
  • f({1,2})=2f(\{-1,2\})=-2
  • f({1,4})=4f(\{-1,4\})=-4
  • f({2,4})=8f(\{2,4\})=8
  • f({1,2,4})=8f(\{-1,2,4\})=8

So we should print (0+0+0+024+8+8)mod(109+7)=10(0+0+0+0-2-4+8+8)\bmod (10^9+7)=10.

In the second example, note that although the multiset consists of three same values, it still has 88 distinct subsets: ,{1},{1},{1},{1,1},{1,1},{1,1},{1,1,1}\varnothing,\{1\},\{1\},\{1\},\{1,1\},\{1,1\},\{1,1\},\{1,1,1\}.