Seats in a new tram operating in Zagreb are organized into a grid consisting of $N$ rows numbered $1$ through $N$ and two columns numbered $1$ and $2$. The distance between two seats, one at row $R_A$, column $C_A$ and other at row $R_B$, column $C_B$ is the Euclidean distance between the centers of the corresponding grid squares – namely $\sqrt{(𝑅_𝐴 −𝑅_𝐵)^2 + (𝐶_𝐴−𝐶_𝐵)^2}$.
Most passengers prefer solitude when using public transportation and they always try to choose a seat that is as far away from other passengers as possible. More precisely, when a passenger enters the tram he or she will choose a free seat whose distance from the closest occupied seat is the highest possible. If there is more than one such seat, they will always choose one with the lower row number and if there is still more than one such seat, they will choose the one with the lower column number. After the passenger chooses a seat, he or she will sit there until leaving the tram. If the tram is empty, the next passenger to enter will always choose the seat in row 1 and column 1.
TASK
Write a program that will, given a sequence of events, each event either a passenger entering or leaving the tram, determine where each of the passengers was sitting. The tram is initially empty.
There are $M$ events in the input numbered $1$ through $M$ in the order in which they occurred. There are two kinds of events: event of type 'E' corresponds to a passenger entering the tram, while the event of type 'L' corresponds to a passenger leaving the tram. For an event of type 'L', an integer $P$ is also given – it specifies that the passenger leaving in this event is the one that entered at event $P$.
Test data will be such that there will always be at least one free seat in the tram whenever a passenger is trying to enter.