0210. Driving Straight

Input file name: straight.in
Output file name: straight.out
Time limit: 2 s
Memory limit: 64 megabytes

The city where Peter lives has the form of the rectangle with M streets running from east to west and N streets running from north to south. Recently, because of preparations for the celebration of the city's 3141-st birthday, some street sectors has been closed for driving.

Peter lives in the house next to point (1, 1) and works next to the point (N, M). He always drives from home to work by his car using the shortest possible path. Of course, he can't drive through closed sectors. Since there can be many shortest pathes between his house and his work, he may choose any.

But Peter doesn't like to turn (he is an inexperienced driver), so he wants to choose the path using the following algorithm: starting from the point (1, 1) he drives either northwards, or eastwards (wherever there is the shortest path available, if there are both, he may choose any). Whenever he comes to the junction he must decide where to go. If there is only one direction he can drive to stay on the shortest path, he must choose that direction. In the other case he would like to choose the direction giving priority to driving forward, that is, if he can drive forward and still stay on some shortest path, he would go forward. If he can't drive forward to stay on the shortest path, he would choose any available direction.

Help Peter to create the path from his house to his work using the rules described.

Input file

The first line of the input file contains integer numbers M and N (2 ≤ M, N ≤ 400).

Next 2M-1 lines contain 2N-1 characters each, representing the city map. House blocks are marked with spaces, junctions with `+', open sectors with `-' and '|', closed sectors with spaces. Peter's house is at the lower-left corner of the map, his work is at the upper-right corner.

Output file

On the first line of the output file print the direction Peter should choose first, `N' or `E'. On the second line output the sequence of latin letters `F', `L' and `R' representing Peter's behaivour on junctions – go forward, turn left or right respectively. If there are several paths Peter can choose from, output any. You must output Peter's action on the junction even if he has no choice due to closed streets. It is guaranteed that there will always be the way for Peter to get from home to work.

Examples:

straight.instraight.out
4 4 +-+ +-+ | | | + +-+-+ | | +-+-+-+ | | +-+-+-+ N RFLRL


Source: Petrozavodsk Winter 2004. Andrew Stankevich Contest 4, Friday, January 30
Author: Andrew Stankevich

Discuss       Submit a solution



Printable version