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. int noOfMoves = 0; string moves = string.Empty; if ((Math.Abs(i_start - i_end) % 2 == 1)) Console.WriteLine("Impossible"); else { if (i_start == i_end) { if (Math.Abs(j_start - j_end) % 2 == 0) { if (j_start < j_end) { noOfMoves = (j_end - j_start) / 2; for (int i_temp = 0; i_temp < noOfMoves; i_temp++) { if (i_temp == 0) moves = moves + "R"; else moves = moves + " " + "R"; } Console.WriteLine(noOfMoves); Console.WriteLine(moves); } else { noOfMoves = (j_start - j_end) / 2; for (int i_temp = 0; i_temp < noOfMoves; i_temp++) { if (i_temp == 0) moves = moves + "L"; else moves = moves + " " + "L"; } Console.WriteLine(noOfMoves); Console.WriteLine(moves); } } else Console.WriteLine("Impossible"); } else if (i_start < i_end) { if (j_start == j_end) { if ((i_end - i_start) % 4 == 0) { noOfMoves = (i_end - i_start) / 2; for (int i_temp = 0; i_temp < noOfMoves; i_temp++) { if (i_temp == 0) moves = moves + "LR"; else { if (i_temp % 2 == 0) moves = moves + " " + "LR"; else moves = moves + " " + "LL"; } } Console.WriteLine(noOfMoves); Console.WriteLine(moves); } else Console.WriteLine("Impossible"); } else if (j_start < j_end) { int i_temp = i_start; int j_temp = j_start; while (i_temp < i_end || j_temp < j_end) { noOfMoves++; if (i_temp == i_end) { moves = moves + "R" + " "; j_temp = j_temp + 2; } else { moves = moves + "LR" + " "; i_temp = i_temp + 2; j_temp = j_temp + 1; } } if (i_temp == i_end && j_temp == j_end) { Console.WriteLine(noOfMoves); Console.WriteLine(moves.Substring(0, moves.Length - 1)); } else Console.WriteLine("Impossible"); } else { int i_temp = i_start; int j_temp = j_start; while (i_temp < i_end || j_temp > j_end) { noOfMoves++; if (i_temp == i_end) { moves = moves + "L" + " "; j_temp = j_temp - 2; } else { moves = moves + "LL" + " "; i_temp = i_temp + 2; j_temp = j_temp - 1; } } if (i_temp == i_end && j_temp == j_end) { Console.WriteLine(noOfMoves); Console.WriteLine(moves.Substring(0, moves.Length - 1)); } else Console.WriteLine("Impossible"); } } else { if (j_start == j_end) { if ((i_start - i_end) % 4 == 0) { noOfMoves = (i_start - i_end) / 2; for (int i_temp = 0; i_temp < noOfMoves; i_temp++) { if (i_temp == 0) moves = moves + "UL"; else { if (i_temp % 2 == 0) moves = moves + " " + "UR"; else moves = moves + " " + "UL"; } } Console.WriteLine(noOfMoves); Console.WriteLine(moves); } else Console.WriteLine("Impossible"); } else if (j_start < j_end) { int i_temp = i_start; int j_temp = j_start; while (i_temp > i_end || j_temp < j_end) { noOfMoves++; if (i_temp == i_end) { moves = moves + "R" + " "; j_temp = j_temp + 2; } else { moves = moves + "UR" + " "; i_temp = i_temp - 2; j_temp = j_temp + 1; } } if (i_temp == i_end && j_temp == j_end) { Console.WriteLine(noOfMoves); Console.WriteLine(moves.Substring(0, moves.Length - 1)); } else Console.WriteLine("Impossible"); } else { int i_temp = i_start; int j_temp = j_start; while (i_temp > i_end || j_temp > j_end) { noOfMoves++; if (i_temp == i_end) { moves = moves + "L" + " "; j_temp = j_temp - 2; } else { moves = moves + "UL" + " "; i_temp = i_temp - 2; j_temp = j_temp - 1; } } if (i_temp == i_end && j_temp == j_end) { Console.WriteLine(noOfMoves); Console.WriteLine(moves.Substring(0, moves.Length - 1)); } else Console.WriteLine("Impossible"); } } } } 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); } }