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
#include <cstdio>
#include <algorithm>
#include <tuple>
#include <vector>
#include <iostream>

using namespace std;
#define MAX 2010
#define D(x)

int n,m;
char PL[MAX][MAX];

int col[MAX][27];
int wie[MAX][27];
int col_n=0, wie_n=0;

vector<tuple<char, int, char>> r;

void printPL() {
    for(int i=0;i<n;i++) {
        for(int j=0;j<m;j++) {
            printf("%c", PL[i][j]);
        }
        printf("\n");
    }

}

int find(int col[][27], int m, char znak) {
    for(int i=0;i<m;i++) {
        int zer = 0;
        char cc;
        for(int c=1;c<27;c++) {
            if (col[i][c] == 0) zer++;
            else cc = c;
        }
        D(cout << znak << " " << i << " " << zer << "\n");
        if (zer == 25) {
            col[i][cc] = 0;
            r.emplace_back(znak, i+1, cc+'@');
            return i;
        }
    }
    return -1;
}

int main() {
    scanf("%d %d", &n, &m);
    for(int i=0;i<n;i++)
        scanf(" %s ", PL[i]);
    
    for(int i=0;i<n;i++) {
        for(int j=0;j<m;j++) {
            col[j][PL[i][j]-'@']++;
            wie[i][PL[i][j]-'@']++;
        }
    }
    col_n = m;
    wie_n = n;
    while(col_n*wie_n>0) {
        int pos = find(col, m, 'K');
        if(pos>=0) {
            for(int i=0;i<n;i++) {
                wie[i][PL[i][pos]-'@']--;
                PL[i][pos] = '@';
            }
            col_n--;
            D(printPL());
        }
        pos = find(wie, n, 'R');
        if(pos>=0) {
            for(int j=0;j<m;j++) {
                col[j][PL[pos][j]-'@']--;
                PL[pos][j] = '@';                
            }
            wie_n--;
            D(printPL());
        }
    }
    cout << r.size() << "\n";
    reverse(r.begin(), r.end());
    for(auto v: r) {
        cout << get<0>(v) << " " << get<1>(v) << " " << get<2>(v) << "\n";
    }
}