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

using namespace std;

char p[2000][2000];

int main()
{
    int n, m;
    scanf("%d %d", &n, &m);

    for (int y=0; y<n; y++)
    {
        getchar();
        for (int x=0; x<m; x++)
        {
            p[y][x] = getchar();
        }
    }

    char ruchy[4000];
    int numery[4000];
    char kolory[4000];
    int answer = 0;

    char color;
    bool full;

    bool row_history[2000];
    bool collumn_history[2000];
    for (int i=0; i<2000; i++)
    {
        row_history[i];
        collumn_history[i];
    }

    vector<int> full_rows;
    vector<int> full_collumns;

    for (; answer<n+m;)
    {
        full_rows.clear();
        for (int y=0; y<n; y++)
        {
            if (row_history[y])
                continue;
            color = p[y][0];
            full = true;
            for (int x=0; x<m; x++)
            {
                if (color == 0)
                    color = p[y][x];
                if (p[y][x] != color && p[y][x] != 0)
                {
                    full = false;
                    break;
                }
            }
            if (full && color != 0)
            {
                row_history[y] = true;
                full_rows.push_back(y);
            }
        }
        for (int r : full_rows)
        {
            for (int x=0; x<m; x++)
            {
                if (p[r][x] != 0)
                    color = p[r][x];
                p[r][x] = 0;
            }
            ruchy[answer] = 'R';
            numery[answer] = r+1;
            kolory[answer] = color;
            answer++;
        }

        full_collumns.clear();
        for (int x=0; x<m; x++)
        {
            if (collumn_history[x])
                continue;
            color = p[0][x];
            full = true;
            for (int y=0; y<n; y++)
            {
                if (color == 0)
                    color = p[y][x];
                if (p[y][x] != color && p[y][x] != 0)
                {
                    full = false;
                    break;
                }
            }
            if (full && color != 0)
            {
                collumn_history[x] = true;
                full_collumns.push_back(x);
            }
        }
        for (int c : full_collumns)
        {
            for (int y=0; y<n; y++)
            {
                if (p[y][c] != 0)
                    color = p[y][c];
                p[y][c] = 0;
            }
            ruchy[answer] = 'K';
            numery[answer] = c+1;
            kolory[answer] = color;
            answer++;
        }
        if (full_rows.empty() && full_collumns.empty())
            break;
    }
    printf("%d\n", answer);

    for (int i=answer-1; i>=0; i--)
    {
        printf("%c %d %c\n", ruchy[i], numery[i], kolory[i]);
    }

    return 0;
}