#include #include #include #include #include using namespace std; int dir[6][2] = {{-1,-2},{1,-2},{2,0},{1,2},{-1,2}, {-2,0}}; char dir_str[6][3] = {"UL", "UR", "R", "LR", "LL", "L"}; int visited[201][201]; int ie, je, n; vector best_yet; bool solve(int i, int j, int dist, vector &path) { if (i < 0 || j < 0 || i >= n || j >= n || visited[i][j] <= dist) return false; visited[i][j] = dist; if (i == ie && j == je) { best_yet.resize(0); copy(path.begin(), path.end(), back_inserter(best_yet)); return true; } //for(int k = 0; k < path.size(); k++) cout << dir_str[path[k]] << " "; //cout << i << "-" << j << endl; bool solved = false; for (int d = 0; d < 6; d++) { path.push_back(d); if(solve(i+dir[d][1], j+dir[d][0], dist+1, path)) { solved = true; } path.pop_back(); } return solved; } int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int is, js; cin >> n; vector path; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) visited[i][j] = numeric_limits::max(); cin >> is >> js >> ie >> je; if (!solve(is, js, 0, path)) { cout << "Impossible" << endl; return 0; } cout << best_yet.size() << endl; for (int i = 0; i < best_yet.size(); i++) { if (i) cout << " "; cout << dir_str[best_yet[i]]; } cout << endl; return 0; }