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
#include <bits/stdc++.h>
#define dbg(x) " [" << #x << ": " << (x) << "] "
using namespace std;
using ll = long long;
template<typename A, typename B>
ostream& operator<<(ostream& out, const pair<A,B>& p) {
    return out << "(" << p.first << ", " << p.second << ")";
}
template<typename T>
ostream& operator<<(ostream& out, const vector<T>& c) {
    out << "{";
    for(auto it = c.begin(); it != c.end(); it++) {
        if(it != c.begin()) out << ", ";
        out << *it;
    }
    return out << "}";
}

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

    int n,m;
    cin >> n >> m;
    vector<vector<char>> v(n, vector<char>(m));
    vector<bool> row(n), col(m);
    vector<vector<int>> row_cnt(n, vector<int>(26));
    vector<vector<int>> col_cnt(m, vector<int>(26));
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            cin >> v[i][j];
            row_cnt[i][v[i][j] - 'A']++;
            col_cnt[j][v[i][j] - 'A']++;
        }
    }



    vector<tuple<char, int, char>> ans;
    int x = n, y = m;
    while(x && y) {
        bool found = false;
        for(int i = 0; i < n; i++) {
            if(row[i]) continue;
            for(int j = 0; j < 26; j++) {
                if(row_cnt[i][j] == y) {
                    for(int k = 0; k < m; k++) {
                        if(col[k]) continue;
                        col_cnt[k][v[i][k] - 'A']--;
                    }
                    found = true;
                    row[i] = true;
                    x--;
                    ans.push_back({'R', i + 1, 'A' + j});
                }
            }
        }
        if(found) continue;
        for(int i = 0; i < m; i++) {
            if(col[i]) continue;
            for(int j = 0; j < 26; j++) {
                if(col_cnt[i][j] == x) {
                    for(int k = 0; k < n; k++) {
                        if(row[k]) continue;
                        row_cnt[k][v[k][i] - 'A']--;
                    }
                    col[i] = true;
                    y--;
                    ans.push_back({'K', i + 1, 'A' + j});
                }
            }
        }
    }
    reverse(ans.begin(), ans.end());

    cout << ans.size() << '\n';
    for(auto [a, b, c] : ans) {
        cout << a << " " << b << " " << c << '\n';
    }

    return 0;
}