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 i_start, int j_start, int i_end, int j_end) { // Print the distance along with the sequence of moves. Path start = new Path(null, null, i_start, j_start, n); Path end = null; List currentPositions = new ArrayList<>(); currentPositions.add(start); while (!currentPositions.isEmpty() && end == null) { Path path = currentPositions.remove(0); if (path.currentI > i_end && path.currentJ >= j_end && path.canMove("UL")) { currentPositions.add(path.next("UL")); } if (path.currentI > i_end && path.currentJ <= j_end && path.canMove("UR")) { currentPositions.add(path.next("UR")); } if (path.currentI == i_end && path.currentJ < j_end && path.canMove("R")) { currentPositions.add(path.next("R")); } if (path.currentI < i_end && path.currentJ <= j_end && path.canMove("LR")) { currentPositions.add(path.next("LR")); } if (path.currentI < i_end && path.currentJ >= j_end && path.canMove("LL")) { currentPositions.add(path.next("LL")); } if (path.currentI == i_end && path.currentJ > j_end && path.canMove("L")) { currentPositions.add(path.next("L")); } end = destiny(currentPositions, i_end, j_end); } if (currentPositions.isEmpty() && end == null) { System.out.println("Impossible"); return; } Result result = new Result(); fillResult(end, result); System.out.println(result.steps); System.out.println(result.moves.trim()); } private static void fillResult(Path end, Result result) { if (end.parent != null) { fillResult(end.parent, result); result.steps++; result.moves = result.moves + " " + end.move; } } private static Path destiny(List currentPositions, int i_end, int j_end) { for (Path path : currentPositions) { if (path.currentI == i_end && path.currentJ == j_end) return path; } return null; } static class Result { int steps; String moves = ""; } static class Path { Path parent; String move; int currentI, currentJ, limit; Path(Path parent, String move, int i, int j, int n) { this.parent = parent; this.move = move; currentI = i; currentJ = j; limit = n; } public Path next(String command) { int nextI = nextI(command); int nextJ = nextJ(command); return new Path(this, command, nextI, nextJ, limit); } public boolean atDestiny(int i, int j) { return currentI == i && currentJ == j; } public boolean canMove(String command) { int nextI = nextI(command); int nextJ = nextJ(command); if (nextI < 0 || nextI >= limit || nextJ < 0 || nextJ >= limit) { return false; } Path parentPath = parent; while (parentPath != null) { if (nextI == parentPath.currentI && nextJ == parentPath.currentJ) return false; parentPath = parentPath.parent; } return true; } private int nextJ(String command) { switch (command) { case "UL": return currentJ - 1; case "UR": return currentJ + 1; case "R": return currentJ + 2; case "LR": return currentJ + 1; case "LL": return currentJ - 1; case "L": return currentJ - 2; } return -1; } private int nextI(String command) { switch (command) { case "UL": return currentI - 2; case "UR": return currentI - 2; case "R": return currentI; case "LR": return currentI + 2; case "LL": return currentI + 2; case "L": return currentI; } return -1; } } 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(); } }