CSES - E4590 2020 4 - Bank Account
  • Time limit: 1.00 s
  • Memory limit: 512 MB

Teemu has a bank account. On some days he deposits or withdraws money. Some days he doesn't do anything with the account

Now he wonders how much his balance has changed between the morning of day aa and evening of day bb

Input

The first line contains a two integer, nn and qq, the number of days and the number of queries, respectively.

The second line contains nn integers, x1,x2,,xnx_1, x_2, \ldots, x_n. If xi>0x_i \gt 0, Teemu deposited total of xix_i units of money on ithi^{th} day. If xi<0x_i \lt 0, Teemu withdrew total of xi|x_i| units of money on ithi^{th} day. If xi=0x_i=0, Teemu didn't touch the account on ithi^{th} day.

Each next qq lines contain two integers, aja_j and bjb_j, the first and last days of query jj.

Output

Output qq lines, one for each query. The jthj^{th} line should contain a single integer, the amount of money that the balance has changed between the morning of day aja_j (i.e. before any deposits or withdrawals on that day) and the evening of the day bjb_j (i.e. after all deposits and withdrawals on that day).

Limits

  • The balance of the account is always non-negative, i.e. 0\ge 0, and at most 10610^6
  • 100xi100-100 \le x_i \le 100
  • 1n,q1041 \le n, q \le 10^4

Example

Input:

6 10
10 -5 -5 100 50 -100
1 6
1 2
5 6
4 4
4 6
2 3
1 3
3 4
3 6
2 4

Output:

50
5
-50
100
50
-10
0
95
45
90

Explanation:
1st1^{st} query: In the beginning of the first day the balance is 0, and after the last day the balance is 50, hence the difference is 50.
2nd2^{nd} query: In the beginning of the first day the balance is 0, and after the second day the balance is 5 (=10-5), hence the difference is 5.
3rd3^{rd} query: In the beginning of the second last day the balance is 100, and after the last day the balance is 50, hence the difference is -50.
4th4^{th} query: In the beginning of the fourth day the balance is 0, and after the fourth day the balance is 100, hence the difference is 100.