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. bool isImpossible = (Math.Abs(i_start - i_end) % 2 != 0) || (j_start == j_end && Math.Abs(i_start - i_end) % 4 != 0) || (i_start == i_end && Math.Abs(j_start - j_end) % 2 != 0); if (isImpossible) { Console.WriteLine("Impossible"); } else { int i_start_point = i_start, j_start_point = j_start; var distance = Math.Pow((i_start_point - i_end), 2) + Math.Pow((j_start_point - j_end), 2); int moveCount = 0; var moves = new List(); while (distance > 0) { var moveResult = chooseMove(i_start_point, j_start_point, i_end, j_end); i_start_point = moveResult.Item1[0]; j_start_point = moveResult.Item1[1]; distance = Math.Pow((i_start_point - i_end), 2) + Math.Pow((j_start_point - j_end), 2); moves.Add(moveResult.Item2); moveCount++; } Console.WriteLine(moveCount); Console.WriteLine(String.Join(" ", moves)); } } static Tuple chooseMove(int i_start, int j_start, int i_end, int j_end) { var dictionary = new Dictionary> { { "UL", (int i_start_point, int j_start_point ) => { return new int[] { i_start_point - 2, j_start_point - 1}; } }, { "UR", (int i_start_point, int j_start_point ) => { return new int[] { i_start_point - 2, j_start_point + 1}; } }, { "R", (int i_start_point, int j_start_point ) => { return new int[] { i_start_point, j_start_point + 2}; } }, { "LR", (int i_start_point, int j_start_point ) => { return new int[] { i_start_point + 2, j_start_point + 1}; } }, { "LL", (int i_start_point, int j_start_point ) => { return new int[] { i_start_point + 2, j_start_point - 1}; } }, { "L", (int i_start_point, int j_start_point ) => { return new int[] { i_start_point, j_start_point - 2}; } } }; string move; if (i_start > i_end) // go up { if (j_start < j_end) // go left { move = "UR"; } else { move = "UL"; } } else { if(j_start < j_end) // go right, R, LR { var column_distance = Math.Abs(j_end - j_start); var row_distance = Math.Abs(i_end - i_start); if (row_distance < column_distance * 2) move = "R"; else move = "LR"; } else if(j_start > j_end) // go left LL, L { if (i_start == i_end) move = "L"; else move = "LL"; } else { move = "LR"; } } return new Tuple(dictionary[move](i_start, j_start), move); } 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); } }