The parking lot in the center of the capital has N parking spaces. You are asked to develop a program to write the parking log of the lot. The program is required to record such two operations which may happen in the lot:
A: A motorcade with Mi cars applies for Mi parking spaces in a row, namely, continuous spaces [Si,Si+Mi-1]. A special constraint is that the number of free spaces between the coming motorcade and the last car parking before Si, should not be larger than Li. Note that, this constraint has no effect if there is no car before Si. What's more, the number of free spaces between the coming motorcade and the first car parking after Si+Mi-1 should not be larger than Ri. Also, you should ignore this constraint when Si+Mi-1 is last occupied space. The space with the smallest Si is selected when there are several candidate start places. The motorcade will leave if there are no spaces satisfying the conditions. After one motorcade is parked, its parking limits Li and Ri can be ignored when finding parking places for later coming motorcades. Your task is to find the Si, and return it as result.
B. The k-th motorcade counted from left to right leaves the lot. Ignore this operation if there are no more than k motorcades in the parking lot.
In the very beginning, the spaces in the lot are all free.