Farmer John's pasture can be regarded as an N×M (2≤N≤109, 2≤M≤2⋅105) 2D grid of square "cells" (picture a huge chessboard). The cell at the x-th row from the top and y-th column from the right is denoted by (x,y) for each x∈\[1,N],y∈\[1,M]. Furthermore, for each y∈\[1,M], the y-th column is associated with the cost c_y (1≤c_y≤109).
Bessie starts at the cell (1,1). If she is currently located at the cell (x,y), then she may perform one of the following actions:
Given Q (1≤Q≤2⋅105) independent queries each of the form (x_i,y_i) (x_i∈\[1,N],y_i∈\[1,M]), compute the minimum possible total cost for Bessie to move from (1,1) to (x_i,y_i).
The first line contains N and M.
The second line contains M space-separated integers c_1,c_2,…,c_M.
The third line contains Q.
The last Q lines each contain two space-separated integers x_i and y_i.
Q lines, containing the answers for each query.
Note that the large size of integers involved in this problem may require the use of 64-bit integer data types (e.g., a "long long" in C/C++).
The output in grid format:
1 2 3 4
*--*--*--*--*
1 | 0| 1| 2| 3|
*--*--*--*--*
2 | 1| 5| 9|13|
*--*--*--*--*
3 | 2|11|20|29|
*--*--*--*--*
4 | 3|19|35|49|
*--*--*--*--*
5 | 4|29|54|69|
*--*--*--*--*