In a laundry, clothes are hung on coat hangers placed on hooks that are fixed to a circular rail rotated electrically by a computer. The hooks are numbered so that any garment is easy to find, and the rail turns to bring a chosen hook in front of a fixed mark.
Model the rail as a circular array of N hooks whose indices are taken modulo N. To store a batch of n garments, the operator types n. Starting from the hook currently in front of the mark and scanning to the right (increasing indices, modulo N), the computer finds the first block of n+2 usable hooks k,k+1,…,k+n+1. Hook k and hook k+n+1 become separators and are not used for garments; the n garments are hung on hooks k+1,…,k+n. The rail then turns so that hook k+n+1 comes in front of the mark, and the operator hands the customer ticket number k. Hooks holding a customer's garments stay assigned to that customer, even while the garments are being cleaned.
A separator may be shared: the block's two end hooks may reuse hooks that are already separators. The n middle hooks, however, must be empty.
When the customer returns with ticket k, the operator types k; the rail turns so that separator hook k of that batch is in front of the mark (the rail does not move while the batch is handed back). Every hook that held one of that batch's garments becomes free. A separator hook of the removed batch also becomes free if both of its neighbors are free. (As the note goes: once both neighbors of a separator are empty, that separator may be reused for any purpose.)
At the start the rail is empty and hook 0 is in front of the mark. Only garments that have been deposited can be withdrawn.
The first line contains the number of hooks N (1≤N≤300). The second line contains the number l of command lines that follow. Each of the next l lines has one of the two forms:
D n
deposit a batch of n garments, or
W k
withdraw the batch with ticket k (0≤k<N).
For each command, print the corresponding messages.
On a deposit, if no block of n+2 suitable hooks exists, print
No space left, please come back later.
otherwise, when ticket k is issued, print
The launderer gives ticket k.
On a withdrawal of ticket k, print
The launderer gives back batch k.
and free every hook of that batch. Whenever hooks h,…,h+q become free (a contiguous block, indices modulo N), print
i is freed.
for each i from h to h+q in order.