eolymp
bolt
Try our new interface for solving problems
Problems

Cute table

Cute table

Consider the table size \textbf{M}×\textbf{N}, in which cells are non-negative integers. We say that the table is nice, if for all \textbf{i} the sum of the numbers of its \textbf{i}-th row is less than \textbf{R_i} and for all \textbf{j} the sum of the numbers of \textbf{j}-th column is not more than \textbf{C_j}. You set the table \textbf{Z} size \textbf{M}×\textbf{N}, in some cells which are already non-negative integers. Find a nice table with a maximum amount of elements such that it coincides with \textbf{Z} on those cells, which are in the \textbf{Z} number. \InputFile The first line contains the number of \textbf{M} and \textbf{N} (\textbf{1} ≤ \textbf{M}, \textbf{N} ≤ \textbf{20}). The next line contains \textbf{M} non-negative integers - \textbf{R_1}, \textbf{R_2}, ..., \textbf{R_M}. The next line contains \textbf{N} non-negative integers \textbf{C_1}, \textbf{C_2}, ..., \textbf{C_N}. All restrictions shall not exceed \textbf{10^6}. The following \textbf{M} lines contains \textbf{N} integers that define \textbf{Z}. If at some point in the table is missing a number, at this point in the input file is number \textbf{-1}. \OutputFile Bring in the output table found - \textbf{M} rows of \textbf{N} numbers. If there is no solution, output only the number \textbf{-1}.
Time limit 1 second
Memory limit 64 MiB
Input example #1
3 3
2 2 2
1 2 1
1 -1 -1
-1 1 -1
-1 -1 1
Output example #1
1 1 0
0 1 0
0 0 1