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
#include <iostream>
#include <vector>
using namespace std;
const int stala=2010;
char tab[stala][stala];
bool o[stala][stala];
int rzad[stala][30];
int kolumna[stala][30];
int ile_rzad[stala];
int ile_kolumna[stala];
vector<pair<int,int> >do_wyrzucenia; //rzad(1),kolumna(2)/nr
vector<char>wyn;
vector<int>wyn2;
vector<char>wyn3;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int x,y;
    cin>>x>>y;
    for(int i=1;i<=x;i++){
        for(int j=1;j<=y;j++){
            cin>>tab[i][j];
        }
    }
    for(int i=1;i<=x;i++){
        for(int j=1;j<=y;j++){
            char a=tab[i][j]-'A';
            if(rzad[i][(int)a]==0){
                ile_rzad[i]++;
            }
            rzad[i][(int)a]++;
            if(kolumna[j][(int)a]==0){
                ile_kolumna[j]++;
            }
            kolumna[j][(int)a]++;
        }
    }
    for(int i=1;i<=x;i++){
        if(ile_rzad[i]==1){
            do_wyrzucenia.push_back({1,i});
        }
    }
    for(int i=1;i<=y;i++){
        if(ile_kolumna[i]==1){
            do_wyrzucenia.push_back({2,i});
        }
    }
    while(!do_wyrzucenia.empty()){
        int x1=do_wyrzucenia.back().first;
        int x2=do_wyrzucenia.back().second;
        do_wyrzucenia.pop_back();
        if(x1==1&&ile_rzad[x2]==1){
            char target='A';
            for(int i=1;i<=y;i++){
                if(o[x2][i]==0){
                    o[x2][i]=1;
                    target=tab[x2][i];
                    rzad[x2][target-'A']--;
                    if(rzad[x2][target-'A']==0){
                        ile_rzad[x2]--;
                        if(ile_rzad[x2]==1){
                            do_wyrzucenia.push_back({1,x2});
                        }
                    }
                    kolumna[i][target-'A']--;
                    if(kolumna[i][target-'A']==0){
                        ile_kolumna[i]--;
                        if(ile_kolumna[i]==1){
                            do_wyrzucenia.push_back({2,i});
                        }
                    }
                }
            }
            wyn.push_back('R');
            wyn2.push_back(x2);
            wyn3.push_back(target);
        }
        else if(x1==2&&ile_kolumna[x2]==1){
            char target='A';
            for(int i=1;i<=x;i++){
                if(o[i][x2]==0){
                    o[i][x2]=1;
                    target=tab[i][x2];
                    rzad[i][target-'A']--;
                    if(rzad[i][target-'A']==0){
                        ile_rzad[i]--;
                        if(ile_rzad[i]==1){
                            do_wyrzucenia.push_back({1,i});
                        }
                    }
                    kolumna[x2][target-'A']--;
                    if(kolumna[x2][target-'A']==0){
                        ile_kolumna[x2]--;
                        if(ile_kolumna[x2]==1){
                            do_wyrzucenia.push_back({2,x2});
                        }
                    }
                }
            }
            wyn.push_back('K');
            wyn2.push_back(x2);
            wyn3.push_back(target);
        }
    }
    cout<<(int)wyn.size()<<"\n";
    for(int i=(int)wyn.size()-1;i>=0;i--){
        cout<<wyn[i]<<" "<<wyn2[i]<<" "<<wyn3[i]<<"\n";
    }

    return 0;
}