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

#define REP(a, n) for (int a = 0; a < (n); ++a)

using namespace std;

typedef long long LL;

//////////////////////

char tab[2005][2005];
int ile[2][2005][200], W[2];
bool byl[2][2005];
char typ[5000], kolor[5000];
int num[5000];

int main() {
    scanf("%d%d", &W[0], &W[1]);
    REP(y, W[0]) {
        scanf("%s", tab[y]);
        REP(x, W[1]) {
            ile[0][y][tab[y][x]]++;
            ile[1][x][tab[y][x]]++;
        }
    }
    int zz = W[0]+W[1];
    while (zz) {
        REP(t, 2) REP(n, W[t]) if (!byl[t][n]) {
            char k = 'A';
            int i = 0;
            for (char kk = 'A'; kk<='Z'; ++kk)
                if (ile[t][n][kk]) {
                    ++i;
                    k = kk;
                }
            if (i<=1) {
                byl[t][n] = 1;
                --zz;
                typ[zz] = t ? 'K' : 'R';
                num[zz] = n;
                kolor[zz] = k;
                REP(m, W[1-t])
                    ile[1-t][m][t ? tab[m][n] : tab[n][m]]--;
            }
        }
    }
    printf("%d\n", W[0]+W[1]);
    REP(a, W[0]+W[1])
        printf("%c %d %c\n", typ[a], num[a]+1, kolor[a]);
}