Alice is having an array of N numbers (1-based indexing) and was playing with it by answering queries of the form where . Query was simply sum of elements of the array with indexes from (Both inclusive).
In the mean time John, her younger brother came and rearrange all the elements of the array before she could reply to the queries.
Now if earlier the output of queries were Now it becomes
The values of may still be same. But one thing good happen in all this incidence is the sum of all the queries become maximum that is is maximum . She is interested in finding this maximum value of sum.
Input Format:
First line consists of N integers and each q queries.
Next line contains N elements presented in array.
After this, the line consists of q queries, where each query is of form .
Output Format:
We need to find the maximum sum of query replies after the array elements are rearranged .
Constraints :
Each array element is in range between
Each query satisfies
We can see that if we rearrange the elements as [3 6 4] then we get total of [9+10+13] = 32