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
#include <iostream> 
#include <algorithm>
#include <vector>
using namespace std; 


int deleted_row[2001];
int deleted_column[2001];
int w[2001][30];
int k[2001][30];

int main() 
{ 

	int n, m, x;
	char a;
	cin >> n >> m;
	int tab[n][m];

	for(int i = 0; i < n; i++) {
		for(int j = 0; j < m; j++) {
			cin >> a;
			tab[i][j] = int(a) - 64; 
		}
	}

	for(int i = 0; i < n; i++) {
		for(int j = 0; j < m; j++) {
			x = tab[i][j];
			w[i][x] += 1;
			k[j][x] += 1;
		}
	}

	int squares = n*m;
	vector<pair<char, pair<int, int> > > results; 

	while(squares > 0) {
		for(int i = 0; i < n; i++) {
			if(deleted_row[i] == 0) {
				
				int colors = 0, sum = 0, kolor;
				for(int j = 1; j <= 26; j++) {
					if(w[i][j] > 0) { colors += 1; sum += w[i][j]; kolor = j; }
				}
				if(colors == 1) {
				
					squares -= sum;
					for(int j = 0; j < m; j++) {
						k[j][kolor] -= 1; 
					}
					deleted_row[i] = 1; 
					results.push_back(make_pair('R', make_pair(i+1, kolor)));
				}
				
			}
		}
		for(int i = 0; i < m; i++) {
			if(deleted_column[i] == 0) {
				
				int colors = 0, sum = 0, kolor;
				for(int j = 1; j <= 26; j++) {
					if(k[i][j] > 0) { colors += 1; sum += k[i][j]; kolor = j; }
				}
				if(colors == 1) {
				
					squares -= sum;
					for(int j = 0; j < n; j++) {
						w[j][kolor] -= 1; 
					}
					deleted_column[i] = 1; 
					results.push_back(make_pair('K', make_pair(i+1, kolor)));
				}
				
			}
		}
	}

	
	int leng = results.size();
	cout << leng << endl;
	for(int i = leng-1; i >= 0; i--) {
		cout << results[i].first << " " << results[i].second.first << " " << char(results[i].second.second + 64) << endl;
	}
	
    return 0; 
}