|
||||||||||
Cut PiecesTime Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Total Submission(s): 1301 Accepted Submission(s): 591 Problem Description Suppose we have a sequence of n blocks. Then we paint the blocks. Each block should be painted a single color and block i can have color 1 to color ai. So there are a total of prod(ai) different ways to color the blocks. Consider one way to color the blocks. We call a consecutive sequence of blocks with the same color a "piece". For example, sequence "Yellow Yellow Red" has two pieces and sequence "Yellow Red Blue Blue Yellow" has four pieces. What is S, the total number of pieces of all possible ways to color the blocks? This is not your task. Your task is to permute the blocks (together with its corresponding ai) so that S is maximized. Input First line, number of test cases, T. Following are 2*T lines. For every two lines, the first line is n, length of sequence; the second line contains n numbers, a1, ..., an. Sum of all n <= 106. All numbers in the input are positive integers no larger than 109. Output Output contains T lines. Each line contains one number, the answer to the corresponding test case. Since the answers can be very large, you should output them modulo 109+7. Sample Input
Sample Output
Hint Both sequence 1 3 2 and sequence 2 3 1 result in an S of 14. Source | ||||||||||
|