#include #include #include #include #include using namespace std; void showPath(vector< pair >& move_step,int r,int c){ // cout<=0){ //Indicating we have to go downwards if(c>=0){ //Indicating we have to go leftwards if(abs(c) < abs(r)){ move_step.push_back(make_pair("UL",c+1)); move_step.push_back(make_pair("UR",r-c-1)); } else if(abs(c) == abs(r)) move_step.push_back(make_pair("UL",r)); else{ move_step.push_back(make_pair("UL",r)); move_step.push_back(make_pair("L",(c-r)/2)); } } else{ //Indicating we have to go rightwards c=abs(c); if(abs(c) < abs(r)){ move_step.push_back(make_pair("UL",c+1)); move_step.push_back(make_pair("UR",r-c-1)); } else if(abs(c) == abs(r)) move_step.push_back(make_pair("UR",r)); else{ move_step.push_back(make_pair("UR",r)); move_step.push_back(make_pair("R",(c-r)/2)); } } } else{ //Indicating we have to go downwards r=abs(r); if(c>=0){ //Indicating we have to go leftwards if(abs(c) < abs(r)){ move_step.push_back(make_pair("LR",c+1)); move_step.push_back(make_pair("LL",r-c-1)); } else if(abs(c) == abs(r)) move_step.push_back(make_pair("LL",r)); else{ move_step.push_back(make_pair("LL",r)); move_step.push_back(make_pair("L",(c-r)/2)); } } else{ //Indicating we have to go rightwards c=abs(c); if(abs(c) < abs(r)){ move_step.push_back(make_pair("LR",c+1)); move_step.push_back(make_pair("LL",r-c-1)); } else if(abs(c) == abs(r)) move_step.push_back(make_pair("LR",r)); else{ move_step.push_back(make_pair("R",(c-r)/2)); move_step.push_back(make_pair("LR",r)); } } } } void printShortestPath(int n, int i_start, int j_start, int i_end, int j_end) { // Print the distance along with the sequenace of moves. int row=i_start - i_end; int col=j_start - j_end; if(abs(row) % 2 != 0){ cout<<"Impossible"; return; } else{ vector< pair > move_step; int n_move = abs(row)/2; if(n_move % 2 == 0 ){ if(abs(col) % 2 == 0){ showPath(move_step,row/2,col); if(abs(col) > n_move) n_move += (abs(col)-n_move)/2; } else{ cout<<"Impossible"; return; } }else{ if(abs(col) % 2 != 0){ showPath(move_step,row/2,col); if(abs(col) > n_move) n_move += (abs(col)-n_move)/2; } else{ cout<<"Impossible"; return; } } cout<> 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; }