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

int tab[2009][2009], lit[4009][40], cnt[4009], wyn[4009];
queue<int> q;
vector<int> v;
string s;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n, m, a;
    char c;
    cin>>n>>m;
    for(int i=1; i<=n; i++)
    {
		cin>>s;
		for(int j=0; j<m; j++)
		{
			a = s[j] - 'A';
			tab[i][j+1] = a;
			if(lit[i][a] == 0) cnt[i]++;
			lit[i][a]++;
			if(lit[j+1+n][a] == 0) cnt[j+1+n]++;
			lit[j+1+n][a]++;
		}
	}
	
	for(int i=1; i<=n+m; i++) q.push(i);
	while(!q.empty())
	{
		a = q.front();
		q.pop();
		if(cnt[a] != 1) continue;
		cnt[a] = 0;
		for(int k=0; k<30; k++)
		{
			if(lit[a][k] > 0)
			{
				wyn[a] = k;
				break;
			}
		}
		for(int i=0; i<30; i++) lit[a][i] = 0;
		v.push_back(a);
		if(a <= n)
		{
			for(int j=1; j<=m; j++)
			{
				if(tab[a][j] == -1) continue;
				lit[j+n][tab[a][j]]--;
				if(lit[j+n][tab[a][j]] == 0)
				{
					cnt[j+n]--;
					if(cnt[j+n] == 1) q.push(j+n);
				}
				tab[a][j] = -1;
			}
		}
		else
		{
			a -= n;
			for(int i=1; i<=n; i++)
			{
				if(tab[i][a] == -1) continue;
				lit[i][tab[i][a]]--;
				if(lit[i][tab[i][a]] == 0)
				{
					cnt[i]--;
					if(cnt[i] == 1) q.push(i);
				}
				tab[i][a] = -1;
			}
		}
	}
	
	cout<<v.size()<<"\n";
	for(int i=v.size()-1; i>=0; i--)
	{
		a = v[i];
		c = wyn[a] + 'A';
		if(a > n) cout<<"K "<<a-n<<" "<<c<<"\n";
		else cout<<"R "<<a<<" "<<c<<"\n";
	}		
    return 0;
}