import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { static void printShortestPath(int n, int iStart, int jStart, int iEnd, int jEnd) { // Print the distance along with the sequence of moves. int minNoOfMoves = 0; List moveSequence = new ArrayList<>(); int distanceToEnd = Math.abs(iStart - iEnd) + Math.abs(jStart - jEnd); int currentRow = iStart; int currentColumn = jStart; while(!hasReachedDestination(currentRow, currentColumn, iEnd, jEnd) && !hasReachedAdjacentToDestinationCell(currentRow, currentColumn, iEnd, jEnd)) { int potentialNewDistanceToEnd = distanceToEnd; String potentialMoveSequence = ""; int potentialCurrentRow = 0; int potentialCurrentColumn = 0; // Upper Left int upperLeftRow = currentRow - 2; int upperLeftColumn = currentColumn-1; if(upperLeftRow >= 0 && upperLeftRow < n && upperLeftColumn >= 0 && upperLeftColumn < n) { int newDistanceToEnd = Math.abs(upperLeftRow - iEnd) + Math.abs(upperLeftColumn - jEnd); if(newDistanceToEnd < potentialNewDistanceToEnd) { potentialNewDistanceToEnd = newDistanceToEnd; potentialMoveSequence = "UL"; potentialCurrentRow = upperLeftRow; potentialCurrentColumn = upperLeftColumn; } } // Upper Right int upperRightRow = currentRow - 2; int upperRightColumn = currentColumn + 1; if(upperRightRow >= 0 && upperRightRow < n && upperRightColumn >= 0 && upperRightColumn < n) { int newDistanceToEnd = Math.abs(upperRightRow - iEnd) + Math.abs(upperRightColumn - jEnd); if(newDistanceToEnd < potentialNewDistanceToEnd) { potentialNewDistanceToEnd = newDistanceToEnd; potentialMoveSequence = "UR"; potentialCurrentRow = upperRightRow; potentialCurrentColumn = upperRightColumn; } } // Right int rightRow = currentRow; int rightColumn = currentColumn + 2; if(rightRow >= 0 && rightRow < n && rightColumn >= 0 && rightColumn < n) { int newDistanceToEnd = Math.abs(rightRow - iEnd) + Math.abs(rightColumn - jEnd); if(newDistanceToEnd < potentialNewDistanceToEnd) { potentialNewDistanceToEnd = newDistanceToEnd; potentialMoveSequence = "R"; potentialCurrentRow = rightRow; potentialCurrentColumn = rightColumn; } } // Lower Right int lowerRightRow = currentRow + 2; int lowerRightColumn = currentColumn + 1; if(lowerRightRow >= 0 && lowerRightRow < n && lowerRightColumn >= 0 && lowerRightColumn < n) { int newDistanceToEnd = Math.abs(lowerRightRow - iEnd) + Math.abs((lowerRightColumn - jEnd)); if(newDistanceToEnd < potentialNewDistanceToEnd) { potentialNewDistanceToEnd = newDistanceToEnd; potentialMoveSequence = "LR"; potentialCurrentRow = lowerRightRow; potentialCurrentColumn = lowerRightColumn; } } // Lower Left int lowerLeftRow = currentRow + 2; int lowerLeftColumn = currentColumn-1; if(lowerLeftRow >= 0 && lowerLeftRow < n && lowerLeftColumn >= 0 && lowerLeftColumn < n) { int newDistanceToEnd = Math.abs(lowerLeftRow - iEnd) + Math.abs((lowerLeftColumn - jEnd)); if(newDistanceToEnd < potentialNewDistanceToEnd) { potentialNewDistanceToEnd = newDistanceToEnd; potentialMoveSequence = "LL"; potentialCurrentRow = lowerLeftRow; potentialCurrentColumn = lowerLeftColumn; } } // Left int leftRow = currentRow; int leftColumn = currentColumn - 2; if(leftRow >= 0 && leftRow < n && leftColumn >= 0 && leftColumn < n) { int newDistanceToEnd = Math.abs(leftRow - iEnd) + Math.abs(leftColumn-jEnd); if(newDistanceToEnd < potentialNewDistanceToEnd) { potentialNewDistanceToEnd = newDistanceToEnd; potentialMoveSequence = "L"; potentialCurrentRow = leftRow; potentialCurrentColumn = leftColumn; } } if(!potentialMoveSequence.isEmpty()) { moveSequence.add(potentialMoveSequence); minNoOfMoves++; distanceToEnd = potentialNewDistanceToEnd; currentRow = potentialCurrentRow; currentColumn = potentialCurrentColumn; } } if(distanceToEnd != 0) { System.out.println("Impossible"); } else { System.out.println(minNoOfMoves); for(String s : moveSequence) { System.out.print(s + " "); } } } private static boolean hasReachedDestination(int currentRow, int currentColumn, int endRow, int endColumn) { return currentRow == endRow && currentColumn == endColumn; } private static boolean hasReachedAdjacentToDestinationCell(int currentRow, int currentColumn, int endRow, int endColumn) { if(currentColumn == endColumn && Math.abs(currentRow - endRow) == 1) { return true; } if(currentRow == endRow && Math.abs(currentColumn - endColumn) == 1) { return true; } if(Math.abs(currentColumn - endColumn) == 1 && Math.abs(currentRow - endRow) == 1) { return true; } return false; } 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(); } }