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
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for(int i=a; i>=b; --i)
#define pb push_back
#define ssize(v) (int)(v.size())

constexpr int MAX_N=2e3+14, MAX_M=2e3+14;
struct rresS{
    char evt;
    int v;
    char col;
};
int N, M, qtRow[MAX_N][50], qtCol[MAX_M][50];
string inp[MAX_N];
vector<rresS> rres;

void Input(){
    cin>>N>>M;
    FOR(i,0,N-1) cin>>inp[i];
    FOR(i,0,N-1)
        FOR(j,0,M-1)
            ++qtRow[i][inp[i][j]-'A'],++qtCol[j][inp[i][j]-'A'];
}
void Solve(){
    back:
    int cEl=-1;
    FOR(y,0,N-1){
        FOR(i,0,30) if(qtRow[y][i]) {if(cEl==-1) cEl=i; else {cEl=-1; break;}}
        if(cEl!=-1){
            rres.pb({'R',y+1,(char)(cEl+'A')});
            qtRow[y][cEl]=0;
            FOR(j,0,M-1) qtCol[j][cEl]=max(0,qtCol[j][cEl]-1);
            goto back;
        }
    }
    FOR(x,0,M-1){
        FOR(i,0,30) if(qtCol[x][i]) {if(cEl==-1) cEl=i; else {cEl=-1; break;}}
        if(cEl!=-1){
            // cout<<qtCol[x][cEl]<<"\n";
            rres.pb({'K',x+1,(char)(cEl+'A')});
            qtCol[x][cEl]=0;
            FOR(j,0,N-1) qtRow[j][cEl]=max(0,qtRow[j][cEl]-1);
            goto back;
        }
    }
}
void Print(){
    cout<<ssize(rres)<<"\n";
    FORR(i,ssize(rres)-1,0) cout<<rres[i].evt<<" "<<rres[i].v<<" "<<rres[i].col<<"\n";
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);

    Input();
    Solve();
    Print();
}