#ABC295B. [ABC295B] Bombs

[ABC295B] Bombs

Score : 200200 points

Problem Statement

We have a board with RR rows running horizontally and CC columns running vertically. Let (i,j)(i,j) denote the square at the ii-th row from the top and jj-th column from the left.

You are given characters Bi,jB_{i,j} representing the current states of (i,j)(i,j). . represents an empty square; # represents a square with a wall; 1, 2,\dots, 9 represent a square with a bomb of power 1,2,,91,2,\dots,9, respectively.

At the next moment, all bombs will explode simultaneously. When a bomb explodes, every square whose Manhattan distance from the square with the bomb is not greater than the power of the bomb will turn into an empty square. Here, the Manhattan distance from (r1,c1)(r_1,c_1) to (r2,c2)(r_2,c_2) is r1r2+c1c2|r_1-r_2|+|c_1-c_2|.

Print the board after the explosions.

Constraints

  • 1R,C201\leq R,C \leq 20
  • RR and CC are integers.
  • Each Bi,jB_{i,j} is one of ., #, 1, 2, \dots, 9.

Input

The input is given from Standard Input in the following format:

RR CC

B1,1B1,2B1,CB_{1,1}B_{1,2}\dots B_{1,C}

\vdots

BR,1BR,2BR,CB_{R,1}B_{R,2}\dots B_{R,C}

Output

Print RR lines representing the board after the explosions. Use the format used in the input (do not print RR or CC).

4 4
.1.#
###.
.#2.
#.##
...#
#...
....
#...

Figure representing the explosion ranges of bombs

  • The explosion of the bomb at (1,2)(1,2) will turn the blue squares and purple squares in the above figure into empty squares.
  • The explosion of the bomb at (3,3)(3,3) will turn the red squares and purple squares in the above figure into empty squares.

As seen in this sample, the explosion ranges of bombs may overlap.

2 5
..#.#
###.#
..#.#
###.#

There may be no bombs.

2 3
11#
###
...
..#
4 6
#.#3#.
###.#.
##.###
#1..#.
......
#.....
#....#
....#.