using System; using System.Collections.Generic; using System.IO; using System.Linq; class Solution { static int totalsteps= 0; static int currentI = 0; static int targetI = 0; static int currentJ = 0; static int targetJ = 0; static string moves = ""; static void printShortestPath(int n, int i_start, int j_start, int i_end, int j_end) { currentI = i_start; targetI = i_end; currentJ = j_start; targetJ = j_end; bool impossible = true; // detemine if the path is impossible int yDiffernce = Math.Abs(i_end - i_start); int xDiffernce = Math.Abs(j_end - j_start); int OddEven = Math.Abs(yDiffernce % 2); //is impossible? if(OddEven != 1) { if(((yDiffernce/2) % 2 == 1 && xDiffernce % 2==1 ) || ((yDiffernce/2) % 2 == 0 && xDiffernce % 2==0 ) ) impossible = false; } // find minimum move distance between squares if(!impossible) { int totalMoves = makeNextMove(); Console.WriteLine (totalMoves); Console.WriteLine (moves); } else { Console.WriteLine ("Impossible"); } } static int makeNextMove() { if(currentI == targetI && currentJ == targetJ) { //done and found target return totalsteps; } totalsteps = totalsteps + 1; //move priority helpers int overmoves = (targetJ - currentJ); int downmoves = (targetI - currentI) / 2; bool isSameHoziontalLine = false; bool isTargetToRight = false; if(currentI == targetI) isSameHoziontalLine = true; if((targetJ - currentJ)>1) isTargetToRight = true; //make a move based upon move orders and print it if(currentI > targetI && currentJ >= targetJ) { //target is to left and upper moves = moves + ("UL "); currentI = currentI - 2; currentJ = currentJ - 1; makeNextMove(); } else if(currentI > targetI && currentJ < targetJ) { //target is to left and upper moves = moves + ("UR "); currentI = currentI - 2; currentJ = currentJ + 1; makeNextMove(); } else if( (isSameHoziontalLine && isTargetToRight) || (downmoves != overmoves && isTargetToRight) ) { //target is to right moves = moves + ("R "); currentJ = currentJ + 2; makeNextMove(); } else if(currentI < targetI && currentJ <= targetJ) { //target is to left and upper moves = moves + ("LR "); currentI = currentI + 2; currentJ = currentJ + 1; makeNextMove(); } else if(currentI < targetI && currentJ > targetJ) { //target is to left and upper moves = moves + ("LL "); currentI = currentI + 2; currentJ = currentJ - 1; makeNextMove(); } else if ( currentJ > targetJ) { //target is to left and upper moves = moves + ("L "); currentJ = currentJ - 2; makeNextMove(); } else { //Console.Write ("current target " + targetI + " " + targetJ + " "); } return totalsteps; } 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); } }