Sruti is a forgetful student. She forgets almost everything that she sees in her day-to-day life. To improve her memory, she has decided to take part in a memory competition. In this competition, she will be provided a list containing N
integers sorted in ascending order. She has to remember this list.
Later, she will be asked Q
number of queries. In each query, she will be provided with a number. She has to answer the index of that number in that list.
However, she has opted for high difficulty level. So, after deliberating for a few minutes, the judges introduced one additional step for her. She may receive any number which may or may not be present in the list.
In case the number is present, she has to print YES
and the index of the number, separated by a single white-space.
In case the number is absent, she has to print NO
and the index where the element should have been present in the list so that the list was still sorted in ascending order.
Input Format
The first line contains a single integer, N, denoting the size of the list. The second line will contain N space separated integers, arr[0]
, arr[1]
, ... arr[N-1]
. The third line will contain a single integer, Q
, denoting the number of queries to be made. Then, Q
lines will follow, each having a single integer, R
, as the query.
Output Format
There shall be Q
lines in total. For each query, if the element is present, print YES
and then the index of the element, separated by a single white-space. If the element is absent, print NO
and then the index where the element should have been present in the list so that the list was still sorted in ascending order.
Note: All indexes are 0-indexed
Constraints
\( 1 \le N \le 10^7 \)
\( -10^7 \le arr[i] \le 10^7\)
\(1 \le Q \le 10^6 \)
\(-10^7 \le R \le 10^7\)
For the sample, there are 5
numbers in the list and 5
queries. For the first query, 0
is entered, which is absent in the list. If it were to be present, it should have been present in the first position with index 0. So, NO 0
is printed.
Next, 6
is entered, which is absent. So, once again, if it were to be present, it should have been present at the last position with index 5
. Hence, NO 5
is printed.
The next 3
queries are all present. Thus, YES
and their corresponding indices are printed.