|All-time Popular Problems|
|Maximum difference between node and its ancestor|
|Count nodes of linked list|
|Find first set bit|
|Angle between hour and minute hand|
|Recursively remove all adjacent duplicates|
|Remove every k'th node|
|Merge Two Sorted Arrays|
|Spirally traversing a matrix|
|Merge two sorted linked lists|
|Longest Increasing Subsequence|
Given an array you have to find the max sum of i*A[i] where i is the index of the array obtained by rotating the element of the array one by one . Your task is to complete the function max_sum which takes one argument which is the array A [ ] and returns an integer value denoting the required max sum .
The first line of input is the number of test cases T . Then T test cases follow . The first line of each test case is an integer N denoting the size of the array . Then in the next line are N space separated values of the array A [ ] .
For each test case output will be the required max sum.
8 3 1 2
Above the configuration possible by rotating elements are
3 1 2 8 here sum is 3*0+1*1+2*2+8*3 = 29
1 2 8 3 here sum is 1*0+2*1+8*2+3*3 = 27
2 8 3 1 here sum is 2*0+8*1+3*2+1*3 = 17
8 3 1 2 here sum is 8*0+3*1+1*2+2*3 = 11
Here the max sum is 29
Note:The Input/Ouput format and Example given are used for system's internal purpose, and should be used by a user for Expected Output only. As it is a function problem, hence a user should not read any input from stdin/console. The task is to complete the function specified, and not to write the full code.