The nearest number#1066

The nearest number

3 Sekunden
64 Megabyte
Mittel

Given a matrix of size N \times N filled with non-negative integers. The distance between two elements A_{ij} and A_{pq} is defined as |i-p|+|j-q|. Each zero element in the matrix must be replaced by the nearest nonzero element. If there are two or more nearest nonzero elements at the same distance, the zero should remain unchanged.

Eingabe

The first line contains the number (1 \leq N \leq 200, 0 \leq A_{ij} \leq 1000000). Then lines follow, each containing integers separated by spaces, representing the matrix.

Ausgabe

Print lines, each containing integers separated by spaces— the modified matrix.

Beispiele

Beispiel 1

Loading
Loading