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
#include<bits/stdc++.h>
using namespace std;
constexpr int MAXN = 2e3+4;
char pla[MAXN][MAXN];
bitset<MAXN> wie, kol;
int ileW[MAXN][30], ileK[MAXN][30], usuW[30], usuK[30];
void wypisz(int n, int m) {
    cout << "--------------------------\n";
    for(int i = 0 ; i < n ; ++i) {
      for(int j = 0; j < m; ++j) cout << pla[i][j] << ' ';
      cout << '\n';
    }
    cout << "--------------------------\n";
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<string> odp;
  for(int i = 0; i < n; ++i) 
    for(int j = 0; j < m; ++j) {
      cin >> pla[i][j];
      ileW[i][pla[i][j]-'A']++;
      ileK[j][pla[i][j]-'A']++;
    }

  int it = 0;
  while(it < n + m) {
    for(int i = 0; i < n; ++i) {
      if(wie[i]) continue;
      int ile = 0;
      char kolor;
      for(int x = 0; x < 30; ++x) {
        if(ileW[i][x]-usuW[x] > 0) {
          ile++;
          kolor = char('A'+x);
        }
        if(ile > 1) break;
      }
      if(ile == 1) {
        wie[i] = 1;
        usuK[kolor-'A']++;
        string a = "R " + to_string(i+1) + " " + kolor; 
        odp.push_back(a);
      }
    }
    
    
    for(int i = 0; i < m; ++i) {
      if(kol[i]) continue;
      int ile = 0;
      char kolor;
      for(int x = 0; x < 30; ++x) {
        if(ileK[i][x]-usuK[x] > 0) {
          ile++;
          kolor = char(x+'A');
        }
        if(ile > 1) break;

      }
      if(ile == 1) {
        kol[i] = 1;
        usuW[kolor-'A']++;
        string a = "K " + to_string(i+1) + " " + kolor; 
        odp.push_back(a);
      }
    }

    //wypisz(n, m);
    it++;
  }
  cout << odp.size() << '\n';
  while(odp.size()) {
    cout << odp.back() << '\n';
    odp.pop_back();
  }
}