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
88
#include<cstdio>
#include<vector>
#include<map>
#include<utility>

using namespace std;

int main() {
    int n, m;
    scanf("%d %d\n", &n, &m);

    vector<map<char, int> > rows;
    vector<map<char, int> > columns;

    for (int i = 0; i < n; i++) {
        map<char, int> row;
        rows.push_back(row);

        for (int j = 0; j < m; j++) {
            char color;
            scanf("%c", &color);

            if (i == 0) {
                map<char, int> column;
                columns.push_back(column);
            }

            rows[i][color]++;
            columns[j][color]++;
        }
        scanf("\n");
    }

    vector<pair<char, pair<char, int> > > results;

    for (int i = 0; i < n + m; i++) {
        for (int j = 0; j < n; j++) {
            if (rows[j].size() == 1) {
                pair<char, int> color = *(rows[j].begin());

                pair<char, int> toRes(color.first, j + 1);
                pair<char, pair<char, int> > res('R', toRes);
                results.push_back(res);

                for (int k = 0; k < m; k++) {
                    if (columns[k][color.first] > 0) {
                        columns[k][color.first]--;
                    }

                    if (columns[k][color.first] == 0) {
                        columns[k].erase(color.first);
                    }
                }

                rows[j].erase(color.first);
            }
        }
        
        for (int j = 0; j < m; j++) {
            if (columns[j].size() == 1) {
                pair<char, int> color = *(columns[j].begin());

                pair<char, int> toRes(color.first, j + 1);
                pair<char, pair<char, int> > res('K', toRes);
                results.push_back(res);

                for (int k = 0; k < n; k++) {
                    if (rows[k][color.first] > 0) {
                        rows[k][color.first]--;
                    }

                    if (rows[k][color.first] == 0) {
                        rows[k].erase(color.first);
                    }
                }

                columns[j].erase(color.first);
            }
        }
    }

    printf("%ld\n", results.size());
    for (int i = results.size() - 1; i >= 0; i--) {
        printf("%c %d %c\n", results[i].first, results[i].second.second, results[i].second.first);
    }

    return 0;
}