Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!
ALGOR Contest: Round #2
Problem D · 150 points · ICPC rules

~/algor $ cat contests/round-2/D

D. Range sums

1000 ms 128 MB

An array a of n integers and q queries are given. Each query gives two numbers l and r: find the sum a_l + a_{l+1} + … + a_r. There are many queries, so computing each one separately will not fit in the time limit.

Range sums: the sum of the elements on the range [2..4] is 12

Input

The first line contains n and q. The second line contains n integers — a_1, a_2, …, a_n. Each of the next q lines contains two numbers l and r.

Output

q lines: the sum for each query.

Note

1 ≤ n, q ≤ 200 000; −10⁹ ≤ a_i ≤ 10⁹; 1 ≤ l ≤ r ≤ n. The sum may not fit in a 32-bit integer.

Examples

Input #1
5 3
1 2 3 4 5
1 3
2 5
4 4
Output #1
6
14
4
Input #2
4 2
-5 10 -3 7
1 4
2 3
Output #2
9
7

Sign in to submit a solution

Signing up is free and takes a minute.