Maximum#4473

Maximum

1 second
128 megabytes
Easy

Your task is very simple: you just need to find the maximum value in a given range.

Input

The first line contains an integer n~(1 \le n \le 10^5) — the number of elements in the array.

The second line contains integers a_1, a_2, \ldots, a_n~(-10^9 \le a_i \le 10^9) — the elements of the array.

The third line contains an integer q~(1 \le q \le 5 \cdot 10^5) — the number of queries.

Each of the next lines contains two positive integers and r~(1 \le l, r \le n), representing the endpoints of a range. For each query, you must find the maximum value in the subarray from position to position , inclusive.

Output

For each query, print the maximum value in the corresponding range.

Examples

Example 1

Loading
Loading