#include #include 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. int n_vertical = (i_start - i_end)/2; if ((i_start - i_end)%2 || (j_start - j_end - n_vertical)%2){ cout << "Impossible" << endl; return; } int i_curr = i_start; int j_curr = j_start; int steps = 0; ostringstream oss; while(i_curr != i_end) { if (i_curr < i_end) { i_curr +=2; oss << "L"; if (j_curr <= j_end){ oss << "R"; j_curr++; }else{ oss << "L"; j_curr--; } }else{ // i_curr > i_end i_curr -= 2; oss << "U"; if (j_curr <= j_end){ j_curr++; oss << "R"; }else{ oss << "L"; j_curr--; } } oss << " "; steps++; } // now i_curr == i_start while(j_curr != j_end) { if (j_curr < j_end) { oss << "R"; j_curr+=2; }else{ oss << "L"; j_curr-=2; } //cout << "Moving horizontally - i_curr = " << i_curr << "\tj_curr = " << j_curr << endl; steps++; oss << " "; } cout << steps << endl; cout << oss.str() << 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; }