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
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long ll;

const int N = 2e3+7;
int n, m;
char plan[N][N];
int cnt_row[N][27], cnt_col[N][27];
vector<pair<char,pair<int,char>>> res;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	
	cin >> n >> m;
	for (int i=0; i<n; i++){
		cin >> plan[i];
		for (int j=0; j<m; j++){
			cnt_row[i][plan[i][j]-'A']++;
			cnt_col[j][plan[i][j]-'A']++;
		}
	}
	
	int sum = 0;
	while (sum < n*m){
		//cout << "--------\n";
		//for (int i=0; i<n; i++){
			//cout << i << ": ";
			//for (int j=0; j<26; j++) cout << cnt_row[i][j] << ' ';
			//cout << '\n';
		//}
		//cout << '\n';
		//for (int i=0; i<m; i++){
			//cout << i << ": ";
			//for (int j=0; j<26; j++) cout << cnt_col[i][j] << ' ';
			//cout << '\n';
		//}
		//cout << '\n';
		
		//czy istnieje rzad o tym samym kolorze
		bool ok = false;
		for (int i=0; i<n; i++){
			int row = 0, cur = 0;
			char c;
			for (int j=0; j<26; j++){
				if (cnt_row[i][j] > 0){
					cur += cnt_row[i][j];
					c = j + 'A';
					row++;
				}
			}
			if (row == 1){
				res.push_back({'R', {i, c}});
				sum += cur;
				cnt_row[i][c-'A'] = 0;
				for (int j=0; j<m; j++){
					cnt_col[j][plan[i][j]-'A']--;
				}
				ok = true;
				break;
			}
		}
		if (ok) continue;
		
		//kolumna o tym samym kolorze
		for (int i=0; i<m; i++){
			int col = 0, cur = 0;
			char c;
			for (int j=0; j<26; j++){
				if (cnt_col[i][j] > 0){
					cur += cnt_col[i][j];
					c = j + 'A';
					col++;
				}
			}
			if (col == 1){
				res.push_back({'K', {i, c}});
				sum += cur;
				cnt_col[i][c-'A'] = 0;
				for (int j=0; j<n; j++){
					cnt_row[j][plan[j][i]-'A']--;
				}
				break;
			}
		}
	}
	
	reverse(res.begin(), res.end());
	cout << (int)res.size() << '\n';
	for (auto [c, p] : res) cout << c << ' ' << p.fi+1 << ' ' << p.se << '\n';
	
    return 0;
}
/*

5 5
AAPAA
APPAA
AAPAA
AAPAA
APPPA

3 3
APA
APA
AAA

*/