# Count of Array solution codechef

## Count of Array solution codechef

You love array, don’t you?

You are given two integer NN and MM, along with an array BB of length NN containing pairwise distinct integers. You have to find the number of array AA of length NN satisfying the follow conditions:

1. 1AiM1≤Ai≤M.
2. AiAjAi≠Aj for all 1i<jN1≤i<j≤N.
3. AiBiAi≠Bi for all 1iN1≤i≤N.

Since the answer can be very large, output it under modulo 109+7109+7.

### Input Format

• The first line of the input contains two space-separated integers NN and MM.
• The second line of the input contains NN separated integers B1,B2,,BNB1,B2,…,BN – the array BB.

### Output Format

Output on a single line the number of satisfactory array modulo 109+7109+7.

### Constraints

• 1N21051≤N≤2⋅105
• 1M31051≤M≤3⋅105
• 1Bi1091≤Bi≤109
• BiBjBi≠Bj for all 1i<jN1≤i<j≤N.

### Sample Input 1

3 4
5 1 2


### Sample Output 1

14


### Explanation

All satisfactory arrays are:

• [1,2,3][1,2,3]
• [2,3,1][2,3,1]
• [3,2,1][3,2,1]
• [1,2,4][1,2,4]
• [2,4,1][2,4,1]
• [4,2,1][4,2,1]
• [1,3,4][1,3,4]
• [1,4,3][1,4,3]
• [3,4,1][3,4,1]
• [4,3,1][4,3,1]
• [2,3,4][2,3,4]
• [2,4,3][2,4,3]
• [3,2,4][3,2,4]
• [4,2,3][4,2,3]

### Sample Input 2

2 2
1 3


### Sample Output 2

1


### Explanation

The only satisfactory array is:

• [2,1]