using System; using System.Collections.Generic; using System.IO; using System.Linq; class Solution { public class node { public int i; public int j; public string Path; public int step; } 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. List dList = new List(); bool find = false; int[,] visit = new int[n, n]; Queue nq = new Queue(); node startNode = new node(); startNode.i = i_start; startNode.j = j_start; startNode.Path = ""; startNode.step = 0; visit[i_start, j_start] = 1; nq.Enqueue(startNode); while (nq.Count != 0) { node s = nq.Dequeue(); if(s.i == i_end && s.j == j_end) { Console.WriteLine(s.step); Console.WriteLine(s.Path.Trim()); find = true; break; } Q(nq, s, "UL", n, visit); Q(nq, s, "UR", n, visit); Q(nq, s, "R", n, visit); Q(nq, s, "LR", n, visit); Q(nq, s, "LL", n, visit); Q(nq, s, "L", n, visit); } if (!find) Console.WriteLine("Impossible"); } static void Q(Queue bfsQueue, node s, string D, int N, int[,] visit) { node n = new node(); switch (D) { case "UL": n.i = s.i - 2; n.j = s.j - 1; n.Path = s.Path + "UL "; if (n.i >= 0 && n.j >= 0 && visit[n.i, n.j] == 0) { visit[n.i, n.j] = s.step + 1; n.step = s.step + 1; bfsQueue.Enqueue(n); } break; case "UR": n.i = s.i - 2; n.j = s.j + 1; n.Path = s.Path + "UR "; if (n.i >= 0 && n.j < N && visit[n.i, n.j] == 0) { visit[n.i, n.j] = s.step + 1; n.step = s.step + 1; bfsQueue.Enqueue(n); } break; case "R": n.i = s.i; n.j = s.j + 2; n.Path = s.Path + "R "; if (n.j < N && visit[n.i, n.j] == 0) { visit[n.i, n.j] = s.step + 1; n.step = s.step + 1; bfsQueue.Enqueue(n); } break; case "LR": n.i = s.i + 2; n.j = s.j + 1; n.Path = s.Path + "LR "; if (n.i < N && n.j < N && visit[n.i, n.j] == 0) { visit[n.i, n.j] = s.step + 1; n.step = s.step + 1; bfsQueue.Enqueue(n); } break; case "LL": n.i = s.i + 2; n.j = s.j - 1; n.Path = s.Path + "LL "; if (n.i < N && n.j >= 0 && visit[n.i, n.j] == 0) { visit[n.i, n.j] = s.step + 1; n.step = s.step + 1; bfsQueue.Enqueue(n); } break; case "L": n.i = s.i; n.j = s.j - 2; n.Path = s.Path + "L "; if (n.j >= 0 && visit[n.i, n.j] == 0) { visit[n.i, n.j] = s.step + 1; n.step = s.step + 1; bfsQueue.Enqueue(n); } break; } } 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); } }