LearnPy Hub
← Arena
IntermediateRating 1100

Range Sums

Answer q queries: the sum of elements from position l to r (1-based, inclusive). Use prefix sums.

Input

n, the array, q, then q lines 'l r'.

Output

q lines.

Sample 1

Input
5
1 2 3 4 5
3
1 5
2 3
4 4
Output
15
5
4

Sample 2

Input
1
7
1
1 1
Output
7
solution.py
Output appears here
Range Sums · Python Arena problem · LearnPy Hub