import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Scanner; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author DELL */ public class RedKnight { static boolean check=false; static void printShortestPath(int n, int i_start, int j_start, int i_end, int j_end, ArrayList al) { if (j_start - j_end == 0 && i_start - i_end == 0) { return; } if (i_start - i_end == 0 && Math.abs(j_start - j_end) == 1) { System.out.println("Impossible"); al.add(-100); return; } if (Math.abs(i_start - i_end) == 0) { if (j_start > j_end) { al.add(5); printShortestPath(n, i_start, j_start - 2, i_end, j_end, al); return; } else { al.add(2); printShortestPath(n, i_start, j_start + 2, i_end, j_end, al); return; } } if (j_start - j_end == 0) { if (i_start > i_end) { if (j_start != 0) { al.add(0); printShortestPath(n, i_start - 2, j_start - 1, i_end, j_end, al); return; } else { check =true; al.add(1); printShortestPath(n, i_start - 2, j_start + 1, i_end, j_end, al); return; } } if (i_start < i_end) { if (j_start != n - 1) { al.add(3); printShortestPath(n, i_start + 2, j_start + 1, i_end, j_end, al); return; } else { check =true; al.add(4); printShortestPath(n, i_start + 2, j_start - 1, i_end, j_end, al); return; } } } if (i_start > i_end && j_start > j_end) { al.add(0); printShortestPath(n, i_start - 2, j_start - 1, i_end, j_end, al); return; } if (i_start > i_end && j_start < j_end) { al.add(1); printShortestPath(n, i_start - 2, j_start + 1, i_end, j_end, al); return; } if (i_start < i_end && j_start > j_end) { al.add(4); printShortestPath(n, i_start + 2, j_start - 1, i_end, j_end, al); return; } if (i_start < i_end && j_start < j_end) { al.add(3); printShortestPath(n, i_start + 2, j_start + 1, i_end, j_end, al); return; } } 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(); if (Math.abs(i_start - i_end) % 2 != 0) { System.out.println("Impossible"); return; } String[] moves = {"UL", "UR", "R", "LR", "LL", "L"}; ArrayList al = new ArrayList(); printShortestPath(n, i_start, j_start, i_end, j_end, al); if(al.contains(-100)){ return; } System.out.println(al.size()); if(!check) Collections.sort(al); for (int i = 0; i < al.size(); i++) { System.out.print(moves[al.get(i)]+" "); } in.close(); } }