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
#include <bits/stdc++.h>


using namespace std;


struct Move{
    char dimension;
    char color;
    int which;
};


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n,m;
    cin >> n >> m;
    vector<vector<int>> rows_colors(n, vector<int> (27,0));
    vector<vector<int>> cols_colors(m, vector<int> (27,0));
    vector<Move> solution;
    string color;
    vector<vector<int>> puzzle(n, vector<int> (m));
    for(int i = 0; i < n; i++)
    {
        cin >> color;
        
        for(int j = 0; j < m; j++)
        {
            char cr = color[j];
            cols_colors[j][cr - 'A']++;
            rows_colors[i][cr - 'A']++;
            puzzle[i][j] = cr - 'A';
        }
    }    
    int done_count = 0;
    vector<bool> rows_done(n, false);
    vector<bool> cols_done(m, false);

    int x = 0;
    while(done_count < n*m)
    {

        for(int i = 0; i < n; i++)
        {
            for(int j = 0; j < 26; j++)
            {
                if(rows_colors[i][j] + rows_colors[i][26] == m && !rows_done[i])
                {
                    x++;
                    rows_done[i] = 1;
                    for(int k = 0; k < m; k++)
                    {
                        if(puzzle[i][k] != -1)
                        {
                            cols_colors[k][26]++;
                            cols_colors[k][puzzle[i][k]]--;
                            done_count++;
                            puzzle[i][k] = -1;
                        }
                        
                    }
                    solution.push_back({'R', char(int('A') + j), i});
                    break;
                }
            }
        }
 
        if(done_count >= n*m) break;
        for(int i = 0; i < m; i++)
        {

            for(int j = 0; j < 26; j++)
            {
                if(cols_colors[i][j] + cols_colors[i][26] == n && !cols_done[i])
                {
                    x++;
                    cols_done[i] = 1;
                    for(int k = 0; k < n; k++)
                    {
                        if(puzzle[k][i] != -1)
                        {
                            rows_colors[k][26]++;
                            rows_colors[k][puzzle[k][i]]--;
                            done_count++;
                            puzzle[k][i] = -1;
                        }
                       
                    }
                    solution.push_back({'K', 'A' + j, i});
                    break;
                }
            }
        }
    }
    cout << x << "\n";
    for(int i = solution.size() - 1; i >= 0; i--)
    {
        cout << solution[i].dimension << " " << solution[i].which + 1 << " " << solution[i].color << "\n";
    }

}