#include #include #include #include #include #include #include using namespace std; int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int n; cin >> n; int is, js, ie, je; cin >> is >> js >> ie >> je; // vector > ex(n, vector(n, false)); vector > > prev(n, vector >(n, make_pair(-1, -1))); queue, int> > q; q.push(make_pair(make_pair(is, js), 0)); prev[is][js].first = -2; vector > moves{{-2,-1}, {-2,1}, {0,2}, {2,1}, {2,-1}, {0, -2}}; vector mnames{"UL", "UR", "R", "LR", "LL", "L"}; while(!q.empty()) { pair, int> p = q.front(); q.pop(); int ic = p.first.first; int jc = p.first.second; int l = p.second; if(ie == ic && je == jc) { cout << l << endl; stack seq; while(prev[ic][jc].first != -2) { int ip = prev[ic][jc].first; int jp = prev[ic][jc].second; seq.push(mnames[find(moves.begin(), moves.end(), make_pair(ic-ip, jc-jp)) - moves.begin()]); ic = ip; jc = jp; } while(!seq.empty()) { cout << seq.top() << " "; seq.pop(); } cout << endl; return 0; } for(pair m: moves) { int in = ic + m.first, jn = jc + m.second; if(in >= 0 && in < n && jc >= 0 && jc < n && prev[in][jn].first == -1) { q.push(make_pair(make_pair(in, jn), l+1)); prev[in][jn] = make_pair(ic,jc); } } } cout << "Impossible" << endl; return 0; }