There are modern washbasins numbered from to from left to right in the ladies' room of an enormous shopping centre.
Currently, there are ladies in the restroom (numbered from to ) and they've occupied the washbasins with numbers . Soon there will be more ladies arriving (numbered from to in the order of arrival) that will occupy all the remaining available washbasins. The ladies arriving primarily want their privacy, so each of them always chooses an available washbasin by the following procedure:
- First she finds the largest consecutive series of available washbasins. If there is more than one, she chooses the leftmost.
- After that, she occupies the middle washbasin in the chosen series. If the series is of even length, she chooses the left of the two middle washbasins.
It is safe to assume that none of the ladies will leave the washbasin in the foreseeable future.
Write a programme that will, for each of given integers , determine the label of the washbasin that will be occupied by the lady marked with .
Input Specification
The first line of input contains integers , , and – the number of washbasins, the initial number of ladies in the restroom and the number of ladies for which you need to determine which washbasin they will use.
The second line of input contains space-separated integers, the of those numbers is – the label of the washbasin that is being used by lady .
The third line of input contains space-separated integers, the of those numbers is – the label of the lady for which we want to know which washbasin she will use.
The first ladies in the restroom haven't necessarily chosen their washbasins using the procedure described in the task.
The arrays and are strictly increasing. In other words, it holds and .
Output Specification
Output lines. The line must contain the label of the washbasin that will be used by the lady labeled .
Please note: We recommend that you use a -bit integer data type (int64
in Pascal, long long
in C/C++).
Constraints
For all subtasks:
Subtask | Score | Constraints |
---|---|---|
, | ||
Sample Input 1
7 1 4
4
2 3 4 5
Sample Output 1
2
6
1
3
Sample Input 2
10 2 4
2 8
1 3 5 8
Sample Output 2
2
5
6
4
Explanation for Sample Output 2
The first two ladies occupy the washbasins and (respectively).
The remaining ladies occupy the washbasins , , , , , , , and , respectively.
Comments