Scavenging in Fountains
View as PDF
Submit solution
Points:
100
Time limit:
1.0s
PyPy 3
3.0s
Python 3
3.0s
Memory limit:
977M
Problem type
Jerry desperately needs money. At the bottom of a pool lies a line of coins.
You are given an array , where
is the value of the
-th coin. Jerry
asks you
questions: if he scoops up all the coins between the
-th and
-th coins
(inclusive), what is the total value of the coins he scoops up?
Input
The first line contains the integer , the number of coins in the fountain.
The second line contains integers,
, where
is the value of the
-th
coin.
The third line contains the integer , the number of questions Jerry will ask.
The following lines each contain two integers
and
, asking for the total value of the
coins from the
-th coin through the
-th coin. The queries are 1-indexed.
Output
For each question Jerry asks, output a line containing the answer.
Constraints
Example 1
Input
10
7 7 4 6 3 8 9 8 5 1
4
8 10
4 6
3 6
8 9
Output
14
17
21
13
Example 2
Input
10
4 5 6 10 8 10 8 9 1 7
4
4 10
1 8
3 5
4 6
Output
53
60
24
28
Comments