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
89
90
91
92
93
94
95
96
97
98
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i = a; i < b;++i)
#define pb emplace_back
#define mp make_pair
#define f first
#define s second
using namespace std;
int vis[2005],vis1[2005],tab[2005][2005];
int main(){
  //  cin.tie(0);
  //  ios_base::sync_with_stdio(0);
    int n,m;
    cin>>n >>m;
    int wier[n + 1][27],kol[m + 1][27];
    FOR(i,0,n + 1){
        FOR(j,0,27){
            wier[i][j] = 0;
        }
    }
    FOR(i,0,m + 1){
        FOR(j,0,27){
            kol[i][j] = 0;
        }
    }
    FOR(i,0,n){
        string W;
        cin>>W;
        FOR(j,0,W.size()){
            ++wier[i][W[j] - 'A'];
            ++kol[j][W[j] - 'A'];
            tab[i][j] = W[j] - 'A';
        }
    }
    vector<pair<int,pair<int,int>>> ans;
    int cnt = 0;
    while(cnt != n + m){
       // cout<<cnt <<" " <<"\n";
        FOR(j,0,n){
            if(vis[j] == 0){
                int suma = 0,z = 0;
                FOR(k,0,27){
                    if(wier[j][k] != 0){
                        ++suma;
                        z = k;
                    }
                }
                if(suma == 1){
                    ++cnt;
                    vis[j] = 1;
                    FOR(k,0,m){
                        --kol[k][tab[j][k]];
                    }
                    ans.pb(mp(1,mp(j,z)));
                }
                if(suma == 0){
                    ++cnt;
                    vis[j] = 1;
                }
            }
        }
        if(cnt != n + m){
            FOR(j,0,m){
                if(vis1[j] == 0){
                    int suma = 0,z = 0;
                    FOR(k,0,27){
                        if(kol[j][k] != 0){
                            ++suma;
                            z = k;
                        }
                    }
                    if(suma == 1){
                        ++cnt;
                        vis1[j] = 1;
                        FOR(k,0,n){
                            --wier[k][tab[k][j]];
                        }
                        ans.pb(mp(2,mp(j,z)));
                    }
                    if(suma == 0){
                        ++cnt;
                        vis1[j] = 1;
                    }
                }
            }
        }
    }
    reverse(ans.begin(),ans.end());
    cout<<ans.size() <<"\n";
    for(auto &y : ans){
        if(y.f == 1){
            cout<<"R" <<" ";
        }else{
            cout<<"K" <<" ";
        }
        char k = 'A' + y.s.s;
        cout<<y.s.f + 1 <<" " <<k <<"\n";
    }
}