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
//
//  main.cpp
//  lam
//
//  Created by Michał Kowalski on 15/03/2024.
//

#include <iostream>
#include <vector>
using namespace std;

int H,W;
vector<string> B;
vector<vector<int> > S;

void clear_row(int index, char c) {
    if (c == '*') return;
    int len = B[index].length();
    for(int i=0;i<len;++i) B[index][i]='*';
    S.push_back({'R',index+1,c});
}

void clear_col(int index, char c) {
    if (c == '*') return;
    for(int i=0;i<H;++i) B[i][index]='*';
    S.push_back({'K',index+1,c});
}

char can_clear_row(int index) {
    int last_c = '*';
    for (char c: B[index]) {
        if (c == '*') continue;
        if (last_c != c && last_c == '*') {
            last_c = c;
        } else if (last_c != c && last_c != '*') {
            return 0;
        }
    }
    return last_c;
}

char can_clear_column(int index) {
    int last_c = '*';
    for (int i=0;i<H;++i) {
        char c = B[i][index];
        if (c == '*') continue;
        if (last_c != c && last_c == '*') {
            last_c = c;
        } else if (last_c != c && last_c != '*') {
            return 0;
        }
    }
    return last_c;
}

int main() {
    S.reserve(10000);
    scanf("%d %d",&H,&W);
    for (int i=0;i<H;++i) {
        char l[3000];
        scanf("%s",l);
        B.push_back(l);
    }
    vector<int> columns;
    vector<int> rows;
    for(int i=0;i<H;++i) rows.push_back(i);
    for(int i=0;i<W;++i) columns.push_back(i);
    
    while (!rows.empty() && !columns.empty()) {
        
        // for each row
        for (auto it = rows.begin();it<rows.end();) {
            char c = can_clear_row(*it);
            if (c != 0) {
                clear_row(*it, c);
                rows.erase(it);
            } else {
                ++it;
            }
        }
        
        // for each col
        for (auto it = columns.begin();it<columns.end();) {
            char c = can_clear_column(*it);
            if (c != 0) {
                clear_col(*it, c);
                columns.erase(it);
            } else {
                ++it;
            }
        }
    }
    
    // print solution
    printf("%d\n",S.size());
    for(auto it = S.rbegin();it<S.rend();++it) {
        printf("%c %d %c\n",(*it)[0],(*it)[1],(*it)[2]);
    }
    return 0;
}