import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { private static Cell end; static boolean[][] checked ; private static int MAX_INDEX ; private static final int UL = 1; private static final int UR = 2; private static final int R = 3; private static final int LR = 4; private static final int LL = 5; private static final int L = 6; static class Cell{ int i; int j; int weight; public Cell(int i , int j , int weight){ this.i = i; this.j = j; this.weight = weight; } public int distance() { //how far is this cell from destination. int noOfColumn = Math.abs(end.j -j); int noOfRow = Math.abs(end.i -i); return noOfColumn +noOfRow; } public Cell getUR(){ int row = i -2; int col = j +1; if((row >= 0 && row <= MAX_INDEX) &&(col >= 0 && col <= MAX_INDEX) ) return new Cell(row , col , UR); else return null; } public Cell getUL(){ int row = i -2; int col = j -1; if((row >= 0 && row <= MAX_INDEX) &&(col >= 0 && col <= MAX_INDEX) ) return new Cell(row , col , UL); else return null; } public Cell getR(){ int row = i; int col = j +2; if((row >= 0 && row <= MAX_INDEX) &&(col >= 0 && col <= MAX_INDEX) ) return new Cell(row , col , R); else return null; } public Cell getLR(){ int row = i +2; int col = j +1; if((row >= 0 && row <= MAX_INDEX) &&(col >= 0 && col <= MAX_INDEX) ) return new Cell(row , col , LR); else return null; } public Cell getLL(){ int row = i +2; int col = j -1; if((row >= 0 && row <= MAX_INDEX) &&(col >= 0 && col <= MAX_INDEX) ) return new Cell(row , col , LL); else return null; } public Cell getL(){ if(j<2) return null; int row = i; int col = j -2; if((row >= 0 && row <= MAX_INDEX) &&(col >= 0 && col <= MAX_INDEX) ) return new Cell(row , col , L); else return null; } public Cell get(int cell){ switch (cell){ case UL: return getUL(); case UR: return getUR(); case L: return getL(); case R: return getR(); case LL: return getLL(); case LR: return getLR(); default: return null; } } @Override public String toString() { switch (this.weight){ case UL: return "UL"; case UR: return "UR"; case L: return"L"; case R: return "R"; case LL: return "LL"; case LR: return "LR"; default: return null; } } @Override public boolean equals(Object obj) { return (this.i == ((Cell)obj).i) && (this.j == ((Cell)obj).j); } } static void printShortestPath(int n, int i_start, int j_start, int i_end, int j_end) { Cell source = new Cell(i_start,j_start , 0); PriorityQueue priorizedSteps = new PriorityQueue(new CellComparator()); priorizedSteps.add(source); Cell next = priorizedSteps.poll(); StringBuilder sb = new StringBuilder(); int count=0; do{ for (int i = 1; i <=6 ; i++) { Cell c = next.get(i); if(c != null && !checked[c.i][c.j]) { priorizedSteps.add(c); checked[c.i][c.j] = true; } } next = priorizedSteps.poll(); sb.append(next+" "); count++; }while (!priorizedSteps.isEmpty() && !(next.equals(end))); if(!(next.equals(end))) System.out.println("Impossible"); else { System.out.println(count); System.out.println(sb.toString()); } } public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); MAX_INDEX = n-1; checked = new boolean[n][n]; int i_start = in.nextInt(); int j_start = in.nextInt(); int i_end = in.nextInt(); int j_end = in.nextInt(); end = new Cell(i_end ,j_end ,0); printShortestPath(n, i_start, j_start, i_end, j_end); in.close(); } private static class CellComparator implements Comparator{ @Override public int compare(Cell cell1, Cell cell2) { int diff = cell1.distance() - cell2.distance(); if(diff != 0) return diff; else { return cell1.weight - cell2.weight; } } } }