Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/massiv-oraliq-yigindisi

Range sum queries

Medium 1000 ms 128 MB 56%
Share

A positive integer $n$, an array of $n$ integers and $q$ queries are given. For the indices $l$ and $r$ of each query, compute the sum over the range:

$$S = a_{l} + a_{l+1} + \dots + a_{r}$$

Sums over the queried ranges of an array

Input

The first line contains two integers: $n$ and $q$. The second line contains $n$ integers. Each of the next $q$ lines contains two integers: $l$ and $r$.

Output

For each query, one integer on a separate line — the sum over the range.

Note

$1 \le n, q \le 10^{5}$
$-10^{9} \le a_{i} \le 10^{9}$
$1 \le l \le r \le n$

Examples

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

Sign in to submit a solution

Signing up is free and takes a minute.