Window Manager

No attempts yetTime limit2sMemory limit256 MB

Problem

Touch screens changed how people work with computers. One idea that shows up again and again in touch interfaces is that objects on the display move as if they obeyed physical laws. This problem asks you to implement one example of that.

Write a simulator for the window manager of a phone. The screen is a rectangle that fully contains zero or more rectangular windows. No window crosses a screen boundary and no two windows overlap. The simulator supports four commands.

  • OPEN x y w h: open a new window whose top-left corner is at (x,y)(x, y), with width ww pixels and height hh pixels.
  • CLOSE x y: close the open window that contains the pixel at (x,y)(x, y). A user can tap anywhere on a window to close it.
  • RESIZE x y w h: set the size of the window that contains the pixel at (x,y)(x, y) to width ww and height hh. The top-left corner does not move.
  • MOVE x y dx dy: move the window that contains the pixel at (x,y)(x, y) by dxdx pixels horizontally or by dydy pixels vertically. At most one of dxdx and dydy is non-zero.

OPEN and RESIZE succeed only when the resulting window overlaps no other window and stays inside the screen. MOVE moves the window by as many of the requested pixels as it can. If dxdx is 30 but the window can only travel 15 pixels to the right, it travels 15 pixels.

A moving window can bump into another window. When that happens it pushes the other window in the same direction as far as needed, the way physical objects behave. The effect cascades: a pushed window that meets a further window pushes that one too. Figure 1 shows three windows where window A moves to the right and carries the other two along.

Window A moves right and pushes the other two windows

Figure 1: a MOVE that pushes two windows

Input

The first line contains two positive integers xmaxx_{max} and ymaxy_{max}, the horizontal and vertical size of the screen in pixels. Each is at most 10910^9. The top-left pixel of the screen has coordinates (0,0)(0, 0).

Each of the following lines holds one command as described above. One or more spaces separate the command name and its parameters. The parameters are integers with 0x<xmax0 \le x < x_{max}, 0y<ymax0 \le y < y_{max}, 1w,h1091 \le w, h \le 10^9, and dx,dy109|dx|, |dy| \le 10^9. There are at most 256 commands.

Output

Simulate the commands in the order they appear in the input. Commands are numbered from 1. If an error turns up while a command is simulated, print one line with the command number, the command name, and the first message from the list below that applies, then ignore the result of that command apart from the exception noted for MOVE. The line has this form.

Command N: NAME - message
  • no window at given position, for CLOSE, RESIZE, and MOVE, when no window contains the pixel at the given position.
  • window does not fit, for OPEN and RESIZE, when the resulting window would overlap another window or cross a screen boundary.
  • moved d' instead of d, for MOVE, when the command asked to move a window dd pixels but the window could only move dd' pixels before some window would have to cross a screen boundary. dd and dd' are the absolute numbers of pixels requested and moved. The window still moves in this case, but only the shorter distance.

After every command has been simulated and every error message has been printed, print the number kk of windows that are still open on a line of this form.

k window(s):

Then print one line per open window, in the order the windows were opened, holding the coordinates xx and yy of the top-left corner, the width, and the height, separated by single spaces.