#include using namespace std; typedef long long ll; const int N = 500 + 3; const int C = 20; ll a[N][N], b[N][N], b_col[N][N], r[N], c[N]; ll a_col[N][N], temp[N]; int m, n, p; clock_t timer = clock(); vector> ans; inline bool time_left(){ return (((float)clock() - (float)timer) / (float)CLOCKS_PER_SEC <= (float)4.5); } void rotate_row(int row, int times){ for(int i = 1; i <= m; ++i) temp[i] = a[row][i]; for(int i = 1; i <= m; ++i){ int idx = i - times; if(idx < 1) idx += m; a[row][i] = temp[idx]; } } void rotate_col(int col, int times){ for(int i = 1; i <= n; ++i) temp[i] = a_col[col][i]; for(int i = 1; i <= n; ++i){ int idx = i - times; if(idx < 1) idx += n; a_col[col][i] = temp[idx]; } } void rotate_row(int row){ int prev = a[row][m]; for(int i = m; i >= 2; --i) a[row][i] = a[row][i - 1]; a[row][1] = prev; } void rotate_col(int col){ int prev = a_col[col][n]; for(int j = n; j >= 2; --j) a_col[col][j] = a_col[col][j - 1]; a_col[col][1] = prev; } ll eval_row(int row, ll mn){ ll ans = 0; for(int i = 1; i <= m && ans < mn; ++i) ans += a[row][i] * b[row][i]; return ans; } ll eval_col(int col, ll mn){ ll ans = 0; for(int i = 1; i <= n && ans < mn; ++i) ans += a_col[col][i] * b_col[col][i]; return ans; } bool try_to_improve_row(int row){ if(!p || !time_left()) return false; ll mn = eval_row(row, LLONG_MAX), idx = m; if(mn <= r[row]) return false; for(int i = 1; i <= m; ++i){ rotate_row(row); ll curr = eval_row(row, mn - r[row]) + r[row]; if(curr < mn){ mn = curr; idx = i; } } if(idx == m) return false; rotate_row(row, idx); ans.push_back({1, row, m - (int)idx}); --p; return true; } bool try_to_improve_col(int col){ if(!p || !time_left()) return false; ll mn = eval_col(col, LLONG_MAX), idx = n; if(mn <= c[col]) return false; for(int i = 1; i <= n; ++i){ rotate_col(col); ll curr = eval_col(col, mn - c[col]) + c[col]; if(curr < mn){ mn = curr; idx = i; } } if(idx == n) return false; rotate_col(col, idx); ans.push_back({2, col, n - (int)idx}); --p; return true; } void mode_col(){ for(int i = 1; i <= n; ++i) for(int j = 1; j <= m; ++j) a_col[j][i] = a[i][j]; } void mode_row(){ for(int i = 1; i <= n; ++i) for(int j = 1; j <= m; ++j) a[i][j] = a_col[j][i]; } bool improve(){ bool ok = false; for(int i = 1; i <= n; ++i) ok |= try_to_improve_row(i); mode_col(); for(int j = 1; j <= m; ++j) ok |= try_to_improve_col(j); mode_row(); return ok; } void solve(){ while(p && time_left()) if(!improve()) break; } struct State{ int a[11][11], p; vector> ans; ll curr_score; State(){} void init(){ curr_score = 0; for(int i = 1; i <= n; ++i) for(int j = 1; j <= m; ++j){ a[i][j] = ::a[i][j]; curr_score += a[i][j] * b[i][j]; } p = ::p; } void rotate_row_small(int row, int times){ for(int i = 1; i <= m; ++i) temp[i] = a[row][i]; for(int i = 1; i <= m; ++i){ int idx = i - times; if(idx < 1) idx += m; a[row][i] = temp[idx]; } } void rotate_col_small(int col, int times){ for(int i = 1; i <= n; ++i) temp[i] = a[i][col]; for(int i = 1; i <= n; ++i){ int idx = i - times; if(idx < 1) idx += n; a[i][col] = temp[idx]; } } void rotate_row_small(int row){ int prev = a[row][m]; for(int i = m; i >= 2; --i) a[row][i] = a[row][i - 1]; a[row][1] = prev; } void rotate_col_small(int col){ int prev = a[n][col]; for(int j = n; j >= 2; --j) a[j][col] = a[j - 1][col]; a[1][col] = prev; } ll eval_row_small(int row){ ll ans = 0; for(int i = 1; i <= m; ++i) ans += a[row][i] * b[row][i]; return ans; } ll eval_col_small(int col){ ll ans = 0; for(int i = 1; i <= n; ++i) ans += a[i][col] * b[i][col]; return ans; } friend bool operator<(const State &l, const State &r){ return l.curr_score < r.curr_score; } }; void solve_small(){ static State st[C]; for(int i = 0; i < C; ++i) st[i].init(); while(st[0].p && time_left()){ priority_queue pq; for(int i = 0; i < C; ++i){ st[i].p--; pq.push(st[i]); if(pq.size() > C) pq.pop(); for(int j = 1; j <= n; ++j){ st[i].curr_score += r[j]; for(int k = 1; k <= m; ++k){ st[i].curr_score -= st[i].eval_row_small(j); st[i].rotate_row_small(j); st[i].curr_score += st[i].eval_row_small(j); st[i].ans.push_back({1, j, m - k}); pq.push(st[i]); if(pq.size() > C) pq.pop(); st[i].ans.pop_back(); } st[i].curr_score -= r[j]; } for(int j = 1; j <= m; ++j){ st[i].curr_score += c[j]; for(int k = 1; k <= n; ++k){ st[i].curr_score -= st[i].eval_col_small(j); st[i].rotate_col_small(j); st[i].curr_score += st[i].eval_col_small(j); st[i].ans.push_back({2, j, n - k}); pq.push(st[i]); if(pq.size() > C) pq.pop(); st[i].ans.pop_back(); } st[i].curr_score -= c[j]; } st[i].p++; } for(int i = C - 1; i >= 0; --i){ st[i] = pq.top(); pq.pop(); } } ans = st[0].ans; } void read(){ ios::sync_with_stdio(false); cin.tie(NULL); freopen("movethematrix.in", "r", stdin); freopen("movethematrix.out", "w", stdout); cin >> n >> m >> p; for(int i = 1; i <= n; ++i) cin >> r[i]; for(int j = 1; j <= m; ++j) cin >> c[j]; for(int i = 1; i <= n; ++i) for(int j = 1; j <= m; ++j) cin >> a[i][j]; for(int i = 1; i <= n; ++i) for(int j = 1; j <= m; ++j) cin >> b[i][j]; for(int i = 1; i <= n; ++i) for(int j = 1; j <= m; ++j) b_col[j][i] = b[i][j]; } void write(){ cout << ans.size() << "\n"; for(auto [type, idx, k]: ans){ if(type == 1) cout << "R "; else cout << "C "; cout << idx << " " << k << "\n"; } } int main(){ read(); if(max(n, m) > 10) solve(); else solve_small(); write(); } /* 2 2 2 1 1 1 1 4 0 0 4 4 4 4 0 */