In preparation for Christmas and a brand new year, your school is planning to host a fire drill to review the safety protocols in place.
You have decided to analyze the efficiency of the procedure by observing a particular hallway in the school. The hallway can be represented as a number line that is
To ensure the drill goes smoothly, write a program that supports
1 x
: What is the position of the closest reachable exit from the class at position ? If there are multiple equidistant exits, output the one with the lowest .2 x
: If the nearest exit to the class located at becomes too crowded, how many other valid exits can the class choose to take?
Constraints
For this problem, you will NOT be required to pass the sample cases in order to receive points. In addition, all subtasks are disjoint, and you are NOT required to pass previous subtasks to earn points for a specific subtask.
For all queries,
Subtask 1 [15%]
Subtask 2 [20%]
There are only type 1
queries.
Subtask 3 [20%]
There are only type 2
queries.
Subtask 4 [45%]
No additional constraints.
Input Specification
The first line contains two space-separated integers,
The next
The next line contains a single integer,
The next
Output Specification
For each query, output the answer on a new line.
Sample Input
9 3
5 2
6 1
8 0
3
1 4
1 3
2 4
Sample Output
5
1
2
Explanation of Sample
Query 1: The closest exit from the classroom at 4 is at location 5.
Query 2: From location 3, the front entrance and the exit at location 5 are both a distance of 2 away, but we output 1 because it has a lower
Query 3: The exits accessible from location 4 are at locations 1, 5 and 9. Since the closest exit at location 5 becomes too crowded, we are left with 2 exits remaining.
Comments