The Logging Company has a long line of
trees numbered from
to
. Each tree
has a mass
. The Company wants to cut some of the trees, so they hired you to calculate the mass of all the wood they would get from cutting all the trees between positions
and
inclusive
. In particular, they want you to answer
such queries.
Input Specification
- First line:
.
- Lines
to
: line
is the mass of tree
,
.
- The line
will contain the integer
, the number of queries the logging company wants answered.
- The next
lines will contain the integers
and
.
Output Specification
For each query, print the total mass of the trees at position such that
.
Scoring
- For 30% of the points,
.
- For 50% of the points,
.
- For the rest,
.
Sample Input
5
1
2
3
4
5
3
0 4
1 3
2 2
Sample Output
15
9
3
Comments