You will be given a set of distinct numbers. Your task is to find that even length subset which will give you a maximum value of P % (109 + 7). This value of P for a subset of length N is defined as below :
P = (product of N/2 maximum values) / (product of N/2 minimum values)
Now suppose we have a subset S = {A1 , A3 , A4 , A5}
where A1 < A3 < A4 < A5 , then P = (A4 * A5) / (A1 * A3)
Note : Subset should be of even length and should be non-empty and you have to output the maximum value of P % (109 + 7) i.e. that value which should be maximum after taking this mod.
Input
First line of the input will contian T (number of test cases). Then for every test case first line will contain N (size of the set) and the next line will contain N space separated integers (elements of the set).Output
For every test case print the required maximum value.Constraints
1 <= T <= 52 <= N <= 16
1 <= S[i] <= 109
In the first test case the only subset of even length is { 2, 4} , so ans is 4/2 = 2.
In the second test case the ans will be {2, 8} i.e. 8/2 = 4.
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor