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

using Counts = array<int, 27>;
using Line = tuple<int, int, Counts>;

int Single(const Counts& c)
{
	int res = -1;
	int count = 0;
	for (int i = 0; i < 27; i++)
		if (c[i] != 0)
		{
			res = i;
			count++;
		}
	if (count == 1)
		return res;
	else
		return -1;
}

int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
	vector<Line> lines;
	{
		vector<Counts> cols, rows;
		rows.resize(n, {0});
		cols.resize(m, {0});
		for (int i = 0; i < n; i++)
		{
			char buf[2048];
			scanf("%s", buf);
			for (int j = 0; j < m; j++)
			{
				int k = buf[j] - 'A';
				rows[i][k]++;
				cols[j][k]++;
			}
		}
		for (int i = 0; i < n; i++)
			lines.emplace_back(0, i, rows[i]);
		for (int j = 0; j < m; j++)
			lines.emplace_back(1, j, cols[j]);
	}
	vector<tuple<int, int, int>> opers;
	while (n > 0 && m > 0)
	{
		for (int i = 0; i < (int) lines.size(); i++)
		{
			auto [type, j, counts] = lines[i];
			int c = Single(counts);
			if (c >= 0)
			{
				lines[i] = lines.back();
				lines.pop_back();
				if (type == 0)
					n--;
				else
					m--;
				for (auto& [tt, _, cc] : lines)
					if (tt != type)
						cc[c]--;
				opers.emplace_back(type, j, c);
				break;
			}
		}
	}
	printf("%ld\n", opers.size());
	ranges::reverse(opers);
	for (auto [type, i, c] : opers)
		printf("%c %d %c\n", (type ? 'K' : 'R'), i + 1, c + 'A');
	return 0;
}