#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; string code[6] = { "UL", "UR", "R", "LR", "LL", "L" }; bool v[201][201]; int i_end, j_end, n; int gCnt; bool check(int i, int j) { if (i >= 0 && i < n) { if (j >= 0 && j < n) return 1; } return 0; } int neigh[6][2] = { {-2, -1}, {-2,1}, {0, 2}, {2,1}, {2,-1}, {0,-2} }; int path[40006]; int fPath[40006]; int pcnt; bool dfs(int ii, int jj, int cnt) { if (ii == i_end && jj == j_end) { if (cnt < gCnt) { gCnt = cnt; for (int i = 0; i < cnt; ++i) fPath[i] = path[i]; } return true; } bool ret = 0; v[ii][jj] = 1; for (int i = 0; i < 6; ++i) { if (!v[ii + neigh[i][0]][jj + neigh[i][1]] && cnt + 1 < gCnt && check(ii + neigh[i][0], jj + neigh[i][1])) { path[cnt] = i; ret |= dfs(ii + neigh[i][0], jj + neigh[i][1], cnt + 1); } } v[ii][jj] = 0; return ret; } void printShortestPath( int i_start, int j_start) { // Print the distance along with the sequence of moves. for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) v[i][j] = 0; gCnt = 0x1fffffff; pcnt = 0; if (dfs(i_start, j_start, 0)) { cout << gCnt << endl; for (int i = 0; i < gCnt; ++i) cout << code[fPath[i]] << " "; } else cout << "Impossible" << endl; } int main() { cin >> n; int i_start; int j_start; cin >> i_start >> j_start >> i_end >> j_end; printShortestPath(i_start, j_start); return 0; }