cho.sh
Notes
Loading...

Robot Simulation

Time limit

2s

Memory limit

128 MB

Problem

There is a rectangular field with width A and height B. Both A and B are between 1 and 100 inclusive. There are N robots on the field, where N is between 1 and 100 inclusive.

Each robot's position is represented by an x-coordinate and a y-coordinate. The x-coordinate increases from left to right, and the y-coordinate increases from bottom to top. Each robot initially faces one of N, W, E, and S, and all initial positions are distinct.

You will give M commands to the robots in order, where M is between 1 and 100 inclusive. A command must finish completely before the next command begins. Each command is one of the following three types.

  1. L: turn the robot 90 degrees to the left from its current direction.
  2. R: turn the robot 90 degrees to the right from its current direction.
  3. F: move the robot forward by one cell in its current direction.

Before executing the commands for real, you want to simulate them and check whether something goes wrong. There are two possible failure cases.

  1. Robot X crashes into the wall: robot X leaves the field and crashes into the wall.
  2. Robot X crashes into robot Y: robot X moves into the cell occupied by robot Y.

Input

The first line contains two integers A and B. The next line contains two integers N and M.

Each of the following N lines gives one robot's initial position and direction in the form x y d. Robots are numbered from 1 to N in input order.

Each of the following M lines gives one command in execution order. A command has the form robot command repeat, where robot is the number of the robot receiving the command, command is one of L, R, and F, and repeat is the number of times to repeat the command. The repeat count is between 1 and 100 inclusive.

Output

Print the simulation result on one line. If every command can be executed without a problem, print OK.

If a collision occurs, print only the first collision. For a wall collision, print Robot X crashes into the wall. For a collision with another robot, print Robot X crashes into robot Y.