atcoder#ARC119D. [ARC119D] Grid Repainting 3

[ARC119D] Grid Repainting 3

Score: 700700 points

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 (1iH)(1 \leq i \leq H) and jj-th column from the left (1jW)(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

  • 1H25001 \leq H \leq 2500
  • 1W25001 \leq W \leq 2500
  • si,js_{i, j} is R or B. (1iH,1jW)(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}\cdotss1,Ws_{1, W}

s2,1s_{2, 1}s2,2s_{2, 2}s2,3s_{2, 3}\cdotss2,Ws_{2, W}

s3,1s_{3, 1}s3,2s_{3, 2}s3,3s_{3, 3}\cdotss3,Ws_{3, W}

\vdots

sH,1s_{H, 1}sH,2s_{H, 2}sH,3s_{H, 3}\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

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.

4 4
RBBB
BBBB
BBBB
RBRB
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.

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

We can repaint all squares white.

10 10
BBBBBBBBBB
BBBBBBBBBB
BBBBBBBBBB
BBBBBBBBBB
BBBBBBBBBB
BBBBBBBBBB
BBBBBBBBBB
BBBBBBBBBB
BBBBBBBBBB
BBBBBBBBBB
0

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