There is a shop named Chocolove in the Codeland. There are many chocolates in the shop. Each chocolate has its own taste value. You want to take some chocolates from this shop. But the chocolates are not free. You have to pay.
If you take chocolate i and the previous chocolate you took is j, the cost of taking chocolate i is the difference between i*Tj and j*Ti where Ti, Tj is the taste value of chocolate i and j respectively. Remember, you can’t take chocolate i more than once. The shop has an offer too. The cost of the chocolate you take first is 0.
Now you want to know what is the minimum amount of money you have to pay if you take x chocolates from the shop.
The first line of the input contains an integer N, the number of chocolates. The next line contains N integers separated by a space, ith integer denotes the taste value of ith chocolate.
The next line contains an integer Q, the number of queries. The next Q lines will contain values denoting each query. In each query, there will be an integer x, the number of chocolates you want to take from the shop.
1 <= N <= 19
0 <= Taste Value <= 109
1 <= Q <= 105
1 <= x <= N
For each query, print the minimum amount of money you have to pay in a single line if you take x chocolates from the shop
3 17 90 81 2 3 2
In the first query, one of the best ways is taking chocolates in this order: 2, 1, 3.