#include #include #include #include #include #include using namespace std; vector> visited; vector> bfs(pair start, pair end, int n) { vector> path; path.push_back(start); visited[start.first][start.second] = true; queue >> Q; Q.push(path); while (not Q.empty()) { auto path = Q.front(); Q.pop(); auto cur = path[path.size() - 1]; if (cur == end) return path; if (cur.first - 2 >= 0) { if (cur.second - 1 >= 0 and not visited[cur.first - 2][cur.second - 1]) { pair t(cur.first - 2, cur.second - 1); vector > temp(path); temp.push_back(t); Q.push(temp); visited[t.first][t.second] = true; } if (cur.second + 1 < n and not visited[cur.first - 2][cur.second + 1]) { pair t(cur.first - 2, cur.second + 1); vector > temp(path); temp.push_back(t); Q.push(temp); visited[t.first][t.second] = true; } } if (cur.second + 2 < n and not visited[cur.first][cur.second + 2]) { pair t(cur.first, cur.second + 2); vector > temp(path); temp.push_back(t); Q.push(temp); visited[t.first][t.second] = true; } if (cur.first + 2 < n) { if (cur.second + 1 < n and not visited[cur.first + 2][cur.second + 1]) { pair t(cur.first + 2, cur.second + 1); vector > temp(path); temp.push_back(t); Q.push(temp); visited[t.first][t.second] = true; } if (cur.second - 1 >= 0 and not visited[cur.first + 2][cur.second - 1]) { pair t(cur.first + 2, cur.second - 1); vector > temp(path); temp.push_back(t); Q.push(temp); visited[t.first][t.second] = true; } } if (cur.second - 2 >= 0 and not visited[cur.first][cur.second - 2]) { pair t(cur.first, cur.second - 2); vector > temp(path); temp.push_back(t); Q.push(temp); visited[t.first][t.second] = true; } } vector> t; return t; } int main() { int n; cin >> n; int x, y, i, j; vector> path(n); cin >> x >> y >> i >> j; pair start(x, y), end(i, j); visited.reserve(n); for (int i = 0; i < n; i++) { visited[i].reserve(n); } if (start.first % 2 == end.first % 2) { path = bfs(start, end, n); if (path.size() == 0) { cout << "Impossible\n"; } else { cout << path.size() - 1 << "\n"; pair curr = path[0]; for (int i = 1; i < path.size(); i++) { pair next = path[i]; string move = ""; if (curr.first - next.first == -2) move += "L"; if (curr.first - next.first == 2) move += "U"; if (curr.second < next.second) move += "R"; else move += "L"; cout << move << " "; curr.swap(next); } } } else { cout << "Impossible\n"; } return 0; }