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
#include<bits/stdc++.h>
using namespace std;
struct Node
{
    char z;
    int ind;
    char z2;
};
char tab[2009][2009];
int ile1[2009][300],ile2[2009][300];
bool zaj1[2009],zaj2[2009];
int n,m;
int main()
{ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            cin>>tab[i][j];
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            ile1[i][tab[i][j]]++;
            ile2[j][tab[i][j]]++;
        }
    }
    vector<Node>odp;
    int nn=n,mm=m;
    while(nn>0&&mm>0)
    {
        int ind=-1;
        char z;
        for(int i=1;i<=n;i++)
        {
            if(zaj1[i]){continue;}
            for(int j='A';j<='Z';j++)
            {
                if(ile1[i][j]==mm){ind=i;z=j;break;}
            }
            if(ind!=-1){break;}
        }
        if(ind!=-1)
        {
            odp.push_back({'R',ind,z});
            for(int j=1;j<=m;j++)
            {
                if(zaj2[j]){continue;}
                ile1[ind][tab[ind][j]]--;
                ile2[j][tab[ind][j]]--;
            }
            nn--;
            zaj1[ind]=1;
            continue;
        }
        for(int i=1;i<=m;i++)
        {
            if(zaj2[i]){continue;}
            for(int j='A';j<='Z';j++)
            {
                if(ile2[i][j]==nn){ind=i;z=j;break;}
            }
            if(ind!=-1){break;}
        }
        if(ind!=-1)
        {
            odp.push_back({'K',ind,z});
            for(int j=1;j<=n;j++)
            {
                if(zaj1[j]){continue;}
                ile1[j][tab[j][ind]]--;
                ile2[ind][tab[j][ind]]--;
            }
            mm--;
            zaj2[ind]=1;
            continue;
        }
    }
    reverse(odp.begin(),odp.end());
    cout<<odp.size()<<'\n';
    for(auto[z,ind,z2] : odp)
    {
        cout<<z<<" "<<ind<<" "<<z2<<'\n';
    }
    return 0;
}