Problem: Recently, cryptocurrencies have become increasingly popular. Ann decided that it was about time she started mining the Dogecoin cryptocurrency. Ann's computer is not very powerful, so Ann mines exactly Dogecoin per day. On the Internet, there are forecasts of the cost of dogecoin for the next days. Every day, Ann can sell any amount of dogecoin that she currently has. Note that if Ann mined Dogecoin on the -th day, then she can sell it on the same day.
Ann has not yet decided when to start mining. She has prepared possible plans and for each of them wants to know the maximum profit that she can get. Each of the plans is described by two numbers and — the first and last days of mining. Note that Ann should not have any Dogecoin left after the -th day.
Input Format: The first line contains one integer ().
The second line contains integers (), where is the cost of Dogecoin on the -th day.
The third line contains one integer () — the number of Ann's plans.
The following lines contains two integers and () — the first and last days of mining.
Output Format: For each Ann's plan print one integer — the maximum profit that she can get using this plan.