/**
 * Solution to Challenge Problem 1.
 * Author: Igor Naverniouk
 *
 * Input:
 *     The program expects the input in
 * the following format:
 * - the size of the array, n.
 * - n elements of the array.
 * - pairs of integers (i, j) representing
 *   queries.
 * All of these numbers are separated by whitespace.
 *
 * Output:
 *     For each query, the answer will be printed,
 * one per line.
 *
 * Note:
 *     Contrary to the example shown in class,
 * this solution will not use a second vector.
 * Instead, it will modify the input vector.
 **/
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    // read the array's size
    int n;
    cin >> n;

    // create a vector that is one longer than needed
    vector< int > v( n + 1 );

    // read the numbers into v starting at index 1, not 0.
    // This is so it is easier to compute the running sums after
    for( int i = 1; i <= n; i++ ) cin >> v[i];

    // Initialize the first entry to 0 (it's garbage now)
    v[0] = 0;

    // Compute the running sums
    for( int i = 1; i <= n; i++ ) v[i] += v[i - 1];

    // Read and answer queries
    int i, j;
    while( cin >> i >> j ) cout << v[j + 1] - v[i] << endl;

    // Program finished normally
    return 0;
}

/**
 * To compile the program, save it as "ch1.cpp" and type
 * g++ -Wall ch1.cpp
 * To run, type
 * ./a.out
 *
 * For the following input:
 * 10
 * 2 3 8 9 7 5 -1 8 0 -2
 * 0 0
 * 1 1
 * 0 1
 * 2 3
 * 5 7
 * 1 8
 * 0 9
 * this program will print
 * 2
 * 3
 * 5
 * 17
 * 12
 * 39
 * 39
 **/
