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. if (isImpossible(i_start, j_start, i_end, j_end)) { Console.WriteLine("Impossible"); return; } List moves = new List(); int i_curr = i_start; int j_curr = j_start; //make moves until current position == end position while (i_curr != i_end || j_curr != j_end) { //first get to the same row if(i_curr != i_end) { moves.Add(moveRow(n, ref i_curr, ref j_curr, i_end, j_end)); } else { moves.Add(moveColumn(ref j_curr, j_end)); } //Console.WriteLine("ic={0},jc={1},ie={2},je={3}",i_curr, j_curr,i_end,j_end); } Console.WriteLine(moves.Count); foreach(string s in moves) { Console.Write("{0} ", s); } Console.WriteLine(); } static string moveColumn(ref int j_curr, int j_end) { if (j_curr < j_end){ //move right j_curr += 2; return "R"; } else { //move left j_curr -= 2; return "L"; } } static string moveRow(int n, ref int i_curr, ref int j_curr, int i_end, int j_end) { if(i_end < i_curr){ //we go up if (j_curr >= j_end && j_curr != 0){ //go left i_curr -= 2; j_curr -= 1; return "UL"; } else { //go right i_curr -= 2; j_curr += 1; return "UR"; } } else { //we go down if (j_curr <= j_end && j_curr < (n-1)){ //go right i_curr += 2; j_curr += 1; return "LR"; } else { //go left i_curr += 2; j_curr -= 1; return "LL"; } } } static bool isImpossible(int i_start, int j_start, int i_end, int j_end) { bool result = false; //must be even rows away or same row if(Math.Abs(i_start - i_end) % 2 == 1) return true; int i_diff = Math.Abs(i_start - i_end) % 4; int j_diff = Math.Abs(j_start - j_end) % 2; //if factor of 4 rows away, then must be even columns away or same column if(i_diff == 0 && j_diff == 1) return true; //if factor of 2 rows away (and not 4 factor), then must be odd number of columns away if(i_diff == 2 && j_diff == 0) return true; return result; } 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); } }