/* ID: usaco.t3 TASK: test LANG: C++14 */ #pragma GCC optimize ("O3") /****Author: Barish Namazov****/ #include using namespace std; /***TEMPLATE***/ #define intt long long #define pii pair #define vi vector #define vii vector #define all(v) (v).begin(),(v).end() #define rall(v) (v).rbegin(),(v).rend() #define F first #define S second #define pb push_back #define IO ios_base::sync_with_stdio(false);cin.tie(); #define endl '\n' #define wtfis(x) cerr << "at line " << __LINE__ << ": " << #x << " = " << (x) << endl const intt max3 = 1003; const intt max4 = 10004; const intt maxx = 100005; const intt max6 = 1000006; const intt max7 = 10000007; const intt lg4 = 13; const intt lg5 = 17; const intt lg6 = 20; const intt INF = 2LL * 1000000000; const intt INFLL = 9LL * 1000000000 * 1000000000; /***************/ intt powmod (intt a, intt b, intt mod) { intt res = 1; a %= mod; for (; b; b >>= 1) { if (b & 1) res = (res * a) % mod; a = (a * a) % mod; } return res; } intt gcd (intt a, intt b) { while (b > 0) { intt t = a % b; a = b, b = t; } return a; } intt lcm (intt a, intt b) { return (a / gcd (a, b)) * b; } intt is_prime (intt n) { if (n <= 1 || n > 3 && (n % 2 == 0 || n % 3 == 0)) return 0; for (intt i = 5, t = 2; i * i <= n; i += t, t = 6 - t) if (n % i == 0) return 0; return 1; } /**************************/ intt dx[] = {-2, -2, +0, +2, +2, -0}; intt dy[] = {-1, +1, +2, +1, -1, -2}; string res[] = {"UL", "UR", "R", "LR", "LL", "L"}; intt n, dis[205][205]; intt check (pii p) { if (p.F < 0 || p.F >= n || p.S < 0 || p.S >= n) { return 0; } else { return 1; } } intt par[205][205]; int main() { //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); IO; cin >> n; pii st, en; cin >> st.F >> st.S >> en.F >> en.S; for (intt i = 0; i < n; i++) { for (intt j = 0; j < n; j++) { dis[i][j] = INF; } } dis[st.F][st.S] = 0; queue Q; Q.push (st); while (!Q.empty()) { pii cur = Q.front(); Q.pop(); for (intt k = 0; k < 6; k++) { pii to = {cur.F + dx[k], cur.S + dy[k]}; if (check (to) == 1) { if (dis[to.F][to.S] > dis[cur.F][cur.S] + 1) { par[to.F][to.S] = k; dis[to.F][to.S] = dis[cur.F][cur.S] + 1; Q.push (to); } /*else if (dis[to.F][to.S] == dis[cur.F][cur.S] + 1 && par[to.F][to.S] > k) { par[to.F][to.S] = k; }*/ } } } if (dis[en.F][en.S] == INF) { cout << "Impossible" << endl; return 0; } cout << dis[en.F][en.S] << endl; vi path; pii cur = en; while (cur != st) { path.pb (par[cur.F][cur.S]); pii tmp = cur; cur.F -= dx[par[tmp.F][tmp.S]]; cur.S -= dy[par[tmp.F][tmp.S]]; } while (path.size() > dis[en.F][en.S]) { path.pop_back(); } reverse (all (path)); for (intt i = 0; i < path.size(); i++) { cout << res[path[i]] << " "; } cout << endl; return 0; }