Problem B: Minesweeper mines calculation

Problem B: Minesweeper mines calculation

Time Limit: 1 Sec  Memory Limit: 64 MB
Submit: 12  Solved: 1
[Submit] [Status] [Web Board] [Creator:]

Description

Minesweeper is a very classic stand-alone game. The essence of it is to judge whether the unopened grid is a mine by the number of surrounding mines that have been given from the opened grids.

Now given the mine distribution in the minefield of n rows and m columns, and calculate the number of mines around each grid which does not have mine.

Note: There are eight grids around each grid: up, down, left, right, top left, top right, bottom left, bottom right.

Input

The first line contains two integers, n and m, which represent the number of rows and columns of the minefield. 1 <= n <= 100, 1 <= m <= 100. The next n lines have m characters per line, ‘*’ means that the corresponding grid is a mine, ‘? ’ indicates that there is no mine in the corresponding grid. There are no separators between characters.

Output

Output n lines, m characters per line, describing the entire minefield. If the corresponding grid is a mine, then represent it by ‘*’, otherwise represent the grid by the number of surrounding mines. There are no separators between characters.

Sample Input Copy

3 3
*??
???
?*?

Sample Output Copy

*10
221
1*1