Count of Array

 You love array, don't you?

You are given two integer N and M, along with an array B of length N containing pairwise distinct integers. You have to find the number of array A of length N satisfying the follow conditions:

  1. 1AiM.
  2. AiAj for all 1i<jN.
  3. AiBi for all 1iN.

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

Input Format

  • The first line of the input contains two space-separated integers N and M.
  • The second line of the input contains N separated integers B1,B2,,BN - the array B.

Output Format

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

Constraints

  • 1N2105
  • 1M3105
  • 1Bi109
  • BiBj for all 1i<jN.

Sample Input 1 

3 4
5 1 2

Sample Output 1 

14

Explanation

All satisfactory arrays are:

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

Sample Input 2 

2 2
1 3

Sample Output 2 

1

Explanation

The only satisfactory array is:

Comments

Popular posts from this blog

Flipkart Runway: Season 3 | 2025 | Internship

Walmart Sparkplug 2022 | 150 students will be selected for summer internship | ₹1-1.1 lakh monthly

GUVI Software Course hindi Python Java ML C C++ OOPS With Certificate

Top-order failure leaves India in the doldrums