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
115
116
117
118
119
120
121
122
123
124
125
126
// clang-format off
#include <algorithm>
#include<bits/stdc++.h>
#include <string>
using namespace std;
#define ll long long
#define ssize(x) int(x.size())
template<class A,class B>auto&operator<<(ostream&o,pair<A,B>p){return o<<'('<<p.first<<", "<<p.second<<')';}
template<typename T,typename = typename enable_if<!is_same<T,string>::value>::type>
auto operator<<(ostream&o,T x)->decltype(x.end(),o){o<<'{';int i=0;for(auto e:x)o<<(", ")+2*!i++<<e;return o<<'}';}
#ifdef DEBUG
#define debug(x...) cerr<<"["#x"]: ",[](auto...$){((cerr<<$<<"; "),...);}(x),cerr<<'\n'
#else
#define debug(...) {}
#endif
// clang-format on

char board[2007][2007];
int char_cnt_row[2007][27];
int char_cnt_col[2007][27];
bitset<2007> is_del_r;
bitset<2007> is_del_c;

vector<string> ans;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n, m, found, rcnt = 0, ccnt = 0;
    char cc;
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            cin >> cc;
            board[i][j] = cc;
            char_cnt_row[i][cc - 'A']++;
            char_cnt_col[j][cc - 'A']++;
        }
    }

    for (int it = 0; it < n + m; it++)
    {
        if (rcnt == n || ccnt == m)
            break;
        for (int r = 1; r <= n; r++)
        {
            if (is_del_r[r])
                continue;
            found = -1;
            for (int l = 0; l < 26; l++)
            {
                if (!char_cnt_row[r][l])
                    continue;
                if (found == -1)
                    found = l;
                else
                {
                    found = -1;
                    break;
                }
            }
            if (found != -1)
            {
                is_del_r[r] = 1;
                for (int c = 1; c <= m; c++)
                {
                    if (board[r][c] == '.')
                        continue;
                    char_cnt_col[c][found]--;
                    board[r][c] = '.';
                }
                cc = 'A' + found;
                ans.push_back("R " + to_string(r) + " " + cc);
                rcnt++;
                break;
            }
        }
        if (found != -1)
            continue;
        for (int c = 1; c <= m; c++)
        {
            if (is_del_c[c])
                continue;
            found = -1;
            for (int l = 0; l < 26; l++)
            {
                if (!char_cnt_col[c][l])
                    continue;
                if (found == -1)
                    found = l;
                else
                {
                    found = -1;
                    break;
                }
            }
            if (found != -1)
            {
                is_del_c[c] = 1;
                for (int r = 1; r <= n; r++)
                {
                    if (board[r][c] == '.')
                        continue;
                    char_cnt_row[r][found]--;
                    board[r][c] = '.';
                }
                cc = 'A' + found;
                ans.push_back("K " + to_string(c) + " " + cc);
                ccnt++;
                break;
            }
        }
    }

    reverse(ans.begin(), ans.end());
    cout << ssize(ans) << '\n';
    for (string s : ans)
        cout << s << '\n';

    return 0;
}