#include using namespace std; const int dx[] = {-2, -2, 0, 2, 2, 0}, dy[] = {-1, 1, 2, 1, -1, -2}; const string moves[] = {"UL", "UR", "R", "LR", "LL", "L"}; int d[222][222]; int tr[222][222]; 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. memset(d, -1, sizeof d); memset(tr, -1, sizeof tr); queue > qu; qu.push(make_pair(i_start, j_start)); d[i_start][j_start] = 0; while (qu.size()) { auto p = qu.front(); qu.pop(); for (int i = 0; i < 6; i++) { int x = p.first + dx[i], y = p.second + dy[i]; if (d[x][y] == -1 && x >= 0 && x < n && y >= 0 && y < n) { d[x][y] = d[p.first][p.second] + 1; tr[x][y] = i; qu.push(make_pair(x, y)); } } } // trace if (d[i_end][j_end] == -1) { cout << "Impossible" << endl; return; } cout << d[i_end][j_end] << endl; vector R; int x = i_end, y = j_end; while (tr[x][y] != -1) { int ii = tr[x][y]; x -= dx[ii]; y -= dy[ii]; R.push_back(ii); } reverse(R.begin(), R.end()); for (auto ii: R) { cout << moves[ii] << " "; } cout << endl; } 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; }