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 (Math.Abs(i_end - i_start) % 2 != 0 || (Math.Abs(i_end - i_start) / 2) % 2 != Math.Abs(j_end - j_start) % 2) { Console.WriteLine("Impossible"); return; } else { int i_cur = i_start; int j_cur = j_start; int cur_distance = Math.Abs(i_end - i_cur) + Math.Abs(j_end - j_cur); List path = new List(); Dictionary directions = new Dictionary(); directions.Add("UL", new int[] { -2, -1 }); directions.Add("UR", new int[] { -2, 1 }); directions.Add("R", new int[] { 0, 2 }); directions.Add("LR", new int[] { 2, 1 }); directions.Add("LL", new int[] { 2, -1 }); directions.Add("L", new int[] { 0, -2 }); while (cur_distance > 0) { string best_dir = ""; int best_distance = cur_distance; foreach (KeyValuePair dir in directions) { int i_try = i_cur + dir.Value[0]; int j_try = j_cur + dir.Value[1]; int try_distance = cur_distance; if (i_try >= 0 && i_try < n && j_try >= 0 && j_try < n) { try_distance = Math.Abs(i_end - i_try) + Math.Abs(j_end - j_try); if (try_distance < best_distance) { best_dir = dir.Key; best_distance = try_distance; } } } if (best_dir!="") // Should not be needed { path.Add(best_dir); i_cur += directions[best_dir][0]; j_cur += directions[best_dir][1]; cur_distance = best_distance; } } Console.WriteLine(path.Count); Console.WriteLine(string.Join(" ", path.ToArray())); } } 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); } }