This page is still under construction.

Parts of this page are still being built. What you see may change.

Sequence (Hard)

Time limit1sMemory limit512 MB

Summary
Sum the products A[B1]*...*A[BM] over all increasing index tuples B of length M whose chosen values are pairwise distinct, modulo 1e9+7.
Level

Hard8 of 10

Topics
Dynamic programming, Combinatorics, Math, Sorting
Solved
No attempts yet

Problem

You are given a sequence A1,A2,⋯ ,ANA_1, A_2, \cdots, A_N of NN positive integers and an integer MM. A sequence B1,B2,⋯ ,BMB_1, B_2, \cdots, B_M is called a good sequence if it satisfies all of the following.

  • Its length is MM.
  • Every element is an integer between 11 and NN.
  • It is increasing: B1<B2<⋯<BMB_1 < B_2 < \cdots < B_M.
  • AB1,AB2,⋯ ,ABMA_{B_1}, A_{B_2}, \cdots, A_{B_M} are pairwise distinct.

Over all good sequences B1,⋯ ,BMB_1, \cdots, B_M, find the sum of AB1×AB2×⋯×ABMA_{B_1} \times A_{B_2} \times \cdots \times A_{B_M} modulo 1 000 000 0071\,000\,000\,007.

Input

The first line contains the length NN of the sequence AA and the length MM of a good sequence, separated by a space.

The second line contains the sequence A1,A2,⋯ ,ANA_1, A_2, \cdots, A_N, separated by spaces.

Output

Over all good sequences B1,⋯ ,BMB_1, \cdots, B_M, print the sum of AB1×AB2×⋯×ABMA_{B_1} \times A_{B_2} \times \cdots \times A_{B_M} modulo 1 000 000 0071\,000\,000\,007.

Constraints

  • 1≤N≤1 0001 \le N \le 1\,000
  • 1≤M1 \le M
  • 1≤Ai≤100 0001 \le A_i \le 100\,000 (1≤i≤N1 \le i \le N)
  • MM is at most the number of distinct values in AA.

Hint

The sequence [3,1,1,2][3, 1, 1, 2] in the sample has two good sequences, [1,2,4][1, 2, 4] and [1,3,4][1, 3, 4]. The required answer is 3×1×2+3×1×2=123 \times 1 \times 2 + 3 \times 1 \times 2 = 12.

Examples1

  1. Example 1

    Input
    4 3
    3 1 1 2
    
    Expected output
    12