Recently, Soy Ma is taking part in a robot competition. Yesterday, he bought a new kind of programmable robot. He thinks these robots can solve the problem in the maze.
The maze is made up of H × M girds. Each gird is either an empty cell ‘.’ or a wall cell ‘#’. And Soy Ma’s task is to make a program for the robot which can go from START cell ‘S’ to END cell ‘E’ without going into any wall cell.
The robot can receive three kinds of instructions:
1. ’F’: Go forward exactly one cell;
2. ‘L’: Turn left for 90 degrees;
3. ‘R’: Turn right for 90 degrees.
But the competition committee thought it was so easy to solve the problem for such ACMers like Soy Ma and you. Soon they made some additional rules in the competition:
1. The committee will give an standard program for each maze, and the program consists only ‘L’ and ‘R’ instructions;
2. The competitors should only add ‘F’ instructions into the program;
3. The competitors should not change the amount and the order of the ‘L’, ‘R’ instructions.
For example, if the standard program is “LRR”, then the competitor can add ‘F’ instructions in front of ‘L’ to get “FFLRR”, or add after the end of it getting “LRRFFF”, and also “FFLRRF”, “FLFFRFRF”, “LFFFFRRFFF”, etc., but never “RRFL”, “RRF”, “LRFFRR” nor “LLRF”.
Unfortunately, not all standard programs can be adapted to solve the problem for a given maze, and Soy Ma is worrying about that.
So, as a friend of Soy Ma, you want to help him. Now given the maze and the standard program provided by the committee, can you tell Soy Ma whether he can solve the problem?