


The first line of input contains an integer 'T' representing the number of test cases.
The first line of each test case contains one integer ‘N’ denoting the number of elements in the array.
The second line of each test case contains 'N' space-separated integers denoting the elements of the array 'ARR'.
For each test case, print a single line containing a single integer denoting the maximum power that can be obtained.
The output of each test case will be printed in a separate line.
You do not need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 50
1 <= N <= 10 ^ 4
0 <= ARR[i] <= 10 ^ 3
Where ‘T’ is the number of test cases, ‘N’ is the size of the given array, and ‘ARR[i]’ denotes the ith element of the array.
Time limit: 1 sec.
The idea here is to calculate the power of the array ARR every time by cyclically right shift the array ARR by 1, and then update the maximum power.
The algorithm is as follows:
The idea is to calculate Power(k) using the value of Power(k-1) in constant time. The relation between Power(k) and Power(k-1) is as follows:
Power(k) = 0 * Ck[0] + 1 * Ck[1] + ... + (N-1) * Ck[N-1]
Power(k-1) = 0 * Ck-1[0] + 1 * Ck-1[1] + ... + (N-1) * Ck-1[N-1]
= 0 * Ck[1] + 1 * Ck[2] + ... + (N-2) * Ck[N-1] + (N-1) * Ck[0]
Then,
Power(k) - Power(k-1) = Ck[1] + Ck[2] + ... + Ck[N-1] + (1-N)*Ck[0]
= (Ck[0] + ... + Ck[N-1]) - N*Ck[0]
= sum - N*Ck[0]
Where, sum = (Ck[0] + ... + Ck[N-1]).
Thus,
Power(k) = Power(k-1) + sum - N*Ck[0].
k = 0, C[0] = ARR[0].
k = 1, C[0] = ARR[N - 1].
k = 2, C[0] = ARR[N - 2].
…
The algorithm is as follows: