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
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include <bits/stdc++.h>

typedef long long int lli;

using namespace std;

#define MAX4 10010
#define MAX5 100010
#define MAX6 1000010

#define FOR(n) for (int i = 0; i < n; i++)

using vti = vector<int>;
using vts = vector<string>;

template <typename T> void dbg(T last) { cout << last << "\n"; }

template <typename T, typename... args> void dbg(T current, args... next) {
  cout << current << ' ';
  dbg(next...);
}

template <typename T> void getInput(vector<T> &v, int n, int x = 0) {
  for (int i = x; i < n; i++) {
    cin >> v[i];
  }
}

//-----------------------------------------------------------------------------------------------//

char tab[2001][2001];
set<char> setn1[2001];
set<char> setm1[2001];

map<char, int> tabn1[2001];
map<char, int> tabm1[2001];
map<char, int> tabn2[2001];
map<char, int> tabm2[2001];

struct Output {
  char id_, color_;
  int num_;

  Output(char id, int num, char color) : num_(num), id_(id), color_(color) {}

  friend std::ostream &operator<<(std::ostream &stream, const Output &output) {
    stream << output.id_ << " " << output.num_ << " " << output.color_;
    return stream;
  }
};
void solve() {
  int n, m;
  cin >> n >> m;

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      char c;
      cin >> c;
      tab[i][j] = c;
      tabn1[i][c]++;
      setn1[i].insert(c);
    }
  }

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      char c = tab[i][j];
      tabm1[j][c]++;
      setm1[j].insert(c);
    }
  }
  stack<Output> output;
  while (true) {
    // Remove rows
    vector<Output> tmp;
    for (int i = 1; i <= n; i++) {
      if (setn1[i].size() == 1) {
        tmp.push_back(Output('R', i, *setn1[i].begin()));
        setn1[i].clear();
      }
    }

    for (int i = 1; i <= m; i++) {
      if (setm1[i].size() == 1) {
        tmp.push_back(Output('K', i, *setm1[i].begin()));
        setm1[i].clear();
      }
    }
    // dbg(tmp.size());
    if (tmp.empty()) {
      break;
    }

    for (auto o : tmp) {
      if (o.id_ == 'R') {
        for (int i = 1; i <= m; i++) {
          if (tab[o.num_][i] == o.color_) {
            tab[o.num_][i] = '#';
            tabm1[i][o.color_]--;
            if (tabm1[i][o.color_] == 0) {
              setm1[i].erase(o.color_);
            }
          }
        }
      } else {
        for (int i = 1; i <= n; i++) {
          if (tab[i][o.num_] == o.color_) {
            tab[i][o.num_] = '#';
            tabn1[i][o.color_]--;
            if (tabn1[i][o.color_] == 0) {
              setn1[i].erase(o.color_);
            }
          }
        }
      }
      output.push(o);
    }
  }

  //assert(output.size() <= n + m);
  //assert(output.size() > 0);
  cout << output.size() << "\n";
  while (!output.empty()) {
    auto o = output.top();
    cout << o << "\n";
    output.pop();
  }
}

int main() {
  std::ios::sync_with_stdio(false);

  solve();

  return 0;
}