You are given an array A having N integers. You have to answer Q queries. The ith query is denoted by two integers Li,Ri. The answer to the ith query is ALi+min(ALi,ALi+1)+⋯+min(ALi,ALi+1…,ARi).
For each query find the answer.
Note: Since the size of the input and output is large, please use in memory stack size accordingly otherwise you may see error.
Input format
Output format
For each query, print the answer in a separate line.
Constraints
1≤N,Q≤3⋅1051≤Ai≤1091≤Li≤Ri≤N