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>
#include <unistd.h>

using namespace std;

int n, m;

vector<vector<int>> board;
vector<vector<int>> row;
vector<vector<int>> col;
vector<string> res;
int to_remove;
const bool _log = false;
void print_board();

void find_uniform_row(){
    for(int i = 1; i <= n; ++i){
        int count = 0;
        int last = 0;
        for(int c = 0; c < row[i].size(); ++c){
            if(row[i][c] > 0){
                last = c;
                count++;
            }
        }
        if(count == 1){
            for(int j = 1; j <= m; ++j){
                if(board[i][j]){
                    row[i][board[i][j]]--;
                    col[j][board[i][j]]--;
                    to_remove--;
                }
                board[i][j] = 0;
            }
            res.push_back("R " + to_string(i) + " " + char('A' + last - 1));
            if(_log){
                print_board();
                cout << std::flush;
                sleep(1);
            }
        }
    }
}

void find_uniform_col(){
    for(int j = 1; j <= m; ++j){
        int count = 0;
        int last = 0;
        for(int c = 0; c < col[j].size(); ++c){
            if(col[j][c] > 0){
                last = c;
                count++;
            }
        }
        if(count == 1){
            for(int i = 1; i <= n; ++i){
                if(board[i][j]){
                    row[i][board[i][j]]--;
                    col[j][board[i][j]]--;
                    to_remove--;
                }
                board[i][j] = 0;
            }
            res.push_back("K " + to_string(j) + " " + char('A' + last - 1));
            if(_log){
                print_board();
                cout << std::flush;
                sleep(1);
            }
        }
    }

}

void print_board() {
    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j <= m; ++j) {
            cout << char('A' + board[i][j] - 1) << " ";
        }
        cout << "\n";
    }
    cout<<"____________________\n";
}

int main(){
	ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
    cin>>n>>m;
    to_remove = n * m;
    
    board.assign(n + 2, vector<int>(m + 1, 0));
    row.assign(n + 2, vector<int>(int('Z' - 'A') + 2, 0));
    col.assign(m + 2, vector<int>(int('Z' - 'A') + 2, 0));

    for(int i = 1; i <= n; ++i){
        for(int j = 1; j <= m; ++j){
            char c;
            cin>>c;
            board[i][j] = c - 'A' + 1;
            row[i][board[i][j]]++;
            col[j][board[i][j]]++;
        }
    }

    while(to_remove > 0){
        find_uniform_row();
        find_uniform_col();
    }

    cout<<res.size()<<"\n";
    for(int i = res.size() - 1; i >= 0; --i){
        cout<<res[i]<<"\n";
    }

	return 0;
}