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
#include <bits/stdc++.h>
using namespace std;
#define rep(a, b) for (int a = 0; a < (b); a++)
#define rep1(a, b) for (int a = 1; a <= (b); a++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = 1e9 + 7;

#define LOCAL false

const int MAX_XY = 2007;
int Y, X;

string board[MAX_XY];

bool rowdone[MAX_XY];
bool coldone[MAX_XY];
map<char, int> rowcnt[MAX_XY];
map<char, int> colcnt[MAX_XY];
vector<pair<pair<char, int>, char>> ans;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    if (LOCAL) {
        ignore=freopen("io/in", "r", stdin);
        ignore=freopen("io/out", "w", stdout);
    }

    cin >> Y >> X;
    rep(y, Y) cin >> board[y];

    rep(y, Y) rep(x, X) {
        rowcnt[y][board[y][x]]++;
        colcnt[x][board[y][x]]++;
    }
    rep(i, X+Y) {
        rep(y, Y) if (rowcnt[y].size() == 1 && !rowdone[y]) {
            char c = rowcnt[y].begin()->first;
            rep(x, X) if (--colcnt[x][c] == 0) colcnt[x].erase(c);
            rowdone[y] = true;
            ans.push_back({{'R', y+1}, c});
        }
        rep(x, X) if (colcnt[x].size() == 1 && !coldone[x]) {
            char c = colcnt[x].begin()->first;
            rep(y, Y) if (--rowcnt[y][c] == 0) rowcnt[y].erase(c);
            coldone[x] = true;
            ans.push_back({{'K', x+1}, c});
        }
    }

    cout << ans.size() << '\n';
    for (int i = (int)ans.size()-1; i >= 0; i--) cout << ans[i].first.first << ' ' << ans[i].first.second << ' ' << ans[i].second << '\n';
    
    return 0;
}