Fill up buckets
Submissions: 363   Accuracy:

29.18%

  Difficulty: Medium   Marks: 4

There are N buckets. The task is to assign a certain number of balls to each bucket. Each bucket should have atleast one ball. The capacity of each bucket is provided in an array MAX. For the ith bucket, the capacity is MAX[i] and the number of balls to be assigned to the ith bucket is between 1 to MAX[i] both bounds inclusive. All buckets should have distinct number of balls. Output "the number of ways in which the N buckets can be filled" modulo 109+7.

 

Input:
First line of the input contains a single integer T denoting the number of test cases. Then T test cases follow. Each test case consists of two lines. First line of each test case consists of an integer - N denoting the number of buckets. Second line of each test case consists of N space separated integers of  array MAX[] denoting the maximum cappacity of each bucket.


Output:
For each test case, output the required answer in a separate line.

Constraints:
1 ≤ T ≤ 20
1 ≤ N ≤ 1000
1 ≤ MAX[k] ≤ 1000 for k=1,2..N


Example:
Input
2
1
6
2
5 8

Output
6
35

Explanation
For the first example, the single bucket can be assigned any number between 1 and 6, inclusive, hence 6 ways.

** For More Input/Output Examples Use 'Expected Output' option **

Author: AdityaChatterjee


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.