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
#include<iostream>
#include<string>
#include<vector>

using namespace std;
int n,m;
vector<string>tab;
vector<string>res;
bool row_check(){
    for(int i = 0;i<n;++i){
        char found_color='.';
        for(int j = 0;j<m;++j){
            if(found_color=='.' && tab[i][j]!='.'){
                found_color=tab[i][j];
                continue;
            }
            if(found_color!=tab[i][j] && found_color!='.' && tab[i][j]!='.'){
                found_color='.';
                break;
            }
        }
        if(found_color!='.'){
            for(int j = 0;j<m;++j){
                tab[i][j]='.';
            }
            res.push_back("R "+to_string(i+1)+" "+found_color+"\n");
            return true;
        }
    }
    return false;
}

bool col_check(){
    for(int j = 0;j<m;++j){
        char found_color='.';
        for(int i = 0;i<n;++i){
            if(found_color=='.' && tab[i][j]!='.'){
                found_color=tab[i][j];
                continue;
            }
            if(found_color!=tab[i][j] && found_color!='.' && tab[i][j]!='.'){
                found_color='.';
                break;
            }
        }
        if(found_color!='.'){
            for(int i = 0;i<n;++i){
                tab[i][j]='.';
            }
            res.push_back("K "+to_string(j+1)+" "+found_color+"\n");
            return true;
        }
    }
    return false;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>n>>m;
    tab.resize(n);
    for(int i = 0;i<n;++i){
        cin>>tab[i];
    }
    for(int i = 0;i<n+m;++i){
        if(row_check()){
            continue;
        }    
        if(col_check()){
            continue;
        }  
        break; 
    }
    cout<<res.size()<<"\n";
    for(int i = res.size()-1;i>=0;--i){
        cout<<res[i];
    }
    return 0;
}