using System; using System.Collections.Generic; using System.IO; using System.Linq; class Solution {// 0 1 2 3 4 5 static string[] movesNames = new string[] { "UL", "UR", "R", "LR", "LL", "L" }; static bool firstWas = false; static void SetLeftRight(out int l, out int r, bool cond) { if (cond) { l = 0; r = 1; } else { l = 4; r = 3; } } static void Swap(ref int a, ref int b) { int tmp = a; a = b; b = tmp; } static bool Move(ref int i, ref int j, int index, int n) { if (index == 0) { i -= 2; j -= 1; } else if (index == 1) { i -= 2; j += 1; } else if (index == 2) j += 2; else if (index == 3) { i += 2; j += 1; } else if (index == 4) { i += 2; j -= 1; } else if (index == 5) j -= 2; if (j < 0 || j >= n || i < 0 || i >= n) return false; return true; } static void Write(int i) { Console.Write((firstWas ? " " : "") + movesNames[i].ToString()); firstWas = true; } static void PrintMoves(int[] moves, int i_start, int j_start, int len) { int[] moveI = new int[2]; int n = 0; int count = 0; for (int i = 0; i < moves.Length; ++i) if (moves[i] > 0) { n += moves[i]; moveI[count] = i; if (++count == 2) break; } Console.WriteLine(n.ToString()); while (--moves[moveI[0]] >= 0 && Move(ref i_start, ref j_start, moveI[0], len)) Write(moveI[0]); while (moves[moveI[0]] >= 0) { if (moves[moveI[1]] > 0) { Write(moveI[1]); --moves[moveI[1]]; } Write(moveI[0]); --moves[moveI[0]]; } while (moves[moveI[1]] > 0) { Write(moveI[1]); --moves[moveI[1]]; } } static void PrintShortestPath(int n, int i_start, int j_start, int i_end, int j_end) { int[] moves = new int[6]; int verticalMoves = Math.Abs(i_start - i_end); if (verticalMoves % 2 == 0) { verticalMoves /= 2; int horizontalMoves = Math.Abs(j_start - j_end); if (verticalMoves % 2 == horizontalMoves % 2) { int l, r; bool cond = i_start >= i_end; SetLeftRight(out l, out r, cond); if (verticalMoves >= horizontalMoves) { if (j_start >= j_end) Swap(ref l, ref r); moves[r] += horizontalMoves + (verticalMoves - horizontalMoves) / 2; moves[l] += verticalMoves - moves[r]; } else { if (j_start >= j_end) { moves[l] += verticalMoves; moves[5] += (horizontalMoves - verticalMoves) / 2; } else { moves[r] += verticalMoves; moves[2] += (horizontalMoves - verticalMoves) / 2; } } PrintMoves(moves, i_start, j_start, n); } else Console.Write("Impossible"); } else Console.Write("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); } }