#include using namespace std; const int MAXN = 205; struct Point{ int x, y, step; Point(int x, int y, int s) : x(x), y(y), step(s) {} }; int vis[MAXN][MAXN]; int trace[MAXN * MAXN + 1]; int dirx[6] = {0, 2, 2, 0, -2, -2}; int diry[6] = {-2, -1, 1, 2, 1, -1}; // UL, UR, R, LR, LL, L void print_path(vector &pts) { for(int i = 1; i < pts.size(); i ++) { int tx = pts[i].x - pts[i-1].x; int ty = pts[i].y - pts[i-1].y; if(i > 1) { printf(" "); } if(tx == 0 && ty == -2) printf("L"); else if(tx == 2 && ty == -1) printf("LL"); else if(tx == 2 && ty == 1) printf("LR"); else if(tx == 0 && ty == 2) printf("R"); else if(tx == -2 && ty == 1) printf("UR"); else printf("UL"); } printf("\n"); } 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. for(int i = 0; i < n; i ++) { for(int j = 0; j < n; j ++) vis[i][j] = n * n + 1; vis[i][i] = 0; } vis[i_start][j_start] = 0; queue q; q.push(Point(i_start, j_start, 0)); trace[i_start * n + j_start] = i_start * n + j_start; bool flag = false; while(!q.empty()) { if(flag) break; Point cur = q.front(); q.pop(); for(int i = 0; i < 6; ++ i) { int tx = cur.x + dirx[i]; int ty = cur.y + diry[i]; int step = cur.step + 1; if(tx == i_end && ty == j_end) { printf("%d\n", step); trace[tx * n + ty] = cur.x * n + cur.y; flag = true; break; } if (tx < 0 || ty < 0 || tx >= n || ty >= n) continue; if (vis[tx][ty] >= step) { trace[tx * n + ty] = cur.x * n + cur.y; vis[tx][ty] = step; q.push(Point(tx, ty, step)); } } } if (!flag) { puts("Impossible\n"); return; } vector ans; ans.push_back(Point(i_end, j_end, 0)); int px = i_end, py = j_end; while(trace[px * n + py] != px * n + py) { int p = trace[px * n + py]; px = p / n; py = p % n; ans.push_back(Point(px, py, 0)); } //ans.push_back(Point(i_start, j_start, 0)); reverse(ans.begin(), ans.end()); print_path(ans); } 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; printShortestPath(n, i_start, j_start, i_end, j_end); return 0; }