시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB222100.000%

문제

Trees in Innopolis are exceptional, if you water an innotree (Innopolis Tree), it will grow by number of litres you have watered it. In other words if you water innotree of height $h$ by $x$ litres of water then it will have new height of $h + x$.

Innoforest (Innopolis Forest) is a $n \times m$ grid, each cell of the grid contains one innotree. Irrigation system in innoforest contains $n + m$ canals: one for each row and column. The irrigation system in one operation can water all trees along one of canals by the same amount of water.

The mayor of Innopolis wants to transform the innoforest by performing some operations on the irrigation system. For each tree in innoforest you know its current height and the desired height. Your task is to find the sequence of operations that transforms the innoforest to the desired shape.

입력

First line contains two numbers $n$ and $m$ ($1 \le n, m \le 1000$).

Then $n$ lines follow, each line contains $m$ numbers $a_{i,j}$, current heights of the trees in innoforest ($1 \le a_{i,j} \le 10^9$).

Then $n$ more lines follow, each line contains $m$ numbers $b_{i,j}$, desired heights of the trees ($1 \le b_{i,j} \le 10^9$).

출력

The first line should contain the number of operations $k$ ($0 \le k \le 10^6$), then $k$ lines contain the description of operations.

  • "R r x" The system will water the $r$-th row by $x$ litres. ($1 \le r \le n$, $1 \le x \le 10^9$).
  • "C c x" The system will water the $c$-th column by $x$ litres. ($1 \le c \le m$, $1 \le x \le 10^9$).

If it is impossible to transform the innoforest to the desired shape, output only one integer -1.

Notice that it is not required to minimize the number of operations, only make sure that it does not exceed $10^6$.

서브태스크

번호배점제한
111

$n = 1$, $m \le 1000$, $a_{i, j}, b_{i, j} \le 10^9$

223

$n, m \le 50$, $a_{i, j}, b_{i, j} \le 50$

321

$n, m \le 300$, $a_{i, j}, b_{i, j} \le 300$

445

$n, m \le 1000$, $a_{i, j}, b_{i, j} \le 10^9$ 

예제 입력 1

1 1
4
9

예제 출력 1

2
C 1 2
R 1 3

예제 입력 2

3 3
2 2 2
2 2 2
2 2 2
1 1 1
1 1 1
1 1 1

예제 출력 2

-1

예제 입력 3

3 3
1 2 3
4 5 6
7 8 9
2 4 4
5 7 7
7 9 9

예제 출력 3

3
R 1 1
R 2 1
C 2 1

채점 및 기타 정보

  • 예제는 채점하지 않는다.