From AtCoder
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
Special Judge, 64bit IO Format: %lld

题目描述

You have an grid. Each cell contains an integer. The number at the i-th row and j-th column has initial value .
In one operation you can choose a cell (i, j) and an integer x such that and do the following:

  • Add x to each number in the i-th row. Then, subtract x from each number in the j-th column.
Determine whether you can make all numbers non-negative within 1000 operations. If so, construct a solution.

输入描述:

The first line contains a single integer .

The next n lines each contains n integers. The j-th integer on the i-th line is .

输出描述:

If your goal cannot be achieved, print one integer -1 in a line.

Otherwise print integer in the first line, indicating the number of operations. Then print k lines. Each line contains three integers i, j, x separated by a single space, indicating one operation. You must make sure .
示例1

输入

复制
3
6 5 -4
-7 2 0
3 26 47

输出

复制
5
1 1 3
2 1 -12
2 2 10
3 2 -10
3 3 -2
示例2

输入

复制
3
-1 -2 -3
-4 -5 -6
-7 -8 -9

输出

复制
-1
示例3

输入

复制
3
0 1 2
3 4 5
6 7 8

输出

复制
0