Scavenging in Fountains


Jerry desperately needs money. At the bottom of a pool lies a line of coins.

You are given an array a1,…,ana_1, \dots, a_n, where aia_i is the value of the ii-th coin. Jerry asks you qq questions: if he scoops up all the coins between the ll-th and rr-th coins (inclusive), what is the total value of the coins he scoops up?

Input

The first line contains the integer nn, the number of coins in the fountain.

The second line contains nn integers, a1,…,ana_1, \dots, a_n, where aia_i is the value of the ii-th coin.

The third line contains the integer qq, the number of questions Jerry will ask.

The following qq lines each contain two integers ll and rr, asking for the total value of the coins from the ll-th coin through the rr-th coin. The queries are 1-indexed.

Output

For each question Jerry asks, output a line containing the answer.

Constraints

  • 1≤l≤r≤n≤1061 \le l \le r \le n \le 10^6
  • 1≤ai≤1091 \le a_i \le 10^9
  • 1≤q≤1061 \le q \le 10^6

Example 1

Input 1
10
7 7 4 6 3 8 9 8 5 1 
4
8 10
4 6
3 6
8 9
Output 1
14
17
21
13

Example 2

Input 2
10
4 5 6 10 8 10 8 9 1 7 
4
4 10
1 8
3 5
4 6
Output 2
53
60
24
28

Comments0


No comments yet

Be the first to comment.

New comment


Log in to join the discussion.