Harold is, like the rest of his coworkers, working hard to ensure all records are "accurate". To do this they must change some labels here and there, but more importantly, change the time that certain events occurred… in the database.
Unfortunately for you, many students are looking up "information" for their projects at the same time, and all the queries are grouped together. You wouldn't want to keep them waiting.
The timeline begins with
T a b
- find the event which occurred at time and change it so it occurred at time .L a b
- find the event which occurred at time and change its label to .F s v
- change the filter. Ifs
is<
, allow only events with labels below to pass, ifs
is>
, allow only events with labels above to pass, and ifs
is.
, reset the filter to none and ignore .S v
- find the event which occurred at time closest to and passing the filter. If there is a tie, choose the later one. Output this event's time.
Constraints
For all subtasks:
Subtask 1 [30%]
Subtask 2 [70%]
Input Specification
The first line will contain
The next
The following line will contain
The next
Output Specification
The result of each query, one per line.
Sample Input
5
-2 1
0 4
3 -1
4 3
7 4
13
S -1
F > 3
S -4
S 4
T 7 9
S 4
F < -2
L 9 -3
S -3
F . 0
S 2
T 3 -3
S -3
Sample Output
0
0
7
0
9
3
-3
Explanation
The closest event to
The filter is set to
The closest event to
The closest event to
The time of event
The closest event to
The filter is set to
The label of event
The closest event to
The filter is cleared.
The closest event to
The time of event
The closest event to
Comments
If there are no events that pass the filter what should be printed? (I'm guessing -1 since that worked?)