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
#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define pii pair<int, int>
#define st first
#define nd second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

const int MAXN = 2'009;

queue<pair<pii, int>> Q;

int cnt1[MAXN][26];
int cnt2[MAXN][26];
bool vis1[MAXN];
bool vis2[MAXN];
int tab[MAXN][MAXN];

int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n, m;
	cin >> n >> m;
	for(int i=0;i<n;i++) {
		for(int j=0;j<m;j++) {
			char c;
			cin >> c;
			tab[i][j] = c-'A';
			cnt1[i][c-'A']++;
			cnt2[j][c-'A']++;
		}
	}
	for(int i=0;i<n;i++) {
		for(int j=0;j<26;j++) {
			if(cnt1[i][j]==m) {
				Q.push({{1, i}, j});
				vis1[i] = true;
			}
		}
	}
	for(int i=0;i<m;i++) {
		for(int j=0;j<26;j++) {
			if(cnt2[i][j]==n) {
				Q.push({{2, i}, j});
				vis2[i] = true;
			}
		}
	}
	vector<pair<pii, int>> V;
	while(sz(Q)) {
		auto [x, y] = Q.front();
		Q.pop();
		V.pb({x, y});
		if(x.st==1) {
			for(int i=0;i<m;i++) {
				cnt2[i][tab[x.nd][i]]--;
				for(int j=0;j<26;j++) {
					cnt2[i][j]++;
					if(cnt2[i][j]==n&&!vis2[i]) {
						Q.push({{2, i}, j});
						vis2[i] = true;
					}
				}
			}
		} else {
			for(int i=0;i<n;i++) {
				cnt1[i][tab[i][x.nd]]--;
				for(int j=0;j<26;j++) {
					cnt1[i][j]++;
					if(cnt1[i][j]==m&&!vis1[i]) {
						Q.push({{1, i}, j});
						vis1[i] = true;
					}
				}
			}
		}
	}
	reverse(all(V));
	cout << sz(V) << "\n";
	for(auto [x, y]:V) {
		if(x.st==1) cout << "R ";
		else cout << "K ";
		cout << x.nd+1 << " ";
		char c = 'A'+y;
		cout << c << "\n";
	}
}