On Storing Clothes

No attempts yetTime limit1sMemory limit1024 MB

Problem

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 NN hooks whose indices are taken modulo NN. To store a batch of nn garments, the operator types nn. Starting from the hook currently in front of the mark and scanning to the right (increasing indices, modulo NN), the computer finds the first block of n+2n+2 usable hooks k,k+1,,k+n+1k, k+1, \dots, k+n+1. Hook kk and hook k+n+1k+n+1 become separators and are not used for garments; the nn garments are hung on hooks k+1,,k+nk+1, \dots, k+n. The rail then turns so that hook k+n+1k+n+1 comes in front of the mark, and the operator hands the customer ticket number kk. 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 nn middle hooks, however, must be empty.

When the customer returns with ticket kk, the operator types kk; the rail turns so that separator hook kk 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 00 is in front of the mark. Only garments that have been deposited can be withdrawn.

Input

The first line contains the number of hooks NN (1N3001 \le N \le 300). The second line contains the number ll of command lines that follow. Each of the next ll lines has one of the two forms:

D n

deposit a batch of nn garments, or

W k

withdraw the batch with ticket kk (0k<N0 \le k < N).

Output

For each command, print the corresponding messages.

On a deposit, if no block of n+2n+2 suitable hooks exists, print

No space left, please come back later.

otherwise, when ticket kk is issued, print

The launderer gives ticket k.

On a withdrawal of ticket kk, print

The launderer gives back batch k.

and free every hook of that batch. Whenever hooks h,,h+qh, \dots, h+q become free (a contiguous block, indices modulo NN), print

i is freed.

for each ii from hh to h+qh+q in order.