#include #include #include #include using namespace std; vector > visit; int R[] = { -2,-2,0,2,2,0 }; int C[] = { -1,1,2,1,-1,-2 }; string L[] = { "UL","UR","R","LR","LL","L" }; struct node { pair pos; int cnt; string cmd; }; bool correct_pos(int n, int r, int c) { return r >= 0 && r < n && c >= 0 && c < 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. visit.clear(); visit.resize(n, vector (n, false)); visit.assign(n, vector (n, false)); queue q; node p; p.cnt = 0; p.pos = make_pair(i_start, j_start); p.cmd = ""; q.push(p); visit[p.pos.first][p.pos.second] = true; while (!q.empty()) { node t = q.front(); q.pop(); if (t.pos.first == i_end && t.pos.second == j_end) { cout << t.cnt << endl; cout << t.cmd; cout << endl; return; } for (int i = 0; i < 6; i++) { node new_node; new_node.pos = make_pair(t.pos.first + R[i], t.pos.second + C[i]); new_node.cmd = t.cmd + L[i] + " "; new_node.cnt = t.cnt + 1; if (correct_pos(n, new_node.pos.first, new_node.pos.second) && visit[new_node.pos.first][new_node.pos.second] == false) { visit[new_node.pos.first][new_node.pos.second] = true; q.push(new_node); } } } cout << "Impossible\n"; } 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; }