CF BUDDY
← Problems·

1488F · Dogecoin

2300 · *special, binary search, data structures

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 11 Dogecoin per day. On the Internet, there are forecasts of the cost of 11 dogecoin for the next nn days. Every day, Ann can sell any amount of dogecoin that she currently has. Note that if Ann mined Dogecoin on the ii-th day, then she can sell it on the same day.

Ann has not yet decided when to start mining. She has prepared qq 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 ll and rr — the first and last days of mining. Note that Ann should not have any Dogecoin left after the rr-th day.

Input Format: The first line contains one integer nn (1n21051 \le n \le 2 \cdot 10^5).

The second line contains nn integers c1,c2,,cnc_1, c_2, \dots, c_n (1ci1061 \le c_i \le 10^6), where cic_i is the cost of Dogecoin on the ii-th day.

The third line contains one integer qq (1q21051 \le q \le 2 \cdot 10^5) — the number of Ann's plans.

The following qq lines contains two integers ll and rr (1lrn1 \le l \le r \le n) — 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.

Sample Cases

Case 1

Input

5
4 1 2 3 2
4
1 5
2 4
3 5
5 5

Output

15 9 8 2

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback