#K39137. Sequence Elements Query

    ID: 26354 Type: Default 1000ms 256MiB

Sequence Elements Query

Sequence Elements Query

You are given a sequence defined by an array \(D\) of \(n\) integers. The sequence \(S\) is defined as follows:

\(S_1 = D_1\) and for \(i \geq 2\), \(S_i = S_{i-1} + (D_i - D_{i-1})\).

Note that according to this recurrence, the sequence \(S\) will be identical to the array \(D\). You are then given a list of queries, each representing a 1-indexed position in \(S\). Your task is to output the element at each queried position.

For example, if the input array is [2, 5, 8, 14, 20] and the queries are [1, 3, 5], then the answer is [2, 8, 20].

inputFormat

The input is read from stdin and has the following format:

  1. An integer \(n\) representing the number of elements in the sequence.
  2. \(n\) space-separated integers representing the array \(D\).
  3. An integer \(q\) representing the number of queries.
  4. \(q\) space-separated integers where each integer is a 1-indexed query.

It is guaranteed that \(1 \leq n \leq 10^5\) and the queries are valid indices in the sequence.

outputFormat

Output the sequence elements corresponding to the given queries to stdout in a single line, separated by spaces.

## sample
5
2 5 8 14 20
3
1 3 5
2 8 20