#include using namespace std; using ll = long long; using ld = long double; #define rep(i,n) for(auto i=0;i<(n);i++) #define repd(i,n) for(auto i=(n)-1;i>=0;i--) #define rep1(i,n) for(auto i=1;i<=(n);i++) #define rep_lt(i,j,n) for(auto i=(j);i<(n);i++) void printd(ld x){cout< void vcout(const Vec& v){ for(auto &e:v) cout< void vvcout(const Vec& v){ for(auto &r:v){ for(auto &e:r) cout< inline void chmax(T& a,const U& b){ if(a inline void chmin(T& a,const U& b){ if(a>b) a=b; } struct FastIO{ FastIO(){ ios::sync_with_stdio(false); cin.tie(nullptr);} } fastio; void YN(bool s){ cout<<(s?"Yes\n":"No\n"); } void CY(bool s){ if(s){ cout<<"Yes\n"; exit(0);} } void CN(bool s){ if(s){ cout<<"No\n"; exit(0);} } void Cm1(bool s){ if(s){ cout<<-1<<"\n"; exit(0);} } const ll INF = (ll)4e18; #define all(p) begin(p), end(p) #define rall(p) rbegin(p), rend(p) #define fi first #define se second // ===== XOR Basis (20-bit) ===== struct XorBasis { static const int B = 20; int v[B]; // basis value bitset<128> used[B]; // cells that form this vector XorBasis(){ memset(v,0,sizeof(v)); } void add(int x, const bitset<128>& bs){ bitset<128> c = bs; for(int b=B-1;b>=0;--b){ if(((x>>b)&1)==0) continue; if(v[b]==0){ v[b]=x; used[b]=c; return; } x ^= v[b]; c ^= used[b]; } } // build target -> {built_value, cells_bitset} pair> build(int target) const { int t = target, made = 0; bitset<128> sel; sel.reset(); for(int b=B-1;b>=0;--b){ if(((t>>b)&1)==0) continue; if(v[b]==0) continue; // cannot set t ^= v[b]; made ^= v[b]; sel ^= used[b]; } return {made, sel}; } }; // Score for a fixed s (no operations counted, purely value) static inline ll score_with_s(const vector>& A, int s){ ll sum = 0; int n = (int)A.size(); rep(i,n) rep(j,n){ int x = A[i][j]; int y = x ^ s; sum += max(x,y); } return sum; } // movement helper static inline void move_to(int &r,int &c,int tr,int tc, vector& ops){ while(rtr){ ops.push_back('U'); --r; } while(ctc){ ops.push_back('L'); --c; } } int main(){ int N,T; if(!(cin>>N>>T)) return 0; vector> A(N, vector(N)); rep(i,N) rep(j,N) cin>>A[i][j]; // ---------- Candidate s0: your sequential greedy ---------- int s0 = 0; rep(i,N) rep(j,N){ if(s0 < (s0 ^ A[i][j])) s0 ^= A[i][j]; } // ---------- Candidate s1: per-bit gain max ---------- int s1_target = 0; for(int b=0;b<20;b++){ int cnt0=0,cnt1=0; rep(i,N) rep(j,N){ if((A[i][j]>>b)&1) cnt1++; else cnt0++; } if(cnt0 > cnt1) s1_target |= (1< bs; bs.reset(); bs.set(i*N + j); B.add(A[i][j], bs); } auto [s0_real, cells0] = B.build(s0); auto [s1_real, cells1] = B.build(s1_target); ll sc0 = score_with_s(A, s0_real); ll sc1 = score_with_s(A, s1_real); // choose better (non-decreasing guarantee vs s0) int S = s0_real; // final s bitset<128> needC = cells0; // cells to C if(sc1 > sc0){ S = s1_real; needC = cells1; } // ---------- Ops construction ---------- vector ops; int r=0,c=0; // current pos (0-index) // 1st pass: snake traversal to perform all required C (order doesn't matter) vector> snake; snake.reserve(N*N); for(int i=0;i=0;j--) snake.emplace_back(i,j); } } if(!snake.empty()){ move_to(r,c,snake[0].fi,snake[0].se,ops); for(size_t idx=0; idx0){ move_to(r,c,rr,cc,ops); } int x = A[rr][cc]; if( (x ^ S) > x ) ops.push_back('W'); } } // Safety: if somehow exceeded, trim (should not happen) if((int)ops.size() > T){ // fallback: output nothing (valid but zero score) -> but better: cut // However cutting may break validity. In practice we shouldn't exceed. ops.resize(T); } for(char ch: ops) cout<