Minimum Permutation

5

1 votes
C++, Math, Combinatorics, Arrays, Inclusion-exclusion
Problem

You are given an array of length . Your task is to find the number of permutations of length from which you can construct the given array using the following rule:

  • For each element in the array , it must be equal to the minimum value among the elements in positions 1 through of the permutation  i.e. .

Since the answer could be a large number, you need to compute it modulo .

A permutation is a sequence of integers from  to  of length  containing each number exactly once. For example,  are permutations and  are not.

Input format

  • The first line contains an integer , denoting the number of test cases.
  • The first line of each test casecontains an integer .
  • The next line of each test case contains space-separated integers, elements of array .

Output format

For each test case, print the number of permutations of length from which you can construct the given array . Since the answer could be very large, print it modulo .

Constraints

 

Sample Input
2
5
2 3 1 1 1 
5
5 4 3 2 1
Sample Output
0
1
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

For test case : No permutation satisfies the condition. Hence, the answer is .

For test case : The only permutation will be . Hence, the answer is .

Editor Image

?