#include using namespace std; std::string findHeading(int cRow, int cColumn, int dRow, int dColumn){ std::string heading = ""; if(cRow > dRow && cColumn > dColumn){ heading = "UL"; } if(cRow > dRow && cColumn < dColumn){ heading = "UR"; } if(cRow > dRow && cColumn == dColumn){ heading = "UL"; } if(cRow < dRow && cColumn > dColumn){ heading = "LL"; } if(cRow < dRow && cColumn < dColumn){ heading = "LR"; } if(cRow < dRow && cColumn == dColumn){ heading = "LR"; } if(cRow == dRow && cColumn > dColumn){ heading = "L"; } if(cRow == dRow && cColumn < dColumn){ heading = "R"; } return heading; } bool reachedDestination(int cRow, int cColumn, int dRow, int dColumn){ bool destinationReached = false; if(cRow == dRow && cColumn == dColumn){ destinationReached = true; } return destinationReached; } bool checkMove(int cRow, int cColumn, int dRow, int dColumn, int n){ bool movePossible = false; if(cRow != dRow || cColumn != dColumn - 2 || cColumn != dColumn + 2){ if((cRow >= 0 && cRow <= n) && (cColumn >= 0 && cColumn <= n)){ movePossible = true; } } return movePossible; } void moveUL(int &cRow, int &cColumn){ cRow -= 2; cColumn -= 1; } void moveUR(int &cRow, int &cColumn){ cRow -= 2; cColumn += 1; } void moveR(int &cRow, int &cColumn){ cColumn += 2; } void moveLR(int &cRow, int &cColumn){ cRow += 2; cColumn += 1; } void moveLL(int &cRow, int &cColumn){ cRow += 2; cColumn -= 1; } void moveL(int &cRow, int &cColumn){ cColumn -= 2; } void printShortestPath(int n, int i_start, int j_start, int i_end, int j_end) { // Adding sugar int cRow = i_start; int cColumn = j_start; int dRow = i_end; int dColumn = j_end; bool possibleMove = true; bool destinationReached = false; std::string currentHeading = ""; vector moveList; while(possibleMove && !destinationReached){ currentHeading = findHeading(cRow, cColumn, dRow, dColumn); if(currentHeading == "UL"){ if(checkMove(cRow, cColumn, dRow, dColumn, n)){ moveUL(cRow, cColumn); moveList.push_back("UL"); destinationReached = reachedDestination(cRow, cColumn, dRow, dColumn); } else { possibleMove = false; } } if(currentHeading == "UR"){ if(checkMove(cRow, cColumn, dRow, dColumn, n)){ moveUR(cRow, cColumn); destinationReached = reachedDestination(cRow, cColumn, dRow, dColumn); moveList.push_back("UR"); } else { possibleMove = false; } } if(currentHeading == "L"){ if(checkMove(cRow, cColumn, dRow, dColumn, n)){ moveL(cRow, cColumn); destinationReached = reachedDestination(cRow, cColumn, dRow, dColumn); moveList.push_back("L"); } else { possibleMove = false; } } if(currentHeading == "R"){ if(checkMove(cRow, cColumn, dRow, dColumn, n)){ moveR(cRow, cColumn); moveList.push_back("R"); } else { possibleMove = false; } } if(currentHeading == "LL"){ if(checkMove(cRow, cColumn, dRow, dColumn, n)){ moveLL(cRow, cColumn); destinationReached = reachedDestination(cRow, cColumn, dRow, dColumn); moveList.push_back("LL"); } else { possibleMove = false; } } if(currentHeading == "LR"){ if(checkMove(cRow, cColumn, dRow, dColumn, n)){ moveLR(cRow, cColumn); destinationReached = reachedDestination(cRow, cColumn, dRow, dColumn); moveList.push_back("LR"); } else { possibleMove = false; } } } if(!possibleMove){ std::cout << "Impossible"; } else { std::cout << moveList.size() << std::endl; for (auto move : moveList){ std::cout << move << " "; } } } 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; }