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
#include <iostream>
using namespace std;

int n, m;
char plansza[2001][2001];
char row_st[2001], col_st[2001];

int ret_nr;
char ret_RK[4000]; int ret_licz[4000]; char ret_lit[4000];

int main() 
{
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(NULL);
	string s;
	int i, j, rf, cf;
	int takie_same; char litera;
	cin >> n >> m;
	rf = n; cf = m;
	for (i = 0; i < n; i++)
	{
		cin >> s;
		for (j = 0; j < m ; j++) plansza[i][j] = s[j];
	}
	
/*	for (i = 0; i < n; i++)
	{
		for (j = 0; j < m ; j++) cout << plansza[i][j];
		cout << '\n';
	} */
	
	while (rf && cf)
	{
		if (rf) for (i = 0; i < n; i++)
			if (!row_st[i])
			{
				litera = 0;
				for (j = 0; j < m ; j++)
					if(!col_st[j])
					{
//						cout << i << j << '\n';
						if (litera)
						{
							if (litera != plansza[i][j]) break;
						}
						else litera = plansza[i][j];
					}
				if (j == m)
				{
//					cout << "qwe" << '\n';
					ret_RK[ret_nr] = 'R'; ret_licz[ret_nr] = i + 1; ret_lit[ret_nr++] = litera;
					row_st[i] = 1; rf--;
				}
			}
		if (!rf) break;
		if (cf) for (i = 0; i < m; i++)
			if (!col_st[i])
			{
				litera = 0;
				for (j = 0; j < n ; j++)
					if(!row_st[j])
					{
						if (litera)
						{
							if (litera != plansza[j][i]) break;
						}
						else litera = plansza[j][i];
					}
				if (j == n)
				{
					ret_RK[ret_nr] = 'K'; ret_licz[ret_nr] = i + 1; ret_lit[ret_nr++] = litera;
					col_st[i] = 1; cf--;
				}
			}
	}
	
	cout << ret_nr << '\n';
	for (i = ret_nr - 1; i >= 0; i--)
		cout << ret_RK[i] << ' ' << ret_licz[i] << ' ' << ret_lit[i] << '\n';

	return 0;
}