Modular Circular Permutations
You are given an array
containing distinct positive integers.
Let be a permutation of . Define the value of to be
where is treated to be .
Find the maximum value across all permutations of .
Input Format
- The first line of input contains a single integer , denoting the number of test cases. The description of test cases follows.
- Each test case consists of two lines of input.
- The first line of each test case contains an integer — the size of .
- The second line of each test case contains space-separated integers — the elements of .
Output Format
- For each test case, output a new line containing the answer — the maximum possible value across all permutations of .
Constraints
- for
- The sum of across all test cases won't exceed .
Sample Input 1
2
2
5 13
4
11 5 14869010166 19007432007
Sample Output 1
8
14869010184
Explanation
Test case : The value of any permutation is .
Test case : The cyclic permutations of the given array and their corresponding values are:
- with value
- with value
- with value
- with value
- with value
- with value
Among these, the highest value is .
Comments
Post a Comment