#include namespace { #pragma GCC diagnostic ignored "-Wunused-function" #include #pragma GCC diagnostic warning "-Wunused-function" using namespace std; using namespace atcoder; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) template bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; } template bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; } using ll = long long; using P = pair; using VI = vector; using VVI = vector; using VL = vector; using VVL = vector; using A = array; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; int a[10][10]{}, b[10][10]{}; rep(i, n) rep(j, n) cin >> a[i][j], a[i][j]--; rep(i, n) rep(j, n) cin >> b[i][j], b[i][j]--; vector> hist; A pr, pc; rep(i, 10) pr[i] = i, pc[i] = i; vector

ans; auto dfs = [&](auto&& self, int rest) -> void { bool is_same = [&]() { rep(i, n) rep(j, n) if (a[pr[i]][pc[j]] != b[i][j]) return false; return true; }(); if (is_same) { while (hist.size()) { auto [rc, now, p] = hist.back(); hist.pop_back(); int cnt = 1; bool visited[10]{}; rep(i, n) if (!visited[i]) { int c = 0; while (!visited[i]) visited[i] = true, c++, i = p[i]; cnt = lcm(c, cnt); } A inv; rep(i, n) inv[p[i]] = i; rep(_, cnt - 1) { ans.emplace_back(rc, now); now = inv[now]; } } cout << ans.size() << '\n'; for (auto [rc, i] : ans) { cout << "RC"[rc] << ' ' << i + 1 << '\n'; } exit(0); } if (rest == 0) return; rep(i, n) { A npr{}; rep(j, n) npr[a[pr[i]][pc[j]]] = j; auto pre = pr; rep(i, n) pr[i] = pre[npr[i]]; hist.emplace_back(0, a[pre[i]][pc[i]], npr); self(self, rest - 1); hist.pop_back(); pr = pre; } rep(j, n) { A npc{}; rep(i, n) npc[a[pr[i]][pc[j]]] = i; auto pre = pc; rep(j, n) pc[j] = pre[npc[j]]; hist.emplace_back(1, a[pr[j]][pre[j]], npc); self(self, rest - 1); hist.pop_back(); pc = pre; } }; dfs(dfs, k); assert(false); }