LearnPy Hub
← Arena
IntermediateRating 1400

Distance to the Nearest Zero

For every cell of the 0/1 grid, print the number of steps (up, down, left, right) to the nearest 0. There is at least one 0.

Input

r and c, then r rows of 0s and 1s separated by spaces.

Output

r rows.

Sample 1

Input
3 3
0 0 0
0 1 0
1 1 1
Output
0 0 0
0 1 0
1 2 1

Sample 2

Input
1 1
0
Output
0
solution.py
Output appears here
Distance to the Nearest Zero · Python Arena problem · LearnPy Hub