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
#include <iostream>

constexpr int MAX_N = 2000;

short cols[MAX_N]['Z'+1], rows[MAX_N]['Z'+1];
char tab[MAX_N][MAX_N+1];

int res_size;
struct {char op; short nr; char color;} res[2*MAX_N];

int main()
{
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(nullptr);

	int n, m;
	std::cin >> n >> m;

	for(int i = 0; i < n; ++i)
	{
		std::cin >> tab[i];
		for(int j = 0; j < m; ++j)
			++rows[i][tab[i][j]], ++cols[j][tab[i][j]];
	}

	bool found = true;
	while(found)
	{
		found = false;
		for(int i = 0; i < n; ++i)
			for(char j = 'A'; j <= 'Z'; ++j)
				if(rows[i][j] == m)
				{
					found = true;
					res[res_size++] = {'R', i+1, j};
					for(char l = 'A'; l <= 'Z'; ++l)
						rows[i][l] = m+1;
					for(int k = 0; k < m; ++k)
						for(char l = 'A'; l <= 'Z'; ++l)
							if(j != l)
								cols[k][l] += 1;
				}
		for(int i = 0; i < m; ++i)
			for(char j = 'A'; j <= 'Z'; ++j)
				if(cols[i][j] == n)
				{
					found = true;
					res[res_size++] = {'K', i+1, j};
					for(char l = 'A'; l <= 'Z'; ++l)
						cols[i][l] = n+1;
					for(int k = 0; k < n; ++k)
						for(char l = 'A'; l <= 'Z'; ++l)
							if(j != l)
								rows[k][l] += 1;
				}
	}

	std::cout << res_size << '\n';
	for(int i = res_size-1; i >= 0; --i)
		std::cout << res[i].op <<' '<< res[i].nr <<' '<< res[i].color << '\n';

	return 0;
}