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
#!/usr/bin/python3

# === wej ===

n, m = input().split()
n, m = int(n), int(m)

t = []
t.append("~" * (m+1))
for i in range(n):
    line = input()
    assert(len(line) == m)
    t.append(list("~" + line))


# === prog ===

moves = []


def ready_x(x):
    letters_set = set()
    for y in range(1, n+1):
        letters_set.add(t[y][x])
    if len(letters_set) == 1:
        letter = letters_set.pop()
        return letter if letter != '.' else None
    elif len(letters_set) == 2:
        letters = sorted(letters_set)
        return letters[1] if letters[0] == '.' else None
    else:
        return None

def ready_y(y):
    letters_set = set()
    for x in range(1, m+1):
        letters_set.add(t[y][x])
    if len(letters_set) == 1:
        letter = letters_set.pop()
        return letter if letter != '.' else None
    elif len(letters_set) == 2:
        letters = sorted(letters_set)
        return letters[1] if letters[0] == '.' else None
    else:
        return None


dalej = True
while dalej:
    dalej = False
    for x in range(1, m+1):
        paint = ready_x(x)
        if paint:
            moves.append(f"K {x} {paint}")
            for y in range(1, n+1):
                t[y][x] = '.'
            dalej = True
    for y in range(1, n+1):
        paint = ready_y(y)
        if paint:
            moves.append(f"R {y} {paint}")
            for x in range(1, m+1):
                t[y][x] = '.'
            dalej = True


# === wyj ===

print(len(moves))
for line in reversed(moves):
    print(line)