#K81512. Creature Sum Queries

    ID: 35770 Type: Default 1000ms 256MiB

Creature Sum Queries

Creature Sum Queries

You are given the prefix sums of an array representing the selling values of creatures. Your task is to answer a series of queries where each query asks you to compute the sum of the creatures' values between two indices l and r (inclusive).

Assume the prefix sum array \(P\) is computed from an original array \(A\) such that \(P[i] = \sum_{j=1}^{i} A[j]\) for \(1 \leq i \leq n\). Then, the sum of the values in the range \([l, r]\) can be computed as:

[ \text{Answer} = \begin{cases} P[r] & \text{if } l = 1,\ P[r] - P[l-1] & \text{if } l > 1. \end{cases} ]

Read the input from the standard input and output the results for each query on a new line.

inputFormat

The first line contains an integer \(n\) representing the number of elements in the prefix sum array.

The second line contains \(n\) space-separated integers denoting the prefix sums.

The third line contains an integer \(q\) representing the number of queries.

Each of the next \(q\) lines contains two space-separated integers \(l\) and \(r\) representing a query asking for the sum of values from index \(l\) to \(r\) (1-indexed).

outputFormat

For each query, output the computed sum on a new line.

## sample
5
1 3 6 10 15
3
1 3
2 4
1 5
6

9 15

</p>