#include using namespace std; typedef long long ll; ll cnt = 0; ll MAX_OP = 1000; bool move(ll &sx, ll &sy, ll ex, ll ey) { ll dx = abs(sx - ex); ll dy = abs(sy - ey); if (cnt + dx + dy > MAX_OP) return false; for (int i = 0; i < dx; ++i) cout << (ex > sx ? "R" : "L") << "\n"; for (int i = 0; i < dy; ++i) cout << (ey > sy ? "D" : "U") << "\n"; cnt += dx + dy; sx = ex; sy = ey; return true; } bool copy(ll x, ll y, ll &num, const vector> &grid) { if (cnt + 1 > MAX_OP) return false; num ^= grid[x][y]; cout << "C\n"; ++cnt; return true; } ll total_score(const vector>& grid) { ll sum = 0; for (const auto &row : grid) { for (ll val : row) sum += val; } return sum; } bool write(ll x, ll y, ll num, vector> &grid) { if (cnt + 1 > MAX_OP) return false; ll before = grid[x][y]; ll after = before ^ num; // 一時的に変更 grid[x][y] = after; ll new_score = total_score(grid); grid[x][y] = before; // 元に戻す // 現状のスコアを計算(注意:頻繁に呼ぶなら高速化要検討) ll old_score = total_score(grid); // スコア増加があれば確定 if (new_score > old_score) { grid[x][y] = after; cout << "W\n"; ++cnt; return true; } // スコア悪化はスキップ return true; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll N, T; cin >> N >> T; vector> grid(N, vector(N)); for (int i = 0; i < N; ++i) for (int j = 0; j < N; ++j) cin >> grid[i][j]; ll s = 0; ll x = 0, y = 0; // 全ビット範囲を処理(0〜19) for (int p = 10; p < 20; ++p) { for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) { // pより上位ビットが立ってたらスキップ bool skip = false; for (int q = 19; q > p; --q) { if (grid[i][j] & (1LL << q)) { skip = true; break; } } if (skip) continue; if (grid[i][j] & (1LL << p)) { if (!move(x, y, i, j)) return 0; if (!copy(x, y, s, grid)) return 0; if (!move(x, y, 0, 0)) return 0; for (int a = 0; a < N; ++a) { for (int b = 0; b < N; ++b) { if ((grid[a][b] & (1LL << p)) == 0) { if (!move(x, y, a, b)) return 0; if (!write(x, y, s, grid)) return 0; } } } if (!move(x, y, i, j)) return 0; if (!copy(x, y, s, grid)) return 0; goto next; } } } next:; } }