#arc119d. [arc119_d]Grid Repainting 3

[arc119_d]Grid Repainting 3

Problem Statement

We have a canvas represented as a grid with HH rows and WW columns. Let (i,j)(i, j) denote the square at the ii-th row from the top (1leqileqH)(1 \\leq i \\leq H) and jj-th column from the left (1leqjleqW)(1 \\leq j \\leq W). Initially, (i,j)(i, j) is painted red if si,j=s_{i, j}= R and blue if si,j=s_{i, j}= B.

For any number of times, you can choose one of the two operations below and do it.

Operation X: Choose a square painted red, and repaint all squares in the row containing that square (including itself) white.
Operation Y: Choose a square painted red, and repaint all squares in the column containing that square (including itself) white.

Show one way that maximizes the number of squares painted white in the end.

Constraints

  • 1leqHleq25001 \\leq H \\leq 2500
  • 1leqWleq25001 \\leq W \\leq 2500
  • si,js_{i, j} is R or B. (1leqileqH,1leqjleqW)(1 \\leq i \\leq H, 1 \\leq j \\leq W)
  • HH and WW are integers.

Input

Input is given from Standard Input in the following format:

HH WW s1,1s_{1, 1}s1,2s_{1, 2}s1,3s_{1, 3}cdots\\cdotss1,Ws_{1, W} s2,1s_{2, 1}s2,2s_{2, 2}s2,3s_{2, 3}cdots\\cdotss2,Ws_{2, W} s3,1s_{3, 1}s3,2s_{3, 2}s3,3s_{3, 3}cdots\\cdotss3,Ws_{3, W} vdots\\vdots sH,1s_{H, 1}sH,2s_{H, 2}sH,3s_{H, 3}cdots\\cdotssH,Ws_{H, W}

Output

Print the following to Standard Output:

nn t1t_1 r1r_1 c1c_1 t2t_2 r2r_2 c2c_2 t3t_3 r3r_3 c3c_3 vdots\\vdots tnt_n rnr_n cnc_n

Here, nn is the number of operations you do, and ti,ri,cit_i, r_i, c_i means that your ii-th operation is Operation tit_i with (ri,ci)(r_i, c_i) being chosen, where tit_i is X or Y.
If there are multiple possible solutions, you may print any of them.


Sample Input 1

4 4
RBBB
BBBB
BBBB
RBRB

Sample Output 1

3
X 1 1
Y 4 3
X 4 1

Here is one sequence of operations that makes 1010 squares white:

  • First, do Operation X choosing (1,1)(1, 1).
  • Then, do Operation Y choosing (4,3)(4, 3).
  • Then, do Operation X choosing (4,1)(4, 1).

There is no way to make 1111 or more squares white.


Sample Input 2

1 119
BBBRBBBBBBRBBBBBBRBBBBBBRBBBBBBRBBBBBBRBBBBBBRBBBBBBRBBBBBBRBBBBBBRBBBBBBRBBBBBBRBBBBBBRBBBBBBRBBBBBBRBBBBBBRBBBBBBRBBB

Sample Output 2

4
Y 1 60
Y 1 109
Y 1 46
X 1 11

We can repaint all squares white.


Sample Input 3

10 10
BBBBBBBBBB
BBBBBBBBBB
BBBBBBBBBB
BBBBBBBBBB
BBBBBBBBBB
BBBBBBBBBB
BBBBBBBBBB
BBBBBBBBBB
BBBBBBBBBB
BBBBBBBBBB

Sample Output 3

0

Since there is no red square, we cannot do the operations at all.