There's a robot in an N×M grid, where some unit squares are blocked so that the robot cannot walk on the square. Now she wants to move to another square, and have asked her owner to program her to do this. This owner happen to be you.
To transfer the programming to a robot from your computer requires a lot of energy, so you want to make the program as short as possible - this means using as few commands as possible. As everyone knows, the robot programming language looks as follows:
forward Move the robot forward a single step in its current direction.right Rotate 90deg clockwise.left Rotate 90deg counterclockwise.for X { A1 A2 ... An } Repeat the commands A1, A2, ..., An X times.call X Jump to the instruction with label X, and add it to the current position in the call stack.return Jump to the last added position in the call stack, and remove it.gotoblocked X Jump to the instruction with label X, if the square in front of the robot is blocked.A label has the syntax labelnamn:, and may only consist of small letters. A label cannot be inside a loop. The execution starts at the label called main.
Input consists of 10 different grids, which you can download here: robot.zip. Each grid is formatted as follows:
The first line contains the testcase name.
The next line contains two integers 1≤R≤1000 and 1≤C≤1000, the number of rows and columns in the grid.
Each square is one of:
. free square# blocked squareM goal square<>^v start square, indicating the direction of the robot (in the order left, right, up, down).It should consist of a program on the form described above, that moves the robot from its starting position to the end position.