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
#include <bits/stdc++.h>
using namespace std;

const int N = 2005;
int Board[N][N];

//0 - rows, 1 - columns
bool Removed[N][2];

int Columns[N][27];
int Rows[N][27];

vector<pair<char, pair<int, char>>> Solution;

void Solve(int n, int m)
{
    int blank_cnt = 0;

    while(blank_cnt != n*m) {

        for(int i = 0; i < n; i++) {
            if(Removed[i][0]) 
                continue;

            int col = 0;
            bool work = true;
            for(int j = 1; j <= 26; j++) {
                if(Rows[i][j] > 0 && col != 0) {
                    work = false;
                    break;
                } else if(Rows[i][j] > 0) {
                    col = j;
                }
            }
            if(work && col != 0) {
                Solution.push_back({'R', {i+1, 'A' + (col-1)}});
                Removed[i][0] = true;
                for(int j = 0; j < m; j++) {
                    blank_cnt += (Board[i][j] != 0);

                    Rows[i][Board[i][j]]--;
                    Rows[i][0]++;
                    Columns[j][Board[i][j]]--;
                    Columns[j][0]++;

                    Board[i][j] = 0;
                }
            }
        }
        for(int i = 0; i < m; i++) {
            if(Removed[i][1]) 
                continue;

            int col = 0;
            bool work = true;
            for(int j = 1; j <= 26; j++) {
                if(Columns[i][j] > 0 && col != 0) {
                    work = false;
                    break;
                } else if(Columns[i][j] > 0) {
                    col = j;
                }
            }
            if(work && col != 0) {
                Solution.push_back({'K', {i+1, 'A' + (col-1)}});
                Removed[i][1] = true;
                for(int j = 0; j < n; j++) {
                    blank_cnt += (Board[j][i] != 0);

                    Columns[i][Board[j][i]]--;
                    Columns[i][0]++;
                    Rows[j][Board[j][i]]--;
                    Rows[j][0]++;

                    Board[j][i] = 0;
                }
            }
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n, m;
    cin >> n >> m;
    char x;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            cin >> x;
            Board[i][j] = (x - 'A')+1;
            Columns[j][(x - 'A')+1]++;
            Rows[i][(x - 'A')+1]++;
        }
    }

    Solve(n, m);
    reverse(Solution.begin(), Solution.end());

    cout << Solution.size() << "\n";
    for(auto x : Solution) 
        cout << x.first << " " << x.second.first << " " << x.second.second << "\n";
}