import java.util.ArrayList; import java.util.LinkedList; import java.util.Queue; import java.util.Scanner; class cell { int x, y; ArrayList path; cell() {} cell(int x, int y, ArrayList path) { this.x = x; this.y = y; this.path = path; } } class REDKNIGHTWALK { boolean isInside(int x, int y, int N) { if (x >= 0 && x < N && y >= 0 && y < N) return true; return false; } void printShortestPath(int knightPosx, int knightPosy, int targetPosx, int targetPosy, int N) { int dx[] = {-2, -2, 0, 2, 2, 0}; int dy[] = {-1, 1, 2, 1, -1, -2}; ArrayList path = new ArrayList(); Queue q = new LinkedList(); path.add(-1); // push starting position of knight with 0 distance q.add(new cell(knightPosx, knightPosy, path)); cell t; int x, y; boolean visit[][] = new boolean[N][N]; for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) visit[i][j] = false; visit[knightPosx][knightPosy] = true; while(!q.isEmpty()) { t = q.poll(); visit[t.x][t.y] = true; path = t.path; if (t.x == targetPosx && t.y == targetPosy) { System.out.println((t.path.size() - 1)); for(int i = 0;i < t.path.size();i++) { int node = t.path.get(i); if(node == 5) {System.out.print("L ");} else if(node == 0) {System.out.print("UL ");} else if(node == 1) {System.out.print("UR ");} else if(node == 2) {System.out.print("R ");} else if(node == 3) {System.out.print("LR ");} else if(node == 4) {System.out.print("LL ");} } return; } for (int i = 0; i < 6; i++) { x = t.x + dx[i]; y = t.y + dy[i]; if (isInside(x, y, N))// && { path.add(i); ArrayList newpath = new ArrayList(); newpath.addAll(path); if(!visit[x][y]) q.add(new cell(x, y, newpath)); path.remove(path.size() - 1); } } } System.out.println("Impossible");; } } public class Solution { 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(); REDKNIGHTWALK walk = new REDKNIGHTWALK(); walk.printShortestPath(i_start, j_start, i_end, j_end, n); in.close(); } }