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
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef basic_string<int> BI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(1); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=2010;
int n,m;
int rs[N][27],cs[N][27];
int rst[N],cst[N];
bool vis[2][N],d[N][N];
char s[N][N];
int main() {
	scanf("%d%d",&n,&m);
	rep(i,0,n) {
		scanf("%s",s[i]);
		rep(j,0,m) {
			rs[i][s[i][j]-'A']++;
			rst[i]|=1<<(s[i][j]-'A');
			cs[j][s[i][j]-'A']++;
			cst[j]|=1<<(s[i][j]-'A');
		}
	}
	queue<PII> q;
	rep(i,0,n) if (__builtin_popcount(rst[i])<=1) {
		q.push(mp(0,i));
		vis[0][i]=1;
	}
	rep(i,0,m) if (__builtin_popcount(cst[i])<=1) {
		q.push(mp(1,i));
		vis[1][i]=1;
	}
	vector<array<int,3>> ret;
	while (!q.empty()) {
		auto [u,c]=q.front(); q.pop();
		auto del=[&](int x,int y) {
			if (d[x][y]) return;
			int w=s[x][y]-'A';
			//printf("del %d %d\n",x,y);
			rs[x][w]--;
			cs[y][w]--;
			if (rs[x][w]==0) {
				rst[x]^=(1<<w);
				if (__builtin_popcount(rst[x])==1&&!vis[0][x]) {
					q.push(mp(0,x));
					vis[0][x]=1;
				}
			}
			if (cs[y][w]==0) {
				cst[y]^=(1<<w);
				if (__builtin_popcount(cst[y])==1&&!vis[1][y]) {
					q.push(mp(1,y));
					vis[1][y]=1;
				}
			}
			//puts("cnm");
		};
		if (u==0&&rst[c]==0) continue;
		if (u==1&&cst[c]==0) continue;
		if (u==0) {
			int let=__builtin_ctz(rst[c]);
			ret.pb({0,c,let});
			//VI rr(all(rs[c][let]));
			rep(x,0,m) del(c,x);
		} else {
			int let=__builtin_ctz(cst[c]);
			ret.pb({1,c,let});
			//VI cr(all(cs[c][let]));
			rep(x,0,n) del(x,c);
		}
	}
	printf("%d\n",SZ(ret));
	reverse(all(ret));
	for (auto [ty,c,let]:ret) {
		printf("%c %d %c\n","RK"[ty],c+1,'A'+let);
	}
}