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
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 2137
#endif

const int N = 2020;
const int A = 26;
int n, m;
string s[N];
int cnt[2][N][A];
vector<array<int, 3>> ops;
queue<pair<int, int>> q;

int znajdz(int t, int x) {
  int a = -1;
  for (int i = 0; i < A; i++) {
    if (cnt[t][x][i] > 0) {
      if (a != -1) {
        return -1;
      }
      a = i;
    }
  }
  return a;
}

void rozw(int t, int x) {
  int a = znajdz(t, x);
  if (a == -1) {
    return;
  }
  ops.push_back({t, x, a});
  for (int i = 0; i < A; i++) {
    cnt[t][x][i] = 0;
  }
  if (t == 0) {
    for (int i = 0; i < m; i++) {
      cnt[1][i][s[x][i] - 'A']--;
      if (znajdz(1, i) != -1) {
        q.push({1, i});
      }
    }
  } else {
    for (int i = 0; i < n; i++) {
      cnt[0][i][s[i][x] - 'A']--;
      if (znajdz(0, i) != -1) {
        q.push({0, i});
      }
    }
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    for (int j = 0; j < m; j++) {
      int a = s[i][j] - 'A';
      cnt[0][i][a]++;
      cnt[1][j][a]++;
    }
  }
  for (int i = 0; i < n; i++) {
    rozw(0, i);
  }
  for (int i = 0; i < m; i++) {
    rozw(1, i);
  }
  while (!q.empty()) {
    auto [x, y] = q.front();
    q.pop();
    rozw(x, y);
  }
  reverse(ops.begin(), ops.end());
  cout << ssize(ops) << '\n';
  for (auto [x, y, z] : ops) {
    cout << (x == 0 ? 'R' : 'K') << ' ' << y + 1 << ' ' << char('A' + z) << '\n';
  }
}