using System; using System.Collections.Generic; using System.IO; using System.Linq; class Solution { enum Move {UL, UR, R, LR, LL, L, None}; class Coord { public int i; public int j; public Coord(int i, int j) { this.i = i; this.j = j; } } class ChessCell { public int movesCount; public Move moveType; public ChessCell(Move type, int count) { moveType = type; movesCount = count; } } static Coord getMove(Move move) { if(move == Move.UL) return new Coord(-2, -1); if(move == Move.UR) return new Coord(-2, 1); if(move == Move.R) return new Coord(0, 2); if(move == Move.LR) return new Coord(2, 1); if(move == Move.LL) return new Coord(2, -1); if(move == Move.L) return new Coord(0, -2); return new Coord(0, 0); } static void getShortestPath(int n, int i_start, int j_start, int i_end, int j_end, ChessCell[,] cells) { Queue queue = new Queue(); cells[i_start, j_start] = new ChessCell(Move.None, 0); queue.Enqueue(new Coord(i_start, j_start)); bool reached = false; while(queue.Count > 0 && !reached) { Coord current = queue.Dequeue(); for(int k = 0; k < 6; k++) { Coord coord = getMove((Move)k); if(current.i + coord.i >= 0 && current.i + coord.i < n && current.j + coord.j >= 0 && current. j + coord.j < n) { if(cells[current.i + coord.i, current.j + coord.j] == null) { cells[current.i + coord.i, current.j + coord.j] = new ChessCell((Move)k, cells[current.i, current.j].movesCount + 1); queue.Enqueue(new Coord(current.i + coord.i, current.j + coord.j)); if(current.i + coord.i == i_end && current.j + coord.j == j_end) reached = true; } } } } } static void printPath(ChessCell[,] cells, int i, int j) { if(cells[i,j].moveType != Move.None) { Coord coord = getMove(cells[i,j].moveType); printPath(cells, i - coord.i, j - coord.j); Console.Write(cells[i,j].moveType.ToString() + " "); } } 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. ChessCell[,] cells = new ChessCell[n,n]; getShortestPath(n, i_start, j_start, i_end, j_end, cells); if(cells[i_end, j_end] == null) Console.WriteLine("Impossible"); else { Console.WriteLine(cells[i_end, j_end].movesCount); printPath(cells, i_end, j_end); } } static void Main(String[] args) { int n = Convert.ToInt32(Console.ReadLine()); string[] tokens_i_start = Console.ReadLine().Split(' '); int i_start = Convert.ToInt32(tokens_i_start[0]); int j_start = Convert.ToInt32(tokens_i_start[1]); int i_end = Convert.ToInt32(tokens_i_start[2]); int j_end = Convert.ToInt32(tokens_i_start[3]); printShortestPath(n, i_start, j_start, i_end, j_end); } }