import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { static void findPaths(int n, int i_start, int j_start, int i_end, int j_end, int i_curr, int j_curr, ArrayList> paths, ArrayList current) { System.out.println("i: " + i_curr + ", j: " + j_curr); // reached the ending coordinate if(i_curr == i_end && j_curr == j_end) { System.out.println("got one"); paths.add(current); return; } // we've gone too far: one of the curr coordinates passes n if(i_curr >= n || j_curr >= n || i_curr < 0 || j_curr < 0) { System.out.println("nope"); return; } ArrayList update = current; // go through the operations update = current; update.add("UL"); System.out.println("0"); findPaths(n, i_start, j_start, i_end, j_end, i_curr - 2, j_curr - 1, paths, update); update = current; update.add("UR"); System.out.println("1"); findPaths(n, i_start, j_start, i_end, j_end, i_curr - 2, j_curr + 1, paths, update); update = current; update.add("R"); System.out.println("2"); findPaths(n, i_start, j_start, i_end, j_end, i_curr, j_curr + 2, paths, update); update = current; update.add("LR"); System.out.println("3"); findPaths(n, i_start, j_start, i_end, j_end, i_curr + 2, j_curr + 1, paths, update); update = current; update.add("LL"); System.out.println("4"); findPaths(n, i_start, j_start, i_end, j_end, i_curr + 2, j_curr - 1, paths, update); update = current; update.add("L"); System.out.println("5"); findPaths(n, i_start, j_start, i_end, j_end, i_curr, j_curr - 2, paths, update); } static ArrayList> findShortest(ArrayList> paths) { int lowest = Integer.MAX_VALUE; for(int i = 0; i < paths.size(); i++) { if(paths.get(i).size() < lowest) lowest = paths.get(i).size(); } ArrayList> fList = new ArrayList>(); for(int i = 0; i < paths.size(); i++) { if(paths.get(i).size() == lowest) fList.add(paths.get(i)); } return fList; } 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. ArrayList> paths = new ArrayList>(); findPaths(n, i_start, j_start, i_end, j_end, i_start, j_start, paths, new ArrayList()); ArrayList> shortest = findShortest(paths); System.out.println(shortest.get(0).size()); for(int i = 0; i < shortest.get(0).size(); i++) { System.out.print(shortest.get(0).get(i) + " "); } } 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(); } }