Roger is a famous gaming streamer on Twitch. However, he is notorious for being too lazy to go on stream. One of his fan even records the time he streams each day, and he would like to implement a fuction which can tell how much time Roger streamed from day A to day B.
In order to help this crazy fan out, you have to design a program which can take in several time inrervals (from day A to day B) and calculate how much time Roger streamed in each time interval.
The first line contains an integer N, represents the number of the days which the fan recorded.
The second line contains N integers, i-th number Hi represents the number of hours he streamed on day Hi.
The third line contains an integer M, represents the number of the intervals.
Next, there would be M lines, each line contains two integers A B, represents the starting day and the ending day of the interval. (Starting day A and ending day B are included in the interval.)
Input constraints: (You don't have to type the followings into your code, these are here to show you how large the data would be)
1 ≤ N, M ≤ 1000
0 ≤ Hi ≤ 24
1 ≤ A ≤ B ≤ N
Explanation:
Take sample input as an example:
The first line contains an integer 5, meaning there would be 5 days of records.
Next line contains 5 integers, which means Roger streamed for 2 hours on the first day, 3 hours on the second day, 0 hour on the third day, 7 hours on the fourth day, 5 hours on the fifth day.
The third line contains an integer 3, meaning there would be 3 time interval for queries.
Next, there are 3 lines, first line means from day 3 to day 5, second line means from day 2 to day 4, third line means from day 4 to day 4 (which means there is only on day in this time interval, and it is day 4).
Output M lines, each line contain an integer represents the number of hours Roger streamed in that time interval.
There should be a '\n' at the end of each line.
Explanation:
Take sample ouput as an example:
We can get the answer of the first time interval by adding streaming hours of day 3, day 4 and day 5, which is 0, 7, 5 respectively, and the answer is 12.
We can get the answer of the second time interval by adding streaming hours of day 2, day 3 and day 4, which is 3, 0, 7 respectively, and the answer is 10.
We can get the answer of the third time interval by adding streaming hours of day 4, which is 7, and the answer is 7.