import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Solution { static int ini_start_i; static int ini_start_j; static void printShortestPath( int n, int i_start, int j_start, int i_end, int j_end ) { // Print the distance along with the sequence of moves. UL, UR, R, LR, LL, L ini_start_i = i_start; ini_start_j = j_start; DistanceAndPath distanceAndPath = findShortestPath( n, i_start, j_start, i_end, j_end, new String( "" ), 0, "ALL", "ALL" ); if ( distanceAndPath.distance == Integer.MAX_VALUE ) { System.out.println( "Impossible" ); } else { System.out.println( distanceAndPath.distance ); System.out.println( distanceAndPath.path.trim() ); } } private static DistanceAndPath findShortestPath( final int n, final int i_start, final int j_start, final int i_end, final int j_end, final String path, int distance, final String directionV, final String directionH ) { if ( i_start < 0 || j_start < 0 || i_start >= n || j_start >= n ) { return new DistanceAndPath( Integer.MAX_VALUE, "" ); } if ( i_start == i_end && j_start == j_end ) { return new DistanceAndPath( distance, path ); } List distanceAndPaths = new ArrayList<>(); if ( directionV.equals( "UL" ) || directionV.equals( "UR" ) || directionV.equals( "ALL" ) ) { distanceAndPaths.add( findShortestPath( n, i_start - 2, j_start - 1, i_end, j_end, path + " UL", distance + 1, "UL", directionH ) ); distanceAndPaths.add( findShortestPath( n, i_start - 2, j_start + 1, i_end, j_end, path + " UR", distance + 1, "UR", directionH ) ); } if ( directionH.equals( "R" ) || directionH.equals( "ALL" ) ) { distanceAndPaths.add( findShortestPath( n, i_start, j_start + 2, i_end, j_end, path + " R", distance + 1, directionV, "R" ) ); } if ( directionH.equals( "LR" ) || directionV.equals( "LL" ) || directionH.equals( "ALL" ) ) { distanceAndPaths.add( findShortestPath( n, i_start + 2, j_start + 1, i_end, j_end, path + " LR", distance + 1, "LR", directionH ) ); distanceAndPaths.add( findShortestPath( n, i_start + 2, j_start - 1, i_end, j_end, path + " LL", distance + 1, "LL", directionH ) ); } if ( directionH.equals( "L" ) || directionH.equals( "ALL" ) ) { distanceAndPaths.add( findShortestPath( n, i_start, j_start - 2, i_end, j_end, path + " L", distance + 1, directionV, "L" ) ); } return min( distanceAndPaths ); } private static DistanceAndPath min( final List distanceAndPaths ) { DistanceAndPath min = new DistanceAndPath( Integer.MAX_VALUE, "" ); for ( DistanceAndPath distanceAndPath : distanceAndPaths ) { if ( min.distance > distanceAndPath.distance ) min = distanceAndPath; } return min; } public static void main( String[] args ) { Scanner in = new Scanner( System.in ); int n = in.nextInt(); int i_start = in.nextInt(); int j_start = in.nextInt(); int i_end = in.nextInt(); int j_end = in.nextInt(); printShortestPath( n, i_start, j_start, i_end, j_end ); in.close(); } } class DistanceAndPath { int distance; String path; public DistanceAndPath( final int distance, final String path ) { this.distance = distance; this.path = path; } }