import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; class Point { boolean visit; int x; int y; Point parent; String direction; public Point(int x, int y) { this.x = x; this.y = y; this.visit = false; this.parent = null; this.direction = ""; } } public class Solution { 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. Point[][] board = new Point[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { board[i][j] = new Point(i, j); } } Point start = board[j_start][i_start]; Point end = board[j_end][i_end]; if (start == end) { System.out.println(0); return; } Queue queue = new LinkedList(); queue.add(start); start.visit = true; while (!queue.isEmpty()) { Point current = queue.remove(); Point next = getNext(current, board); while (next != null) { next.visit = true; next.parent = current; queue.add(next); if (next == end) { int count = countPath(next); System.out.println(count); String[] array = printPath(next, count); for (int i = array.length - 1; i >= 0; i--) { System.out.print(array[i] + " "); } return; } next = getNext(current, board); } } System.out.println("Impossible"); } public static String[] printPath(Point point, int count) { Point temp = point; String[] retval = new String[count]; int index = 0; while (temp.parent != null) { retval[index] = temp.direction; index++; temp = temp.parent; } return retval; } public static int countPath(Point point) { Point temp = point; int retval = 0; while (temp.parent != null) { retval++; temp = temp.parent; } return retval; } public static Point goUpperLeft(Point point, Point[][] board) { if (point.x <= 0 || point.y < 2) { return null; } return board[point.x - 1][point.y - 2]; } public static Point goUpperRight(Point point, Point[][] board) { if (point.x >= board.length - 1 || point.y < 2) { return null; } return board[point.x + 1][point.y - 2]; } public static Point Right(Point point, Point[][] board) { if (point.x >= board.length - 2) { return null; } return board[point.x + 2][point.y]; } public static Point goLowerLeft(Point point, Point[][] board) { if (point.x <= 0 || point.y >= board.length - 2) { return null; } return board[point.x - 1][point.y + 2]; } public static Point goLowerRight(Point point, Point[][] board) { if (point.x >= board.length - 1 || point.y >= board.length - 2) { return null; } return board[point.x + 1][point.y + 2]; } public static Point Left(Point point, Point[][] board) { if (point.x <= 1) { return null; } return board[point.x - 2][point.y]; } public static Point getNext(Point point, Point[][] board) { Point retval = goUpperLeft(point, board); if (retval != null && !retval.visit) { retval.direction = "UL"; return retval; } retval = goUpperRight(point, board); if (retval != null && !retval.visit) { retval.direction = "UR"; return retval; } retval = Right(point, board); if (retval != null && !retval.visit) { retval.direction = "R"; return retval; } retval = goLowerRight(point, board); if (retval != null && !retval.visit) { retval.direction = "LR"; return retval; } retval = goLowerLeft(point, board); if (retval != null && !retval.visit) { retval.direction = "LL"; return retval; } retval = Left(point, board); if (retval != null && !retval.visit) { retval.direction = "L"; return retval; } return null; } 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(); } }