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


int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector <vector <int>> h(n, vector <int> ('Z'-'A'+1));
    vector <vector <int>> w(m, vector <int> ('Z'-'A'+1));
    vector <vector <int>> a(n, vector <int> (m));
    for(int i = 0; i < n; i++)
        for(int j = 0; j < m; j++)
    {
        char x;
        cin >> x;
        a[i][j] = x - 'A';
        h[i][a[i][j]]++;
        w[j][a[i][j]]++;
    }
    bool flag = 1;
    stack <string> ans;
    while(flag){
        flag = 0;
        for(int j = 0; j < n; j++)
        {
            int cnt = 0;
            int ni = 0;
            for(int i = 0; i < 'Z'-'A'+1; i++){
                if(h[j][i] > 0){
                    cnt++;
                    ni = i;
                }
            }

            if(cnt == 1)
            {
                flag = 1;
                ans.push("R " + to_string(j+1)+ " " + (char)('A'+ni) + "\n");
                h[j][ni] = 0;
                for(auto &g: w)
                    g[ni]--;
            }

        }
        for(int j = 0; j < m; j++)
        {
            int cnt = 0;
            int ni = 0;
            for(int i = 0; i < 'Z'-'A'+1; i++){
                if(w[j][i] > 0){
                    cnt++;
                    ni = i;
                }
            }
            if(cnt == 1)
            {
                flag = 1;
                ans.push("K " + to_string(j+1) + " " + (char)('A'+ni) + "\n");
                w[j][ni] = 0;
                for(auto &g: h)
                    g[ni]--;
            }
        }
    }
    cout << ans.size() <<  endl;
    while(!ans.empty()){
        cout << ans.top();
        ans.pop();
    }
    return 0;
}