e-olymp
Competitions

2018 Innopolice First Stage, December 1

Innoforest

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 * 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.

Input

First line contains two numbers n and m (1n, m1000) - the size of innoforest.

Then n lines follow, each line contains m numbers ai,j (1ai,j109), current heights of the trees in innoforest.

Then n more lines follow, each line contains m numbers bi,j (1bi,j109), desired heights of the trees.

Output

The first line should contain the number of operations k (0k106), then k lines contain the description of operations.

  • "R r x" The system will water the r-th row by x litres (1rn, 1x109).
  • "C c x" The system will water the c-th column by x litres (1cm, 1x109).

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 106.

Time limit 1 second
Memory limit 128 MiB
Input example #1
1 1
4
9
Output example #1
1
R 1 5
Input example #2
3 3
2 2 2
2 2 2
2 2 2
1 1 1
1 1 1
1 1 1
Output example #2
-1
Input example #3
3 3
1 2 3
4 5 6
7 8 9
2 4 4
5 7 7
7 9 9
Output example #3
3
R 1 1
R 2 1
C 2 1
Source 2018 Innopolice First Stage, December 1