Skip to content
UPEEC

Range Sum Queries

Medium#arrays#prefix-sums· solved by 0 · time limit 2.0 s

Answer qq queries: each asks for al+al+1+⋯+ara_l + a_{l+1} + \dots + a_r (1-based). Re-adding for every query is too slow — precompute prefix sums.

Input

nn, the nn integers, qq, then qq lines with ll and rr.

Output

One sum per line.

Constraints

1≤n,q≤1051 \le n, q \le 10^5, ∣ai∣≤106|a_i| \le 10^6

Sample 1

Input

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

Output

15
5
4

Sign in or join free to run and submit your solution.