Can you answer these queries - 1#2906

Can you answer these queries - 1

1 second
128 megabytes
Medium (≈1000)

You are given a sequence of integers a_1, a_2, \ldots, a_n. A query Q(x, y) asks for the maximum sum of a contiguous subsegment lying within the segment :

Q(x, y) = \max_{x \le i \le j \le y} (a_i + a_{i + 1} + \ldots + a_j)

Answer such queries.

Input

The first line contains an integer n~(1 \le n \le 50000) — the length of the sequence.

The second line contains integers a_1, a_2, \ldots, a_n~(|a_i| \le 15007).

The third line contains an integer — the number of queries.

Each of the next lines contains two integers and y~(1 \le x \le y \le n) — the boundaries of a query.

Output

For each query, print the value of Q(x, y) on a separate line.

Examples

Example 1

Loading
Loading