#include using namespace std; using ll = long long; // ===== XOR Basis (20-bit) ===== struct XorBasis { static const int B = 20; int v[B]; vector mask[B]; XorBasis(){ memset(v,0,sizeof(v)); } void add(int x, const vector& cells){ vector c = cells; for(int b=B-1;b>=0;--b){ if(((x>>b)&1)==0) continue; if(!v[b]){ v[b]=x; mask[b]=c; return; } x ^= v[b]; // symmetric diff of sorted vectors vector a = mask[b], res; res.reserve(c.size()+a.size()); sort(c.begin(),c.end()); sort(a.begin(),a.end()); size_t i=0,j=0; while(i> build(int target) const{ int t=target, made=0; vector sel; for(int b=B-1;b>=0;--b){ if(((t>>b)&1)==0) continue; if(!v[b]) continue; t ^= v[b]; made ^= v[b]; vector a = mask[b], res; res.reserve(sel.size()+a.size()); sort(sel.begin(),sel.end()); sort(a.begin(),a.end()); size_t i=0,j=0; while(i& A, int s){ ll sum=0; for(int x:A){ int y=x^s; sum += (y>x?y:x);} return sum; } // greedy route over specified ids (0..NN-1). start at (r,c) and mutate them. emit opch for each cell visited in order. static void visit_cells(int N, int &r, int &c, const vector& ids, vector& ops, char opch){ vector used(ids.size(),0); int cur_r=r, cur_c=c; for(size_t done=0; donerr){ ops.push_back('U'); --cur_r; } while(cur_ccc){ ops.push_back('L'); --cur_c; } ops.push_back(opch); } r=cur_r; c=cur_c; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N,T; if(!(cin>>N>>T)) return 0; // N=10, T=1000 const int NN=N*N; vector> A2(N, vector(N)); for(int i=0;i>A2[i][j]; vector board(NN); for(int i=0;i ops; ops.reserve(2000); int r=0,c=0; // current pos (0-indexed) int curS = 0; auto start = chrono::steady_clock::now(); const double TL = 1.85; // seconds safe margin while(true){ if((int)ops.size() > T-200) break; // spare double t = chrono::duration(chrono::steady_clock::now()-start).count(); if(t>TL) break; // base sum ll baseSum=0; for(int v:board) baseSum+=v; // exhaustive best s on current board int targetS=-1; ll bestGain=0; for(int s=0;s<(1<<20);++s){ ll tot=0; for(int x:board){ int y=x^s; tot += (y>x?y:x);} ll g=tot-baseSum; if(g>bestGain){bestGain=g; targetS=s;} } if(bestGain<=0) break; // build basis from current board XorBasis B; for(int i=0;i{idx}); } int diff = curS ^ targetS; auto [diffReal, needC] = B.build(diff); int newS = curS ^ diffReal; // decide which cells to W vector wlist; wlist.reserve(NN); ll afterSum=0; for(int id=0; ida){ wlist.push_back(id); afterSum+=b; } else afterSum+=a; } if(afterSum <= baseSum) break; // simulate op count to check T size_t need_ops = ops.size(); // rough path cost: greedy path length <= manhattan bound: (#C + #W)*5 avg // We'll just trust T check after emitting; if exceed, break before printing final // emit C if(!needC.empty()) visit_cells(N, r, c, needC, ops, 'C'); curS = newS; // emit W if(!wlist.empty()) visit_cells(N, r, c, wlist, ops, 'W'); // update board for(int id: wlist) board[id] ^= curS; } if((int)ops.size() > T) ops.resize(T); for(char ch: ops) cout<