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
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include<bits/stdc++.h>
using namespace std;

typedef pair<char, pair<int, int>> pcii;
#define st first
#define nd second.first
#define rd second.second

int main(){
    int n, m;
    cin>>n>>m;

    vector<vector<int>> r(n, vector<int>(27, 0));
    vector<vector<int>> c(m, vector<int>(27, 0));

    vector<pcii> q;

    string s;

    for(int i = 0; i < n; i++){
        cin>>s;

        for(int j = 0; j < m; j++){
            r[i][s[j]-'A'+1]++;
            c[j][s[j]-'A'+1]++;
        }
    }

    for(int i = 0; i < n; i++){
        for(int j = 1; j < 27; j++){
            if(r[i][0] + r[i][j] == m and r[i][j] > 0){
                q.push_back({'R', {i, j}});
                r[i][j] = 0;
                r[i][0] = m;

                for(int k = 0; k < m; k++){
                    c[k][j]--;
                    c[k][0]++;
                }
            }
        }
    }

    for(int i = 0; i < m; i++){
        for(int j = 1; j < 27; j++){
            if(c[i][0] + c[i][j] == n and c[i][j] > 0){
                q.push_back({'K', {i, j}});
                c[i][j] = 0;
                c[i][0] = n;

                for(int k = 0; k < n; k++){
                    r[k][j]--;
                    r[k][0]++;
                }
            }
        }
    }

    // for(int i = q.size()-1; i >= 0; i--){
    //     cout<<q[i].st<<" "<<q[i].nd+1<<" "<<(char)(q[i].rd+'A'-1)<<"\n";
    // }

    for(int f = 0; f < q.size(); f++){
        for(int i = 0; i < n; i++){
            for(int j = 1; j < 27; j++){
                if(r[i][0] + r[i][j] == m and r[i][j] > 0){
                    q.push_back({'R', {i, j}});
                    r[i][j] = 0;
                    r[i][0] = m;
    
                    for(int k = 0; k < m; k++){
                        c[k][j]--;
                        c[k][0]++;
                    }
                }
            }
        }
    
        for(int i = 0; i < m; i++){
            for(int j = 1; j < 27; j++){
                if(c[i][0] + c[i][j] == n and c[i][j] > 0){
                    q.push_back({'K', {i, j}});
                    c[i][j] = 0;
                    c[i][0] = n;
    
                    for(int k = 0; k < n; k++){
                        r[k][j]--;
                        r[k][0]++;
                    }
                }
            }
        }
    }

    cout<<q.size()<<"\n";
    for(int i = q.size()-1; i >= 0; i--){
        cout<<q[i].st<<" "<<q[i].nd+1<<" "<<(char)(q[i].rd+'A'-1)<<"\n";
    }

    // cout<<"r\n";
    // for(int i = 0; i < n; i++){
    //     for(int j = 0; j < 27; j++){
    //         cout<<r[i][j]<<" ";
    //     }
    //     cout<<"\n";
    // }

    // cout<<"c\n";
    // for(int i = 0; i < m; i++){
    //     for(int j = 0; j < 27; j++){
    //         cout<<c[i][j]<<" ";
    //     }
    //     cout<<"\n";
    // }
}