[Question]
  [
Your task is to model the effects of batter on pieces of food. Please add three layers of crust.
```
[[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0], // in
 [0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
 [0,0,0,1,1,1,0,0,0,0,0,0,0,1,1,0,0,0],
 [0,0,0,0,1,0,0,0,0,0,0,0,1,1,0,1,0,0],
 [0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0],
 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]]
                   |
                   V
[[0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,2,1,2],
 [0,0,2,1,2,2,0,0,0,0,0,0,0,2,2,0,2,0],
 [0,0,2,1,1,1,2,0,0,0,0,0,2,1,1,2,0,0],
 [0,0,0,2,1,2,0,0,0,0,0,2,1,1,2,1,2,0],
 [0,0,0,0,2,0,0,0,0,0,0,0,2,1,1,1,2,0],
 [0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,0,0]]
                   |
                   V
[[0,0,3,2,3,3,0,0,0,0,0,0,0,3,3,2,1,2],
 [0,3,2,1,2,2,3,0,0,0,0,0,3,2,2,3,2,3],
 [0,3,2,1,1,1,2,3,0,0,0,3,2,1,1,2,3,0],
 [0,0,3,2,1,2,3,0,0,0,3,2,1,1,2,1,2,3],
 [0,0,0,3,2,3,0,0,0,0,0,3,2,1,1,1,2,3],
 [0,0,0,0,3,0,0,0,0,0,0,0,3,2,2,2,3,0]]
                   |
                   V
[[0,4,3,2,3,3,4,0,0,0,0,0,4,3,3,2,1,2], // out
 [4,3,2,1,2,2,3,4,0,0,0,4,3,2,2,3,2,3],
 [4,3,2,1,1,1,2,3,4,0,4,3,2,1,1,2,3,4],
 [0,4,3,2,1,2,3,4,0,4,3,2,1,1,2,1,2,3],
 [0,0,4,3,2,3,4,0,0,0,4,3,2,1,1,1,2,3],
 [0,0,0,4,3,4,0,0,0,0,0,4,3,2,2,2,3,4]]
```
A little visual aid:
```
body {
   background-color:#222;
   color:lightgray;
}
```
```
<pre>
[[<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:red">1</span>,<span style="color:gold">0</span>], // in
 [<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:red">1</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>],
 [<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>],
 [<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:red">1</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:gold">0</span>,<span style="color:red">1</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>],
 [<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>],
 [<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>]]
                   |
                   V
[[<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:brown">2</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>],
 [<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>,<span style="color:brown">2</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:brown">2</span>,<span style="color:brown">2</span>,<span style="color:gold">0</span>,<span style="color:brown">2</span>,<span style="color:gold">0</span>],
 [<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>],
 [<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>,<span style="color:gold">0</span>],
 [<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:brown">2</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>,<span style="color:gold">0</span>],
 [<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:brown">2</span>,<span style="color:brown">2</span>,<span style="color:brown">2</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>]]
                   |
                   V
[[<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>,<span style="color:chocolate">3</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:chocolate">3</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>],
 [<span style="color:gold">0</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>],
 [<span style="color:gold">0</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>,<span style="color:gold">0</span>],
 [<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>],
 [<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>],
 [<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:chocolate">3</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:brown">2</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>,<span style="color:gold">0</span>]]
                   |
                   V
[[<span style="color:gold">0</span>,<span style="color:orange">4</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>,<span style="color:chocolate">3</span>,<span style="color:orange">4</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:orange">4</span>,<span style="color:chocolate">3</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>], // out
 [<span style="color:orange">4</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>,<span style="color:orange">4</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:orange">4</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>],
 [<span style="color:orange">4</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>,<span style="color:orange">4</span>,<span style="color:gold">0</span>,<span style="color:orange">4</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>,<span style="color:orange">4</span>],
 [<span style="color:gold">0</span>,<span style="color:orange">4</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>,<span style="color:orange">4</span>,<span style="color:gold">0</span>,<span style="color:orange">4</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>],
 [<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:orange">4</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>,<span style="color:orange">4</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:orange">4</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>],
 [<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:orange">4</span>,<span style="color:chocolate">3</span>,<span style="color:orange">4</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:orange">4</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:brown">2</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>,<span style="color:orange">4</span>]]
</pre>
```
The input is a boolean matrix representing the fryer: 0 for the oil, 1 for the food.
Your function or program should add the three layers as 2s, 3s, and 4s around the 1s, thus overwriting some of the 0s. Batter sticks horizontally and vertically (but not diagonally) to food of any shape or size, including donuts (food with holes) and crumbles (isolated food "pixels"), and is restricted to the boundaries of the fryer. Earlier layers of batter turn into crust and are not affected by later ones.
In other words, first you should replace all 0s that are in the von-Neumann neighbourhoods of 1s with 2s, then replace all 0s in the von-Neumann neighbourhoods of 2s with 3s, and finally replace all 0s in the von-Neumann neighbourhoods of 3s with 4s. Thus, the numbers 2,3,4 represent a quantity one greater than the Manhattan distance to the nearest 1-cell.
The fryer will be of size at least 3-by-3 and it will contain at least one piece of food. I/O is flexible - use a matrix format suitable for your language. Extra whitespace is allowed, shorter code desirable, loopholes forbidden.
More tests:
```
 [[0,0,1], // in
  [0,0,0],
  [0,1,0]]
 [[3,2,1], // out
  [3,2,2],
  [2,1,2]]
 -
 [[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1], // in
  [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
  [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,1,1,1,0,0,0,0,0,0],
  [1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0],
  [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,1,1,1,1,1,0,0,1,0,0,0],
  [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,1,0,0,1,0,0,0,0,0,0],
  [0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,1,1,0,1,0,0,0,0,0,0,0,0,0,0],
  [0,0,0,0,1,1,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,1,0,0,0,0],
  [0,0,0,1,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1],
  [0,0,1,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0],
  [0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
  [0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,1,1,0,0,0,0,0,0],
  [0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
  [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0]]
 [[3,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,3,3,4,3,3,3,4,4,4,3,2,1], // out
  [2,3,4,0,0,0,0,0,0,0,0,0,0,0,0,4,3,2,2,3,2,2,2,3,3,4,4,3,2],
  [1,2,3,4,0,0,0,0,0,0,0,0,0,0,4,3,2,1,1,2,1,1,1,2,2,3,4,4,3],
  [1,1,2,3,4,4,4,4,0,0,0,0,0,4,3,2,1,1,1,1,1,1,1,1,1,2,3,4,4],
  [2,2,3,4,4,3,3,3,4,0,0,0,4,3,2,1,1,2,1,1,1,1,1,2,2,1,2,3,4],
  [3,3,4,4,3,2,2,2,3,4,0,0,4,3,2,1,2,2,1,1,2,2,1,2,3,2,3,4,4],
  [4,4,4,3,2,1,1,1,2,3,4,0,4,3,2,1,1,2,1,2,3,3,2,2,2,3,4,3,3],
  [0,4,3,2,1,1,2,1,2,3,4,0,0,4,3,2,2,2,1,2,3,3,2,1,1,2,3,2,2],
  [4,3,2,1,1,2,2,1,2,3,4,0,0,0,4,3,3,3,2,3,4,4,3,2,2,3,2,1,1],
  [3,2,1,2,1,1,1,1,2,3,4,0,0,0,0,4,4,3,3,3,4,3,3,3,3,3,2,1,2],
  [4,3,2,1,2,2,1,2,3,4,0,0,0,0,0,4,3,2,2,2,3,2,2,3,4,4,3,2,3],
  [0,4,3,2,1,1,2,3,2,3,4,0,0,0,4,3,2,1,1,1,2,1,1,2,3,4,4,3,4],
  [0,0,4,3,2,2,3,2,1,2,3,4,0,0,0,4,3,2,2,2,3,2,2,3,4,4,3,2,3],
  [0,0,0,4,3,3,4,3,2,3,4,0,0,0,0,0,4,3,3,3,4,3,3,4,4,3,2,1,2],
```
A little visual aid:
```
body {
   background-color: #222;
   color:lightgray;
}
```
```
<pre>[[<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:red">1</span>], // in
  [<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>],
  [<span style="color:gold">0</span>,<span style="color:red">1</span>,<span style="color:gold">0</span>]]
 [[<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>], // out
  [<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:brown">2</span>],
  [<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>]]
 -
 [[<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:red">1</span>], // in
  [<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>],
  [<span style="color:red">1</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:gold">0</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>],
  [<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>],
  [<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:gold">0</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:red">1</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>],
  [<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:red">1</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:red">1</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>],
  [<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:gold">0</span>,<span style="color:red">1</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>],
  [<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:gold">0</span>,<span style="color:red">1</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:red">1</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>],
  [<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:red">1</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:red">1</span>,<span style="color:red">1</span>],
  [<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:red">1</span>,<span style="color:gold">0</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:red">1</span>,<span style="color:gold">0</span>],
  [<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:red">1</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:red">1</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>],
  [<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:gold">0</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>],
  [<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:red">1</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>],
  [<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:red">1</span>,<span style="color:gold">0</span>]]
 [[<span style="color:chocolate">3</span>,<span style="color:orange">4</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:orange">4</span>,<span style="color:chocolate">3</span>,<span style="color:chocolate">3</span>,<span style="color:orange">4</span>,<span style="color:chocolate">3</span>,<span style="color:chocolate">3</span>,<span style="color:chocolate">3</span>,<span style="color:orange">4</span>,<span style="color:orange">4</span>,<span style="color:orange">4</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>], // out
  [<span style="color:brown">2</span>,<span style="color:chocolate">3</span>,<span style="color:orange">4</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:orange">4</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:brown">2</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>,<span style="color:chocolate">3</span>,<span style="color:orange">4</span>,<span style="color:orange">4</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>],
  [<span style="color:red">1</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>,<span style="color:orange">4</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:orange">4</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>,<span style="color:orange">4</span>,<span style="color:orange">4</span>,<span style="color:chocolate">3</span>],
  [<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>,<span style="color:orange">4</span>,<span style="color:orange">4</span>,<span style="color:orange">4</span>,<span style="color:orange">4</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:orange">4</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>,<span style="color:orange">4</span>,<span style="color:orange">4</span>],
  [<span style="color:brown">2</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>,<span style="color:orange">4</span>,<span style="color:orange">4</span>,<span style="color:chocolate">3</span>,<span style="color:chocolate">3</span>,<span style="color:chocolate">3</span>,<span style="color:orange">4</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:orange">4</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>,<span style="color:orange">4</span>],
  [<span style="color:chocolate">3</span>,<span style="color:chocolate">3</span>,<span style="color:orange">4</span>,<span style="color:orange">4</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:brown">2</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>,<span style="color:orange">4</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:orange">4</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>,<span style="color:orange">4</span>,<span style="color:orange">4</span>],
  [<span style="color:orange">4</span>,<span style="color:orange">4</span>,<span style="color:orange">4</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>,<span style="color:orange">4</span>,<span style="color:gold">0</span>,<span style="color:orange">4</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:brown">2</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>,<span style="color:orange">4</span>,<span style="color:chocolate">3</span>,<span style="color:chocolate">3</span>],
  [<span style="color:gold">0</span>,<span style="color:orange">4</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>,<span style="color:orange">4</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:orange">4</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:brown">2</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:brown">2</span>],
  [<span style="color:orange">4</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>,<span style="color:orange">4</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:orange">4</span>,<span style="color:chocolate">3</span>,<span style="color:chocolate">3</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>,<span style="color:orange">4</span>,<span style="color:orange">4</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:red">1</span>],
  [<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>,<span style="color:orange">4</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:orange">4</span>,<span style="color:orange">4</span>,<span style="color:chocolate">3</span>,<span style="color:chocolate">3</span>,<span style="color:chocolate">3</span>,<span style="color:orange">4</span>,<span style="color:chocolate">3</span>,<span style="color:chocolate">3</span>,<span style="color:chocolate">3</span>,<span style="color:chocolate">3</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>],
  [<span style="color:orange">4</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>,<span style="color:orange">4</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:orange">4</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:brown">2</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>,<span style="color:orange">4</span>,<span style="color:orange">4</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>],
  [<span style="color:gold">0</span>,<span style="color:orange">4</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>,<span style="color:orange">4</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:orange">4</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>,<span style="color:orange">4</span>,<span style="color:orange">4</span>,<span style="color:chocolate">3</span>,<span style="color:orange">4</span>],
  [<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:orange">4</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>,<span style="color:orange">4</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:orange">4</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:brown">2</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>,<span style="color:orange">4</span>,<span style="color:orange">4</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>],
  [<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:orange">4</span>,<span style="color:chocolate">3</span>,<span style="color:chocolate">3</span>,<span style="color:orange">4</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:chocolate">3</span>,<span style="color:orange">4</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:gold">0</span>,<span style="color:orange">4</span>,<span style="color:chocolate">3</span>,<span style="color:chocolate">3</span>,<span style="color:chocolate">3</span>,<span style="color:orange">4</span>,<span style="color:chocolate">3</span>,<span style="color:chocolate">3</span>,<span style="color:orange">4</span>,<span style="color:orange">4</span>,<span style="color:chocolate">3</span>,<span style="color:brown">2</span>,<span style="color:red">1</span>,<span style="color:brown">2</span>],
</pre>
```
---
Thanks @Tschallacka for the visualizations.
  
[Answer]
# Java 8, ~~271~~ ~~269~~ ~~247~~ ~~210~~ ~~202~~ ~~198~~ ~~193~~ ~~186~~ ~~179~~ ~~177~~ 176 bytes
```
a->{for(int l=a[0].length,i,t,I,J,n=0;++n<4;)for(i=a.length*l;i-->0;)for(t=4;a[I=i/l][J=i%l]==n&t-->0;)try{a[I-=t-t%3*t>>1][J-=t<2?1-2*t:0]-=a[I][J]<1?~n:0;}finally{continue;}}
```
Java and index-dependent matrices.. Not a good combination for an already verbose language to begin with..
Modifies the input-matrix instead of returning a new one.
-8 bytes thanks to *@ceilingcat*.
[Try it online.](https://tio.run/##tVdbb5swFH7fr3CROiWNodyeQklVTZuUSuvD@hjx4CVuR@c6GZiuEaJ/PTPggLmYXKSJlmBz/J3vfD4@Ni/oDenrDaYvq9@7JUFxDL6jkKafAAgpw9ETWmLwkDcBeFuHK7Ac8f5FsAgAGnu8O@P//C9miIVL8AAo8MEO6bP0aR3lpoD4aGEGBsH0mf2CIWRwDu8h9U1vMqE3rjcuDH0kLK6IF@r6zCz7me96aDH3w2sSLO798JIEvk8/s9KCRduUv9V9prNL54rNZha34s0b@9bS7Ss2NQOdu5/z3uDGuv2gU9PLnkKKCNmmyzVlIU2wl2U7r4xik/wkPAoRTBHvK1dj9MiikD4XMZdSMByzEcV/gRAjBdfXYE43CZsW7wFITWhCK4Ny05SbFm8WLdHZRvv6vsFLhlcgwnFCalwH2jJu3rTrJn/HmyXu2Mt/TuF7ztWO8ZyrhrAO@8uVK@6WCsI6CNC8OhDHM9gPt06FqIFMVSBtyv0sBuU8wljqHdCil@qwRk0IWbJjIXpYnMJhUAt1Zpjq1FJLdzKLExfZ2cXCHcR1oQMdcc9/3eK5UWBsOARSmtviblcwjlyULKgGEf7ysiX0t4U1f9Nc1HZF0e0FaF7CWg6kwhU0VQz2LASIXGyr6CqaMoRdAe0Hd1hIGks02yxKIWsnjqxFn7HbmA0ZwqqY2DILp0PVbeSEI6m1n2CrvfHIkjWnWJbZqa5yd@qw6HJoBuPIOZE/qbRwOoHUMssZ1JjUdhpbPSAHWTQXU18otRZ1AvyfnVpZOI8sTurdRlFPlRvTMWWv8nZSjTyrGprV5PRNz0BydtOhlQCHVnQr4dxWonXWc192qhK7Nw9VC8mtMq5zdi@Ou0X67U/4eQPulQVYqPqjEFUchKmxHOVmBR4A5UEZMBj5mgYxv5X94mNgEbxPC@tUMH7cxgy/GuuEGRs@khHKj/wv/JvESFhIjLsoQtvYYOsSd/Q@NiK8IfybZKQBDWraWPgFIJr4rHzO2h5bxMUAPDnK0R0he18ixC7lyMB/EkTiER7fal/WUcTdXWhT7RsKCV5dDIwU05Dt/gE)
**Explanation:**
```
a->{                            // Method with integer-matrix parameter and no return-type
  for(int l=a[0].length,          //  Amount of columns
      i,t,I,J,                    //  Temp integers
      n=0;++n<4;)                 //  Loop `n` in range [1, 4):
    for(i=a.length*l;i-->0;)      //   Inner loop over the cells:
      for(t=4;a[I=i/l][J=i%l]     //    Set I,J to the current cell
                             ==n& //    If the value of the current cell is the current `n`:
              t-->0;)             //     Loop `t` downwards in the range (4, 0]:
        try{a                     //      Get the cell at a location relative to the current
             [I-=t-t%3*t>>1]      //       If `t` is 3:
                                  //        Take the cell above
                                  //       Else if `t` is 2:
                                  //        Take the cell below
             [J-=t<2?1-2*t:0]     //       Else if `t` is 0:
                                  //        Take the cell left
                                  //       Else if `t` is 1:
                                  //        Take the cell right
              -=a[I][J]<1?        //      And if this cell contains a 0:
                 ~n:0;            //       Fill it with `n+1`
        }finally{continue;}       //      catch and ignore ArrayIndexOutOfBoundsExceptions
                                  //      (saves bytes in comparison to manual checking)
```
[Answer]
# [Stencil](https://github.com/abrudz/Stencil): 1 + 14 = 15 bytes
Command-line argument: `3`
Code: `s<×⌈/N:1+⌈/N⋄S`
[Try it online!](https://tio.run/##jVBLCsIwEN17iuxMUWgmrbURz@DGI4iLgqjQ7sSVUkStCCJewqWewJvkIMb82qauSiCZeXkz896k2Xw5SxZCpOPPg58P/mQEPf3y034qxIby4w7zy53n1y7Pb13PJrx41@HT20YIYl68MEQ@8frQx6F9YagCHPggb4gURyOAQP@XCSJIsQc1W3botJ4foEC2JqoLIvZA@3IIEWVKG42tbspKA1GlsLRRIvJT28TMuGMOc6AgYl2ZpkaUFahgcFbzt4ewmZLGVlFzb4bCGoCSELqqqlrLp44JR4cWWM2XRWbOd7XOktUyFcEP "Stencil – Try It Online")
`3` repeat the following transformation thrice:
 `s` if whether the **s**elf is non-empty
 `<` is less than
 `×` the signum of
 `⌈/N` the maximum of the von neuman**N** neighborhood
 `:` then the new value becomes
  `1+` one plus
  `⌈/N` the maximum of the von neuman**N** neighborhood
 `⋄` else
  `S` the value stays unmodified (**S**elf)
[Answer]
# [Stencil](https://github.com/abrudz/Stencil) *+CLA: `3`*, 11 bytes
```
s:S⋄+∘×⍨⌈/N
```
[Try it online!](https://tio.run/##Ky5JzUvOzPn/v9gq@FF3i/ajjhmHpz/qXfGop0Pf7///R20TNQwUyIOGmmRrNdDUMCRsvoIhlDRE12pIUCMqhGsl3kaYNkNitSIMMEB3MLrTsNuKNZiIUIQkisWvWJ2EPwwgWpGDglitSLaSYidWv@KOWQPMJIE7SIi2lcTED9T6L7@gJDM/r/i/MQA "Stencil – Try It Online")
-1 thanks to [Adám](https://codegolf.stackexchange.com/users/43319/ad%c3%a1m).  
-2 thanks to a suggestion on another answer by [ngn](https://codegolf.stackexchange.com/users/24908/ngn), which led me to convert this from **Stencil** to **Stencil *+CLA: `3`***.
[Answer]
# JavaScript (ES6), ~~107~~ 105 bytes
```
f=(m,k=1)=>k<4?f(m.map((r,y)=>r.map((v,x)=>v|[-1,0,1,2].every(d=>(m[y+d%2]||0)[x+~-d%2]^k)?v:k+1)),k+1):m
```
### Test cases
```
f=(m,k=1)=>k<4?f(m.map((r,y)=>r.map((v,x)=>v|[-1,0,1,2].every(d=>(m[y+d%2]||0)[x+~-d%2]^k)?v:k+1)),k+1):m
draw = a => O.innerText += a.map(r => r.join(',')).join('\n')+'\n\n'
draw(f(
 [[0,0,1],
  [0,0,0],
  [0,1,0]]
))
draw(f(
 [[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
  [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
  [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,1,1,1,0,0,0,0,0,0],
  [1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0],
  [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,1,1,1,1,1,0,0,1,0,0,0],
  [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,1,0,0,1,0,0,0,0,0,0],
  [0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,1,1,0,1,0,0,0,0,0,0,0,0,0,0],
  [0,0,0,0,1,1,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,1,0,0,0,0],
  [0,0,0,1,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1],
  [0,0,1,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0],
  [0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
  [0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,1,1,0,0,0,0,0,0],
  [0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
  [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0]]
))
```
```
<pre id=O></pre>
```
### Commented
```
f = (m, k = 1) =>                  // given the input matrix m[] and starting with k = 1
  k < 4 ?                          // if this is not the 4th iteration:
    f(                             //   do a recursive call:
      m.map((r, y) =>              //     for each row r[] at position y in m[]:
        r.map((v, x) =>            //       for each cell v at position x in r[]:
          v |                      //         if v is non-zero
          [-1, 0, 1, 2].every(d => //         or each neighbor cell at (x+dx, y+dy), with:
            (m[y + d % 2] || 0)    //           dy = d % 2 --> [-1, 0, 1, 0]
            [x + ~-d % 2]          //           dx = (d - 1) % 2 --> [0, -1, 0, 1]
            ^ k                    //           is different from k  
          ) ?                      //         then:
            v                      //           let the cell unchanged
          :                        //         else:
            k + 1                  //           set the cell to k + 1
        )                          //       end of inner map()
      ),                           //     end of outer map()
      k + 1                        //     increment k for the next iteration
    )                              //   end of recursive call
  :                                // else:
    m                              //   stop recursion and return m[]
```
[Answer]
# [Python 3](https://docs.python.org/3/), 176 bytes
```
f=lambda a,i=-2,e=enumerate:a*i or f([[E or int((6*max(len(a)>i>-1<j<len(a[i])and a[i][j]for i,j in((r+1,c),(r-1,c),(r,c+1),(r,c-1))))**.5)for c,E in e(R)]for r,R in e(a)],i+1)
```
[Try it online!](https://tio.run/##hY/BboMwDIbvPIWPDg2o2bQdqtJbX4Ar4uBBqhlBQEkq0adnCZ3QpnVbfPDv6Pv/ONPNv4/meVkuRU/DW0tAkovsSepCm@ugLXl9oJRhtHDBqjpHwcYjvqYDzdhrgyROfMrUsTuuU8W1INNCFFVXX6JBdsGEaHdKNkKizT67bHbq3jMlwknT/EVERyPPwQEaS7EmWFneZxK15GBaeJhG68HdXGKhiMv17DwONGHYT8Kcu6lnjyEVYsIc/YHOnW/Z5FZT27PRDkUtkgisD9gDTDb@L92CSiGWPfxdCvbJpn6vjVE/uO0m@ZL5gFDfmEebqH@ZrT4A "Python 3 – Try It Online")
-18 bytes thanks to Mr. Xcoder  
-20 bytes thanks to ovs
[Answer]
# [Python 2](https://docs.python.org/2/), ~~146~~ 143 bytes
```
e=enumerate;l=input()
for y,f in e(l):
 for g,h in e(f):x=1+min(abs(y-a)+abs(g-c)for a,b in e(l)for c,d in e(b)if d==1);l[y][g]=x*(x<5)
print l
```
[Try it online!](https://tio.run/##nVPLboMwELzzFRYn3DgSW6kXiI/ptZfeEKqAmIdKDHKNAl9PeZcSXon24PUyo50d1mkhw4S/ll5yYVRV1ZJRxrMrE45kZkwjnmZSw4qfCFQQH0UcMS3GhoLqSkDCtuJjI6dwuEZcc9wfrTg6@FAnwdHDNdAhbk@trx65tFcXRz66UArYjK3CtgKb5i9afnrDSioiLlFcVpqUWxjFDH2KjFWNEcuZh2q9VS5FYQjn9tXpNBtWg/FYKtH54/0sRCIMVzDnu7QsnawHEN0m1pAvxwgFd8ihMqD0BQxMUHOKYAfqT5etKO2Y0BOaE8afngnY13/RLdju0Dky8bPhwibzf@h3/m/37Hmwmzv@1zC7HesbAqubtYoaVefmnVW17kPHHfuxlzt9M/DgbsxMsvAKYMVn/bHeT@9z85R@AQ "Python 2 – Try It Online")
[Answer]
# Fortran 95, ~~309~~ ~~299~~ ~~294~~ ~~287~~ 269 bytes
```
subroutine f(a)
integer::a(:,:),s(2)
integer,allocatable::b(:,:)
s=shape(a)
allocate(b(0:s(1)+1,0:s(2)+1))
do1 k=0,3
do1 i=1,s(1)
do1 j=1,s(2)
b(i,j)=a(i,j)
if(any((/b(i+1,j)==k,b(i-1,j)==k,b(i,j+1)==k,b(i,j-1)==k/)).and.b(i,j)<1.and.k>0)b(i,j)=k+1
1 a(i,j)=b(i,j)
end
```
Fortran is not a golfing language.
* **Edit:** Saved 10 bytes by using weird old-fashioned do loops.
* **Edit 2:** Saved 5 bytes with `any()`
* **Edit 3:** Saved 7 bytes by removing an unnecessary `if`
* **Edit 4:** Saved 18 bytes by shrinking declaration of `s`
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 70 bytes
```
Mod[-MorphologicalTransform[#,#[[;;,2]]~Max~#[[2]]&,i]~Sum~{i,0,3},5]&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n6Zgq/DfNz8lWtc3v6ggIz8nPx0onBNSlJhXnJZflButrKMcHW1trWMUG1vnm1hRB@QBmWo6mbF1waW5ddWZOgY6xrU6prFq/wOKMvNKotOiq6sNdPBDQx2DWp1qOBs3RFJliKESLgJXZYBDjSGaKmwuMiRCFcJdtbGx/wE "Wolfram Language (Mathematica) – Try It Online")
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), ~~34~~ ~~30~~ 23 bytes ([abrudz/SBCS](https://github.com/abrudz/SBCS))
```
5|{5⊃,⍵+×⌊.⌊⍨⍵}⌺3 3⍣3∘-
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///37Sm2vRRV7POo96t2oenP@rp0gPiR70rgPzaRz27jBWMH/UuNn7UMUP3//9HvXMVfBMz8xTSSvOSSzLz8xQ0ikuTcjOLi4FsTS6uNIVHbRMUiDeRiwtkYkhqcYlCcmJxajHQhEdtEzUMFMiDhppkazXQ1DAkbL6CIZQ0RNdqSFAjKoRrJd5GmDZDYrUiDDBAdzC607DbijWYiFCEJIrFr1idhD8MIFqRg4JYrUi2kmInVr/ijlkDzCSBO0iItpXExA/UCgA "APL (Dyalog Unicode) – Try It Online")
-4 thanks to [ngn](https://codegolf.stackexchange.com/users/24908/ngn).
[Answer]
# [Clean](https://clean.cs.ru.nl), 157 bytes
```
import StdEnv,StdLib
t=transpose
z=zipWith
?n=n+sign n
f[0,h:l]=[?h:f[h:l]]
f[h,0:l]=[h,?h:f l]
f[h:l]=[h:f l]
f l=l
$l=z(z max)(t(map f(t l)))(map f l)
```
# 
```
$o$o$
```
[Try it online!](https://tio.run/##nVSxbsMgEN35CqRmsFUqwRoJZWmGStkydLA8UMfESIAtm1SpP770EhLVTW3Hjk8y3BO8ezxxZDoX1ptyd9A5NkJZr0xV1g5v3W5tPwkMG/WBHHe1sE1VNjlqeauqd@UKtLLcPjdqb7FFMqGkWOqUJ6tiKZPTNAWwIPQMFuQEY33GAnJJseYaLTRvoxYEHOPIRUZUWEYO6ziOQwJTv3WidugJFrlaHTHHCZR8LFhKEIbvYQJ6JWD3axF2@bN@AnZ3@9@4IZhe/bqZzSP4paH9R7gV269gxMQJSzvooAe9Ise96RJ0jZpK8E/BnPojHgzfBDp0kYYNm6lgZisBQQpdKQ82g55clBCIhzR0qv/OpBb7xr@8bfzrlxVGZSEJj8sP "Clean – Try It Online")
As a function literal.
[Answer]
# Perl, 63 bytes
Includes +3 for `0ap`
```
perl -0ape 's/0(?=$a|.{@{-}}$a)/$a+1/seg,$_=reverse while($a+=$|-=/
/)<4'
```
Give the input matrix as a block of digits **without** final newline., e.g.
```
001
000
010
```
for the 3x3 example. The output format is the same, a block of digits without final newline.
You can use a small script like 
```
perl -i -0pe 's/\n*$//' <file>
```
to conveniently remove the final newlines from a file if that is hard to do in your favorite editor
[Answer]
# [Retina](https://github.com/m-ender/retina/wiki/The-Language), ~~93~~ ~~87~~ 84 bytes
```
1
4
3{m`(?<=^(.)*)0(?=4|.*¶(?>(?<-1>.)*)4|(?<=40|^(?(1)_)(?<-1>.)*4.*¶.*))
5
T`1-5`d
```
[Try it online!](https://tio.run/##fZFBDsIgFET3/ySfJiVMpDtbLuG6YqILF7ow7uRcHsCLYanQ0Bb7w2rezGcIj8vzej/Be5Cm3etm2ezbnqWohGLTaierz5tNN8g1uiBrFyxauZ4NQxzFhHTwykoIauhgUTf27L3aGNAWVYRVAMNBoljCOCMtJgNDiY4GlTandVk2a7WWEKVIs1WLDhQAgCL9ZcvR7N7ZgyeBZl2K2X@foL4 "Retina – Try It Online") Based on my answer to [Kill it With Fire](https://codegolf.stackexchange.com/questions/138068). Edit: Saved ~~6~~ 9 bytes thanks to @MartinEnder. Explanation:
```
1
4
```
Turn all the 1s into 4s.
```
3{
```
Repeat the rest of the program (at most) 3 times.
```
m`(?<=^(.)*)0(?=4|.*¶(?>(?<-1>.)*)4|(?<=40|^(?(1)_)(?<-1>.)*4.*¶.*))
5
```
Change all 0s adjacent to 4s into 5s.
```
T`1-5`d
```
Decrement all digits.
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), ~~100~~ 94 bytes
```
1
3
{m`(?<=^(.)*)0(?=3|.*¶(?>(?<-1>.)*)3|(?<=30|^(?(1)_)(?<-1>.)*3.*¶.*))
4
T`1-4`d`^[^1]+$
```
[Try it online!](https://tio.run/##fZFBDsIgFET3/xwuoKYNE7q05RLujIiJLlzowriTc/UAXgxLhYa22B9W82Y@Q3heX7fH2TmQpPfdMLVrNKt4wQVTjbRV8emYanu5ROtlab1FCquZYuAnPiLpvVXBOdW0NyhrczH6oHHcbpwTKwNao4KwCKA/iBRzGGag2aRnyNHBIOLmuC7JJq2WEoIUaLJq1oE8AJClv2w@mtw7efAo0KRLNvvvE8QX "Retina 0.8.2 – Try It Online") Explanation:
```
1
3
```
Turn all the 1s into 3s.
```
{
```
Repeat until the output does not change.
```
m`(?<=^(.)*)0(?=3|.*¶(?>(?<-1>.)*)3|(?<=30|^(?(1)_)(?<-1>.)*3.*¶.*))
4
```
Change all 0s adjacent to 3s into 4s.
```
T`1-4`d`^[^1]+$
```
If there are no 1s, decrement all digits.
[Answer]
# [Ruby](https://www.ruby-lang.org/), ~~183~~ ~~158~~ 146 bytes
```
->a{3.times{|n|a.size.times{|i|r=a[i];r.size.times{|j|(r[j]<1&&[i>0?a[i-1][j]:0,a[i+1]&.at(j),j>0?r[j-1]:0,r[j+1]].include?(n+1))?r[j]=n+2:0}}};a}
```
[Try it online!](https://tio.run/##jZDdisIwEEbv@xShF6WhMWT0Tq0@SDYX0a2Q0EZJW8Rt8uzdWfxZRVeWgfDlO@diGN9vTuOuHCcrPcx4Z5qqHYILmrfmq7r@TfCllkYt/ENtQ@6lVUvIMmlWYo3KBBQ2c8EwF6AyrrvcUmaRoooUEQZEihu3rfvPap27Aij94ap0xXQuYowLHUdftX3dkZLs@FbXNZEJkYK9H2BCsZsH79wHD57cW3PniT8sePJebQb/8n73U0ly6LuWnO/AG30Ygt8fA8GH271xeUpSGi/xw6V0/AY "Ruby – Try It Online")
Uses the obvious three-loop algorithm. ~~The fact that Ruby allows negative indexing into arrays means that there is no way (that I can see) around making the bounds checks.~~ Reaching beyond the boundary of an array returns `nil`, so only the negative bound checks are necessary. The check for `a[i+1][j]` just needs to use the safe access operator.
I also shaved off a few bytes by using a variable for `a[0]`.
-12 more bytes: Use `.times` instead of `(0...x).map` (in three places).
```
->a{
  3.times{|n|                    # For n from 0 to 2
    a.size.times{|i|             # For each row
      r=a[i];
      r.size.times{|j|           # For each column
        (r[j]<1 && [             # If the current cell is 0, and any of
            i>0 ? a[i-1][j] : 0, #     the cell to the north,
            a[i+1]&.at(j),       #     the cell to the south,
            j>0 ? r[j-1] : 0,    #     the cell to the west,
            r[j+1]               #     or the cell to the east
          ].include?(n+1)        #   are set to the previous value,
        ) ? r[j]=n+2 : 0         # Set this cell to the next value (or 0)
      }
    }
  };
  a                              # Return the modified array
}
```
[Answer]
# [Python 3](https://docs.python.org/3/), 125 bytes
```
f=lambda a,n=2,e=enumerate:n//5*a or f([[r[j]or n*any([0,*r][j:j+3]+[0,*c][i:i+3])for j,c in e(zip(*a))]for i,r in e(a)],n+1)
```
[Try it online!](https://tio.run/##pVbLbqMwFN3zFV7ixFK5xt1E4kuQF0yHaIhaJ6JEVfvzGT/wC4yTqLFQ8OXcp6@Pffme/p1Ffbsdm/fu48/fDnVENJT0TS@uH/3YTf1BvLy87jp0HtGxbNuxPXH5Knad@C7biuxG3p4Op33N92r2xtvhMMgZPkrUibyhQaC@/Bku5a7DmCvpQEYj7TAnYg/4pqXiQtD5OqlPZVEWqJX28gNIxUmBUOum2yMGwgrsJCGw2oDBGpiKDh4D@hgVUqXNSE2ofGr55r8zLaHSKDUmmZ1qMAtgRiKfGAgabKBepiU2SG9zDQNv0TtaOnZewrRZIhVq4@a8wMSvOASK9hVccbQLI9YmzKspirGDHmmdzUV7eLFybQb3/cx9tGhEqw53leNRpXr3vmerCs@oh7sFtrZYfpvBvR2aBQbSjdyT4eVr4tXD8jyqnuAheL5tElltcArkK189F8Fvej7cmSyLZDOh1fM/s4Rht3DOQEhq1HGjlto9s20g5jAIGJNZmvLMaEZKOR4z2gbv7EW0vfZsvUe0G2QTkXlI8LFi5D2o5SbFw1w076D2FL0GsgVNe3VwEdDl4UIX6pWrB40SnPGexcPyxMsYlrR2Y@MMXPdAWFIaRZHMPXeehR0SnJfVIqvUSZzxHm8Mmjzxa4dwyaqjrsAHaQOhsf@8vk@okdczeYfCWqYuVOP5C6nLlPlusOp3GQcxlfKrgeopKq2VRt3B8O0/ "Python 3 – Try It Online")
Adaptation of my answer to [Calculate COVID spread](https://codegolf.stackexchange.com/questions/214463/calculate-covid-spread)
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 217 bytes
```
for(w=2;w<=4;w++)for(y=0;y<H;y++)for(x=0;x<W;x++){if(o[y][x].v[w%2])continue;if(o[y][x].v[!(w%2)]){o[y][x].v[w%2]=o[y][x].v[!(w%2)];continue;}for(z=0;z<8;z++)if(o[y][x].a[z]&&o[y][x].a[z]->v[!(w%2)])o[y][x].v[w%2]=w;}
```
[Try it online!](https://tio.run/##pVRtU6MwEP6c/Io9nVawqIC9OzWgX/sP@gGZmw5tlbkedSpKaeW39zYJbymg7V2ZacjuPs@zWXYTXDwFwe40jILF23QGzms8DZeXz/eUnk5n8zCawZjYt@VmRKwhpXH6MkMDvMartyCGYLZY/HqFLSWq4Xzi3fiMEkrCKIZ3z8ZNJp0xo5Qb/0zCSOMvk9VTYEDwPFkhbPX07vk6J@SuhMl1na9pvm6QQ7yEnjX0PfvWB5djyNY0/u2xMuN/4KaEW1/rGFb@b7XBrS/B6qPAD1cuoNYx8IrEbEt@P8129c7SHRBYs3acvTW9z2tSwevlORS@p36MdufZu7@82d423WU6Sv3IgUE4JZmYcTnXsPRGvjcWo4g/M8OfcM@XKy1Fq8kgBQdGuAwGYsaFay1da3SNcSlcYr4XYfQb3Rp3amO4AEuHB7DgDkwdPkDjfNqosNvCzu8GRM81Ae5zl@AjSy/1vbV/OfGGPMm@3MMALH5VlQHCgEHXtSAZkO0x203mHwVIsBRAUjNgkPUFs@vCdZP65x61mnjdiMFmQ4K0JGIfUofvrUfKaE5ZJPguNautOGVYZcDbZcc/eOLaLHHcIUvwW4vmcE2WOiOW5vs17tfOmPFe2GJRKs6kZ/t6sIziMHqbMcX1TUOn7utbNdptRLASn3GxDYptnBu2QbEa4cTb@P1@fXdxX4nsaSQs25Grc9nqCR7bZpCA48IQV@TNO10ZglTaPx0B0jw8lNk3A4rscjBRocrHKWohA1XOrGoXUSCZ3AaTu8ElT1uR5uWBfh@6yiUBzXySopXOryhtL5E4y8sKL4O5dvIY9wLvxED3A5zhcwdn3pnOSTrvEi5QwHvTXoBopWMf1O2d0sAGv3kG/Aa5d2HMRX0hapSiJXXwGCG1lpbho/3wjGa7vw "C (gcc) – Try It Online")
]