Matrix Reduction

Time limit: 1s Memory limit: 256MB Input: Output:

Alex and Andrei are playing a game on an NMN \cdot M matrix filled with non-negative integers. The rows of the matrix are numbered from 11 to NN (from top to bottom), and the columns are numbered from 11 to MM (from left to right).

Alex is allowed to perform the following operation any number of times:

  • Choose a horizontal or vertical 131 \cdot 3 subrectangle.
  • Select an integer VV.
  • Add VV to all numbers in the chosen subrectangle, ensuring that no number becomes negative.

Andrei believes that Alex cannot make all the numbers in the matrix zero within at most 2NM2 \cdot N \cdot M operations.

Alex is determined to prove him wrong -- but since he hasn't learned addition at school yet, he needs your help. Can you determine whether Alex can reduce the entire matrix to zero within the given limit?

Input data

The first line of the input contains two integers: NN and MM.

Each of the next NN lines contains MM non-negative integers, representing the elements of the matrix.

Output data

First, print YES if it is possible to make all Ai,jA_{i,j} equal to zero within at most 2NM2 \cdot N \cdot M operations. Otherwise, print NO.

If the answer is YES, proceed with the following output:

  • Print an integer RR, the number of operations perfomed.
  • Print RR lines, each describing an operation in the format: X1 Y1 X2 Y2 VX_1 \ Y_1 \ X_2 \ Y_2 \ V where (X1,Y1)(X_1, Y_1) are the coordinates of the top-left corner of the chosen subrectangle, (X2,Y2)(X_2, Y_2) are the coordinates of the bottom-right corner of the subrectangle (that is, X1X2X_1 \le X_2 and Y1Y2Y_1 \le Y_2), and VV is the integer added to all elements within the subrectangle.

If there are multiple valid solutions, you can print any of them.

Constraints and clarifications

  • 3N5003 \le N \le 500.
  • 3M5003 \le M \le 500.
  • 0Ai,j1 0000 \le A_{i,j} \le 1 \ 000 for each i=1Ni=1\ldots N and j=1Mj=1\ldots M.
  • 109V109-10^9 \le V \le 10^9.
# Points Constraints
1 0 Examples
2 14 N6N \le 6, M6M \le 6.
3 25 N=3N=3 or M=3M=3.
4 7 All numbers Ai,jA_{i,j} are equal.
5 54 No additional constraints.

Example 1

stdin

3 3
1 5 1
2 6 2
8 12 8

stdout

YES
6
1 1 1 3 8
2 1 2 3 7
3 1 3 3 1
1 1 3 1 -9
1 2 3 2 -13
1 3 3 3 -9

Explanation

In the first sample case, there are multiple valid solutions, with the sample output being one of them.

Example 2

stdin

3 3
1 5 0
2 6 2
8 12 8

stdout

NO

Explanation

In the second sample case it can be proven that no sequence of at most 2NM=182 \cdot N \cdot M = 18 operations will lead to a matrix containing only zeros.

Log in or sign up to be able to send submissions!