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
#include <iostream>
#include <map>
#include <stack>

using namespace std;

struct out {
  char type;
  int id;
  char color;
};

char t[2005][2005];
map<int, bool> visr;
map<int, bool> visk;

stack<out> res;

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

  int n, m;
  cin >> n >> m;

  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> t[i][j];
    }
  }

  int prs;
  do {
    prs = res.size();

    // rows
    for (int row = 0; row < n; ++row) {
      if (visr[row]) continue;

      char color = visk[0] ? '-' : t[row][0];
      for (int col = 1; col < m; ++col) {
        if (!visk[col] && color != t[row][col] && color != '-') {
          color = '-';
          break;
        }

        color = visk[col] ? color : t[row][col];
      }

      if (color != '-') {
        res.push({'R', row + 1, color});
        visr[row] = true;
      }
    }

    // cols
    for (int col = 0; col < m; ++col) {
      if (visk[col]) continue;

      char color = visr[0] ? '-' : t[0][col];
      for (int row = 1; row < n; ++row) {
        if (!visr[row] && color != t[row][col] && color != '-') {
          color = '-';
          break;
        }

        color = visr[row] ? color : t[row][col];
      }

      if (color != '-') {
        res.push({'K', col + 1, color});
        visk[col] = true;
      }
    }
  } while(prs != res.size());


  cout << res.size() << "\n";
  while(!res.empty()) {
    out x = res.top();
    res.pop();

    cout << x.type << " " << x.id << " " << x.color << "\n";
  }

  return 0;
}