Problem
You are given an ordered array A of n natural numbers.
There are q requests to be processed. Each query is given two parameters - its type t
i and the number k
i.
Description of queries by their type:
1) Find in A the minimum number that is not less than k
i.
2) Find the minimum number in A that is strictly greater than k
i.
3) Find in A the maximum number that is not greater than k
i.
4) Find the maximum number in A that is strictly less than k
i.
For each query, report the number found, or -1 if none exists.
Input:
The first line contains number n (1 <= n <= 10
5) - the number of elements of array A.
The second line contains n natural numbers A
i (1 <= A
i <= 10
9) - the array elements themselves. Moreover, for all i < n done A
i <= A
i+1.
The third line contains the number q (1 <= q <= 10
5) - the number of requests.
The next q lines contain two numbers each - t
i (1 <= t
i <= 4) and k
i (1 < ;= k
i <= 10
9).
Output:
Print q lines, i-th one number - the answer to the i-th query.
Examples:
Input |
Output |
4
3 5 5 7
4
15
27
3 2
4 4 |
5
-1
-1
3 |