#K67132. Hiking Distance Calculator

    ID: 32575 Type: Default 1000ms 256MiB

Hiking Distance Calculator

Hiking Distance Calculator

You are given a hiking log represented by an array of integers, where each integer denotes the number of kilometers hiked on a specific day. Additionally, you are given a sequence of queries. Each query consists of two integers \(L\) and \(R\) representing the starting and ending days (1-indexed).

Your task is to calculate the total distance hiked for each query. In other words, for each query, compute the sum:

\(\sum_{i=L}^{R} distance[i]\)

where \(distance[i]\) is the distance hiked on the \(i\)-th day.

Input/Output specifications are provided below.

inputFormat

The input is given via standard input (stdin) and has the following format:

  1. An integer \(N\) representing the number of days.
  2. \(N\) space-separated integers where the \(i\)-th integer represents the kilometers hiked on the \(i\)-th day.
  3. An integer \(Q\) denoting the number of queries.
  4. \(Q\) lines follow, each containing two integers \(L\) and \(R\) (1-indexed) indicating the start and end day for the query.

outputFormat

For each query, output the total kilometers hiked from day \(L\) to day \(R\) on a new line via standard output (stdout).

## sample
1
5
1
1 1
5

</p>