import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static class Coord { int row; int col; int move; public Coord(int row, int col, int move){ this.row = row; this.col = col; this.move = move; } } // prints the length of the shortest path as well as the actual path static void printShortestPath(int n, int i_start, int j_start, int i_end, int j_end) { int[][] moves = {{-1, -2}, {1, -2}, {2, 0}, {1, 2}, {-1, 2}, {-2, 0}}; String[] directions = {"UL", "UR", "R", "LR", "LL", "L"}; int[][] board = new int[n][n]; String[][] paths = new String[n][n]; Queue q = new LinkedList(); Coord start = new Coord(i_start, j_start, 1); q.add(start); board[start.row][start.col] = start.move; while(!q.isEmpty()){ Coord curr = q.remove(); for(int i = 0; i < moves.length; i++){ int col = curr.col + moves[i][0]; int row = curr.row + moves[i][1]; if(row >= 0 && row < n && col >= 0 && col < n && board[row][col] == 0) { board[row][col] = curr.move + 1; paths[row][col] = directions[i]; q.add(new Coord(row, col, curr.move + 1)); } } } if(board[i_end][j_end] != 0) { System.out.println(board[i_end][j_end] - 1); String[] path = retracePath(board[i_end][j_end] - 1, i_end, j_end, paths); for(String s : path) System.out.print(s + " "); } else System.out.println("Impossible"); } // return the best path public static String[] retracePath(int len, int row, int col, String[][] paths){ int[][] moves = {{1, 2}, {-1, 2}, {-2, 0}, {-1, -2}, {1, -2}, {2, 0}}; HashMap priority = new HashMap() {{ put("UL", 0); put("UR", 1); put("R", 2); put("LR", 3); put("LL", 4); put("L", 5);}}; String[] path = new String[len]; for(int i = len - 1; i >= 0; i--){ path[i] = paths[row][col]; int prev = priority.get(path[i]); row = row + moves[prev][1]; col = col + moves[prev][0]; } return path; } 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(); } }