#include using namespace std; vectordirections; int steps=0; bool check(int js, int is, int je, int ie) { if(abs(ie-is)%2==0) { if(abs(ie-is)%4==0 && (je-js)%2==0) { return true; } else if(abs(je-js)%2==1) return true; } return false; } float slope(int js, int is, int je, int ie) { return (ie-is)/(je-js); } void writeDirections(int js, int is, int je, int ie, int n) //recursive function. { if(js==je && is==ie) return; else if(ie2)) { directions.push_back('U'); directions.push_back('L'); directions.push_back(' '); steps++; writeDirections(js-1, is-2, je, ie, n); //cout<<"ul "; } else if(ie=js || slope(js, is, je, ie)<-2)) { directions.push_back('U'); directions.push_back('R'); directions.push_back(' '); steps++; writeDirections(js+1, is-2, je, ie, n); //cout<<"ur "; } else if(je-js>1) { directions.push_back('R'); directions.push_back(' '); steps++; writeDirections(js+2, is, je, ie, n); //cout<<"r"; } else if(ie>is && js!=n-1 && (je>=js || slope(js, is, je, ie)>2)) { directions.push_back('L'); directions.push_back('R'); directions.push_back(' '); steps++; writeDirections(js+1, is+2, je, ie, n); //cout<<"lr "; } else if(ie>is && js!=0 && (je<=js || slope(js, is, je, ie)<-2)) { directions.push_back('L'); directions.push_back('L'); directions.push_back(' '); steps++; writeDirections(js-1, is+2, je, ie, n); //cout<<"ll "; } else { directions.push_back('L'); directions.push_back(' '); steps++; writeDirections(js-2, is, je, ie, n); //cout<<"l "; } } 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. if(!check(j_start, i_start, j_end, i_end)) {cout << "Impossible"; return;} writeDirections(j_start, i_start, j_end, i_end, n); cout << steps << endl; for(int i=0; i> 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; }