#include #define INF 1<<29 using namespace std; const string UL = "UL "; const string UR = "UR "; const string R = "R "; const string LR = "LR "; const string LL = "LL "; const string L = "L "; int path_len = INF; string str_final; void printShortestPath(int n, int i_start, int j_start, int i_end, int j_end, string str, string dir, int path) { // Print the distance along with the sequence of moves. if (i_start < 0 || i_start >= n || j_start < 0 || j_start >= n) return; if (path > (n/3 * n/3)) return; if (i_start == i_end && j_start == j_end && path < path_len) { path_len = path; str_final = str.substr(0, str.length()-1); return; } string str_ul, str_ur, str_r, str_lr, str_ll, str_l; if (dir != LR) { str_ul = str + UL; printShortestPath(n, i_start-2, j_start-1, i_end, j_end, str_ul, UL, path+1); } if (dir != LL) { str_ur = str + UR; printShortestPath(n, i_start-2, j_start+1, i_end, j_end, str_ur, UR, path+1); } if (dir != L) { str_r = str + R; printShortestPath(n, i_start, j_start+2, i_end, j_end, str_r, R, path+1); } if (dir != UL) { str_lr = str + LR; printShortestPath(n, i_start+2, j_start+1, i_end, j_end, str_lr, LR, path+1); } if (dir != UR) { str_ll = str + LL; printShortestPath(n, i_start+2, j_start-1, i_end, j_end, str_ll, LL, path+1); } if (dir != R) { str_l = str + L; printShortestPath(n, i_start, j_start-2, i_end, j_end, str_l, L, path+1); } } int main() { int n; cin >> n; int i_start; int j_start; int i_end; int j_end; cin >> i_start >> j_start >> i_end >> j_end; int i_diff = abs(i_end-i_start); int j_diff = abs(j_end-j_start); if (!(!(i_diff & 1) && ((j_diff & 1) ^ !(i_diff & 3)))) cout << "Impossible" << endl; else { printShortestPath(n, i_start, j_start, i_end, j_end, "", "", 0); cout << path_len << endl; cout << str_final << endl; } return 0; }