Limits 1s, 512 MB

The game of mines is a tricky one. You start with a grid and you click your way through the cells to find out what's under them. If you click on a cell with a mine under it, it's game over! If you click on a cell without a mine under it, you get to continue. Every time you uncover an empty cell, the cell may show a number indicating the number of mines that are around it in the 8 adjacent cells.

In this problem, you will be given a grid with the locations of all of the mines. You will then have to print the same grid with the appropriate numbers in the empty cells.

If a cell does not have any mine in its adjacent cells, you will leave the cell unchanged.

Input

The input will start with two integers, RR and CC (0<R,C100 < R, C ≤ 10). The following RR lines will each contain CC characters representing the contents of the corresponding cells.

An asterisk (*) is used to indicate a mine and a dot (.) is used indicate an empty cell.

Output

Print the same grid, but with the appropriate numbers in the cells that has mines adjacent to them.

Sample

InputOutput
3 9
.**..*...
....*..**
..*......
1**22*222
1333*22**
.1*211122

Submit

Login to submit.

Statistics

94% Solution Ratio
alexwiceEarliest, Sep '19
showmic96Fastest, 0.0s
peppermintLightest, 0 B
Nusab19Shortest, 297B
Toph uses cookies. By continuing you agree to our Cookie Policy.