Sum on a segment#682

Sum on a segment

3 seconds
512 megabytes
Very easy

Given a sequence of numbers a_1, \ldots, a_n. For given indices and , calculate

S_{l, r} = a_l + a_{l+1} + \ldots + a_r

Input

The first line contains the number of elements (1 \le n \le 10^6). The second line contains the numbers a_i (1 \le a_i \le 1000) separated by spaces. The third line contains the number of queries (1 \le m \le 10^6). Each of the next lines contains the indices l_i and r_i (1 \le l_i \le r_i \le n).

Output

Print the value S_{l_i, r_i} for each query on a separate line.

Examples

Example 1

Loading
Loading