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

const int N = 2007;
int tab[N][N];
int kolkol[N][30], kolwie[N][30], ostkol[N];
vector<pair<pair<char, int>, char>> w;
int n, m;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            char a;
            cin >> a;
            tab[i][j] = a-65;
            kolkol[j][(tab[i][j])]++;
            kolwie[i][(tab[i][j])]++;
        }
    }
    
    int licz = 0;
    while (licz < n * m)
    {
        for (int i = 0; i < n; i++)
        {
            bool czy = true;
            int kolor = 27;
            for(int k = 0; k<26; k++)
            {
                for(int k1 = k+1; k1<26; k1++)
                {
                    if(kolwie[i][k] > 0 && kolwie[i][k1] > 0)
                    {
                        czy = false;
                    }
                    
                }
                if(kolwie[i][k] > 0)
                {
                    kolor = k;
                }
            }
            if(czy == true && kolor != 27)
            {
                char a = kolor+65;
                w.push_back({{'R', i+1}, a});
                for(int j = 0; j<m; j++)
                {
                    if(tab[i][j] != 27)
                    {
                        licz++;
                        
                        kolkol[j][tab[i][j]]--;
                        kolkol[j][27]++;
                        kolwie[i][tab[i][j]]--;
                        kolwie[i][27]++;
                        tab[i][j] = 27;
                    }

                }
            }

        }
        for (int i = 0; i < m; i++)
        {
            bool czy = true;
            int kolor = 27;
            for(int k = 0; k<26; k++)
            {
                for(int k1 = k+1; k1<26; k1++)
                {
                    if(kolkol[i][k] > 0 && kolkol[i][k1] > 0)
                    {
                        czy = false;
                    }
                    
                }
                if(kolkol[i][k] > 0)
                {
                    kolor = k;
                }
            }
            if(czy == true && kolor != 27)
            {
                char a = kolor+65;
                w.push_back({{'K', i+1}, a});
                for(int j = 0; j<n; j++)
                {
                    if(tab[j][i] != 27)
                    {
                        licz++;
                        kolkol[i][tab[j][i]]--;
                        kolkol[i][27]++;
                        kolwie[j][tab[j][i]]--;
                        kolwie[j][27]++;
                        tab[j][i] = 27;;
                    }

                }
            }

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