using System; using System.Collections.Generic; using System.IO; using System.Linq; class Solution { 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. (row,column) string output=""; int c_row = i_start; int c_column = j_start; int[] UpperLeft = {-2,-1}; int[] UpperRight = {-2,1}; int[] Right = {0,2}; int[] LowerRight= {2,1}; int[] LowerLeft= {2,-1}; int[] Left = {0,-2}; //Do rows first... while (c_row < n+1 && c_row > -1) { //go up - use ul or ur if(c_row > i_end && i_end < i_start) { if(c_column >= j_end)// ul { c_row = c_row + UpperLeft[0]; c_column = c_column + UpperLeft[1]; output+="UL "; } else if(c_column < j_end ) // ur { c_row = c_row + UpperRight[0]; c_column = c_column + UpperRight[1]; output+="UR "; } else break; } else if(c_row < i_end && i_end > i_start) { if(c_column <= j_end) //LR { c_row = c_row + LowerRight[0]; c_column = c_column + LowerRight[1]; output+="LR "; } else if(c_column > j_end) // LL { c_row = c_row + LowerLeft[0]; c_column = c_column + LowerLeft[1]; output+="LL "; } else break; } else break; } if(c_row == i_end) { while(c_column > 0 || c_column < n) { if (c_column < j_end && j_start < j_end )// Right { c_column = c_column + Right[1]; output+="R "; } else if(c_column > j_end && j_start > j_end) // Left { c_column = c_column + Left[1]; output+="L "; } else break; } } if (c_row == i_end && c_column ==j_end) { Console.WriteLine(output.Trim().Split(' ').Length); Console.Write(output.Trim()); } else { Console.WriteLine("Impossible"); //Console.WriteLine(output.Trim()); //Console.WriteLine("["+c_row+","+c_column+"]"); } } 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); } }