There are N numbers from 1 to N and your task is to create a permutation such that the cost of the permutation is minimum. For each number, there is a left and right cost. To put number p (1≤p≤N) at the ith index, it costs Lp∗(i−1)+Rp∗(N−i−1) where L[] and R[] cost is given.
You do not need to find that permutation but you need to find the total minimum possible cost of the permutation.
Input format
Output format
For each test case, print a single line containing one integer that denotes the minimum cost of the permutation.
Constraints
1≤T≤20
2≤N≤105
1≤Li,Ri≤107 for each 1≤i≤N
For the test case 1, The possible permutaion will be 3,1,2. The cost will be (0∗6+2∗2)+(1∗1+1∗4)+(2∗2+0∗7)=13 and this is the minimum possible value.
For the test case 2, The possible permutaion will be 1,4,3,2. The cost will be (0∗4+3∗3)+(1∗2+2∗2)+(2∗3+1∗5)+(3∗5+0∗8)=41 and this is the minimum possible value.