// Program to print all prime factors # include # include #include #include #include #include using namespace std; using namespace std; 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. map priority; priority.insert(make_pair("UL", 1)); priority.insert(make_pair("UR", 2)); priority.insert(make_pair("R", 3)); priority.insert(make_pair("LR", 4)); priority.insert(make_pair("LL", 5)); priority.insert(make_pair("L", 6)); if (abs(i_start - i_end) % 2 != 0) cout << "Impossible"; else if(abs(abs(j_start-j_end)-(abs(i_start-i_end)/2))%2!=0) cout << "Impossible"; else { int counter = 0; string vD, hD; string diagonalD; vector> directions; if (i_start >= i_end) vD = 'U'; else vD = 'L'; int i= i_start, j=j_start; string path; while (i != i_end) { counter++; if (vD == "U") i -= 2; else i += 2; if (j > j_end) { hD = "L"; j--; } else if (j < j_end) { hD = "R"; j++; } else { if (j == 0) { hD = "R"; j++; } else if(j==n-1) { hD = "L"; j--; } else { if(vD=="U") { hD = "L"; j--; } else { hD = "R"; j++; } } } path += vD+hD; directions.push_back(make_pair(priority[path], path)); path = ""; } while (j != j_end) { counter++; if (hD == "R") j+=2; else j-=2; directions.push_back(make_pair(priority[hD], hD)); } std::sort(directions.begin(), directions.end()); cout << directions.size() << endl; vector < pair>::iterator it; for (it = directions.begin(); it != directions.end(); it++) { cout << it->second.c_str() << " "; } } } 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; }