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

bool check_horizontal(string s){
	set<char> col;

	for(char c : s){
		col.insert(c);
	}

	if(col.size() == 1 && *col.begin() != '0'){
		return true;
	}else if(col.size() == 2 && (*col.begin() == '0' || *col.end() == '0')){
		return true;
	}else{
		return false;
	}
}

void insert_horizontal(vector<string>& v, int nr, int m){
	for(int i = 0; i < m; i++){
		v[nr][i] = '0';
	}
}


bool check_vertical(vector<string>& v, int column, int n){
	set<char> color;

	for(int i = 0; i < n; i++){
		color.insert(v[i][column]);
	}


	if(color.size() == 1 && *color.begin() != '0'){
		return true;
	}else if(color.size() == 2 && (*color.begin() == '0' || *color.end() == '0')){
		return true;
	}else{
		return false;
	}
}

void insert_vertical(vector<string>& v, int nr, int n){
	for(int i = 0; i < n; i++){
		v[i][nr] = '0';
	}
}


int main(){
	cin.tie(nullptr)->ios::sync_with_stdio(0);

	int n, m; // n - liczba wierszy m - liczba kolumn
	cin >> n >> m;

	vector<string> v(n);

	for(auto& e : v){
		cin >> e;
	}


	vector<pair<char, pair<int, char>>> odp;
	bool found = true;

	while(found){
		found = false;

		for(int i = 0; i < n; i++){
			if(check_horizontal(v[i])){
				found = true;

				char c;

				for(char k : v[i]){
					if(k != '0'){
						c = k;
						break;
					}
				}


				odp.push_back({'R', {i + 1, c}});
				insert_horizontal(v, i, m);
			}
		}

		for(int i = 0; i < m; i++){
			if(check_vertical(v, i, n)){
				found = true;

				char c;

				for(int j = 0; j < n; j++){
					if(v[j][i] != '0'){
						c = v[j][i];
						break;
					}
				}
				odp.push_back({'K', {i + 1, c}});
				insert_vertical(v, i, n);
			}
		}

	}

	cout << odp.size() << "\n";

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