#include #include #include #include #include using namespace std; int main() { int n; cin >> n; int is, js, ie, je; cin >> is >> js >> ie >> je; int rowDiff = (ie > is) ? ie - is : is - ie; if (rowDiff % 2 != 0) { cerr << "RowDiff = " << rowDiff << "\n"; cout << "Impossible"; return 0; } else { int colDiff = (je > js) ? je - js : js - je; if (rowDiff % 4 == 0) { if (colDiff % 2 != 0) { cerr << "RowDiff = " << rowDiff << " ColDiff = " << colDiff << "\n"; cout << "Impossible"; return 0; } } else { if (colDiff % 2 == 0) { cerr << "RowDiff = " << rowDiff << " ColDiff = " << colDiff << "\n"; cout << "Impossible"; return 0; } } } int moveCount = 0; vector moves; while (is != ie || js != je) { moveCount++; if (ie < is) { if (je <= js) { moves.push_back("UL"); is -= 2; js--; } else { int rowDiff = is - ie; if (je - js < rowDiff / 2) { moves.push_back("UL"); is -= 2; js--; } else { moves.push_back("UR"); is -= 2; js++; } } } else if (ie > is) { if (je >= js) { int rowDiff = ie - is; if (je - js > rowDiff / 2) { moves.push_back("R"); js += 2; } else { moves.push_back("LR"); is += 2; js++; } } else { moves.push_back("LL"); is += 2; js--; } } else { //OK if (je < js) { moves.push_back("L"); js -= 2; } else if (je > js) { moves.push_back("R"); js += 2; } } } cout << moveCount << "\n"; vector priority { "UL", "UR", "R", "LR", "LL", "L" }; for (auto jt = priority.begin(), jend = priority.end(); jt != jend; ++jt) { string cur = *jt; for (auto it = moves.begin(), end = moves.end(); it != end; ++it) { if (*it != cur) continue; cout << *it << " "; } } return 0; }