1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Author: Kajetan Ramsza
#include "bits/stdc++.h"
using namespace std;

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<typename F, typename S> ostream& operator<<(ostream& os, const pair<F, S> &p) { return os<<"("<<p.first<<", "<<p.second<<")"; }
template<typename T> ostream &operator<<(ostream & os, const vector<T> &v) { os << "{"; typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) { if( it != v.begin() ) os << ", "; os << *it; } return os << "}"; }

void dbg_out() { cerr<<'\n'; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr<<' '<<H; dbg_out(T...); }

#ifdef DEBUG
#define dbg(...) cerr<<"(" << #__VA_ARGS__ <<"):", dbg_out(__VA_ARGS__)
#else
#define dbg(...) 
#endif

const int alf = 27;

int n, m;

vector<vi> board;
vector<bool> rows_vis, cols_vis;
vector<array<int,alf>> rows_cnt, cols_cnt;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	cin>>n>>m;
	board.assign(n, vi(m));
	rep(i,0,n) rep(j,0,m) {
		char c; cin>>c;
		board[i][j] = c - 'A' + 1;
	}
	rows_vis.assign(n, 0);
	cols_vis.assign(m, 0);
	rows_cnt.resize(n);
	cols_cnt.resize(m);
	rep(i,0,n) rep(j,0,m) {
		rows_cnt[i][0] += rows_cnt[i][board[i][j]] == 0;
		rows_cnt[i][board[i][j]]++;
		cols_cnt[j][0] += cols_cnt[j][board[i][j]] == 0;
		cols_cnt[j][board[i][j]]++;
	}
	vector<tuple<int,int,int>> vec;
	rep(num,0,n+m) {
		rep(i,0,n) {
			if(rows_vis[i] || rows_cnt[i][0] != 1) continue;
			int color = 0;
			rep(c,1,alf) if(rows_cnt[i][c] != 0) color = c; 
			vec.push_back({0,i,color});
			rep(j,0,m) {
				if(board[i][j] == 0) continue;
				cols_cnt[j][board[i][j]]--;
				cols_cnt[j][0] -= cols_cnt[j][board[i][j]] == 0;
				board[i][j] = 0;
			}
			rows_vis[i] = true;
			break;
		}
		if(sz(vec) > num) continue;
		rep(j,0,m) {
			if(cols_vis[j] || cols_cnt[j][0] != 1) continue;
			int color = 0;
			rep(c,1,alf) if(cols_cnt[j][c] != 0) color = c; 
			vec.push_back({1,j,color});
			rep(i,0,n) {
				if(board[i][j] == 0) continue;
				rows_cnt[i][board[i][j]]--;
				rows_cnt[i][0] -= rows_cnt[i][board[i][j]] == 0;
				board[i][j] = 0;
			}
			cols_vis[j] = true;
			break;
		}
		if(sz(vec) == num) break;
	}
	cout<<sz(vec)<<'\n';
	reverse(all(vec));
	for(auto [r,i,c] : vec)
		cout<<(r ? 'K' : 'R')<<' '<<i+1<<' '<<char('A' - 1 + c)<<'\n';
}