Problem:


Score : 200 points

Problem Statement

You are given an H × W grid.

The squares in the grid are described by H strings, S_1,...,S_H.

The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W).

. stands for an empty square, and # stands for a square containing a bomb.  

Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square.

(Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.)

He decides to replace each . in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square.  

Print the strings after the process.  

Constraints

1 \leq H,W \leq 50

S_i is a string of length W consisting of # and ..

Input

Input is given from Standard Input in the following format:  

H W
S_1
:
S_H

Output

Print the H strings after the process.

The i-th line should contain a string T_i of length W, where the j-th character in T_i corresponds to the square at the i-th row from the top and j-th row from the left in the grid (1 \leq i \leq H, 1 \leq j \leq W).  

Sample Input 1

3 5
.....
.#.#.
.....

Sample Output 1

11211
1#2#1
11211

For example, let us observe the empty square at the first row from the top and first column from the left.

There is one bomb square adjacent to this empty square: the square at the second row and second column.

Thus, the . corresponding to this empty square is replaced with 1.  

Sample Input 2

3 5
#####
#####
#####

Sample Output 2

#####
#####
#####

It is possible that there is no empty square.  

Sample Input 3

6 6
#####.
#.#.##
####.#
.#..#.
#.##..
#.#...

Sample Output 3

#####3
#8#7##
####5#
4#65#2
#5##21
#4#310



Sample input:
3 5
.....
.#.#.
.....


Sample output:
11211
1#2#1
11211

Submission status: Runtime Error

Solution code:
h,w = map(int, input().split())
m_list = []
for i in range(h):
    m_list.append([i for i in input()])
for m in range(h):
    for i in range(w):
        if m == 0:
            if i == 0:
                if m_list[m][i] != "#":
                    m_list[m][i] = 0
                    x = m_list[m][i]
                    if m_list[m][i+1] == "#":
                        x += 1
                    if m_list[m+1][i+1] == "#":
                        x += 1
                    if m_list[m+1][i] == "#":
                        x += 1
                    m_list[m][i] = str(x)
            elif i == w-1:
                if m_list[m][i] != "#":
                    m_list[m][i] = 0
                    x = m_list[m][i]
                    if m_list[m][i-1] == "#":
                        x += 1
                    if m_list[m+1][i-1] == "#":
                        x += 1
                    if m_list[m+1][i] == "#":
                        x += 1
                    m_list[m][i] = str(x)
            else:
                if m_list[m][i] != "#":
                    m_list[m][i] = 0
                    x = m_list[m][i]
                    if m_list[m][i-1] == "#":
                        x += 1
                    if m_list[m+1][i-1] == "#":
                        x += 1
                    if m_list[m+1][i] == "#":
                        x += 1    
                    if m_list[m][i+1] == "#":
                        x += 1
                    if m_list[m+1][i+1] == "#":
                        x += 1
                    m_list[m][i] = str(x)
        elif m == h-1:
            if i == 0:
                if m_list[m][i] != "#":
                    m_list[m][i] = 0
                    x = m_list[m][i]
                    if m_list[m][i+1] == "#":
                        x += 1
                    if m_list[m-1][i+1] == "#":
                        x += 1
                    if m_list[m-1][i-1] == "#":
                        x += 1
                    m_list[m][i] = str(x)
            elif i == w-1:
                if m_list[m][i] != "#":
                    m_list[m][i] = 0
                    x = m_list[m][i]
                    if m_list[m][i-1] == "#":
                        x += 1
                    if m_list[m-1][i-1] == "#":
                        x += 1
                    if m_list[m-1][i] == "#":
                        x += 1
                    m_list[m][i] = str(x)
            else:
                if m_list[m][i] != "#":
                    m_list[m][i] = 0
                    x = m_list[m][i]
                    if m_list[m][i-1] == "#":
                        x += 1
                    if m_list[m-1][i-1] == "#":
                        x += 1
                    if m_list[m-1][i] == "#":
                        x += 1
                    if m_list[m][i+1] == "#":
                        x += 1
                    if m_list[m-1][i+1] == "#":
                        x += 1
                    m_list[m][i] = str(x)
        else:
            if i == 0:
                if m_list[m][i] != "#":
                    m_list[m][i] = 0
                    x = m_list[m][i]
                    if m_list[m-1][i] == "#":
                        x += 1
                    if m_list[m-1][i+1] == "#":
                        x += 1
                    if m_list[m][i+1] == "#":
                        x += 1
                    if m_list[m+1][i+1] == "#":
                        x += 1
                    if m_list[m+1][i] == "#":
                        x += 1
                    m_list[m][i] = str(x)
            elif i == w-1:
                if m_list[m][i] != "#":
                    m_list[m][i] = 0
                    x = m_list[m][i]
                    if m_list[m-1][i] == "#":
                        x += 1
                    if m_list[m-1][i-1] == "#":
                        x += 1
                    if m_list[m][i-1] == "#":
                        x += 1
                    if m_list[m+1][i-1] == "#":
                        x += 1
                    if m_list[m+1][i] == "#":
                        x += 1
                    m_list[m][i] = str(x)                    
            else:
                if m_list[m][i] != "#":
                    m_list[m][i] = 0
                    x = m_list[m][i]
                    if m_list[m-1][i] == "#":
                        x += 1
                    if m_list[m-1][i-1] == "#":
                        x += 1
                    if m_list[m][i-1] == "#":
                        x += 1
                    if m_list[m+1][i-1] == "#":
                        x += 1
                    if m_list[m+1][i] == "#":
                        x += 1        
                    if m_list[m+1][i+1] == "#":
                        x += 1
                    if m_list[m][i+1] == "#":
                        x += 1
                    if m_list[m-1][i+1] == "#":
                        x += 1 
                    m_list[m][i] = str(x)
for i in m_list:
    print("".join(i))

Submission status: Runtime Error

Solution code:
H, W = map(int, raw_input().split())
S = [raw_input() for i in range(H)]
C = [[0] * W for i in range(H)]
for i in range(H):
    for j in range(W):
        for di in range(-1, 1):
            if i + di < 0 or H <= i + di:
                continue
            for dj in range(-1, 1):
                if j + dj < 0 or W <= j + dj:
                    continue
                C[i][j] += 1 if S[i][j] == "#" else -1
for i in range(H):
    print "".join(C[i])

Submission status: Runtime Error

Solution code:
h,w = map(int,input().split())

s = ['-' * (w + 2)]
for i in range(h):
    s.append('-' + input() + '-')
s.append('-' * (w + 2))

for hi in range(1,h+1):
    ans=''
    for wi in range(1,h+1):
        if s[hi][wi] == '#':
            ans += '#'
        else:
            c = [s[hi-1][wi-1],s[hi][wi-1],s[hi+1][wi-1],s[hi-1][wi],s[hi+1][wi],s[hi-1][wi+1],s[hi][wi+1],s[hi+1][wi+1]]
            ans += str(c.count('#'))
    print(ans)

Submission status: Runtime Error

Solution code:
a,b = map(int,input().split(" "))
ar = [list(input()) for i in range(a)]
br = [["" for j in range(b)] for k in range(a)]
for c in range(a):
    for d in range(b):
        count = 0
        if ar[c][d] == "#":
            br[c][d] = "#"
        else:
            if c == 0:
                if d == 0:
                    if ar[c+1][d] == "#":
                        count += 1
                    if ar[c][d+1] == "#":
                        count += 1
                    if ar[c+1][d+1] == "#":
                        count += 1
                elif d == b-1:
                    if ar[c+1][d] == "#":
                        count += 1
                    if ar[c+1][d-1] == "#":
                        count += 1
                    if ar[c][d-1] == "#":
                        count += 1
                else:
                    if ar[c+1][d] == "#":
                        count += 1
                    if ar[c][d+1] == "#":
                        count += 1
                    if ar[c+1][d+1] == "#":
                        count += 1
                    if ar[c+1][d-1] == "#":
                        count += 1
                    if ar[c][d-1] == "#":
                        count += 1
            elif c == a-1:
                if d == 0:
                    if ar[c-1][d] == "#":
                        count += 1
                    if ar[c][d+1] == "#":
                        count += 1
                    if ar[c-1][d+1] == "#":
                        count += 1
                elif d == b-1:
                    if ar[c-1][d] == "#":
                        count += 1
                    if ar[c-1][d-1] == "#":
                        count += 1
                    if ar[c][d-1] == "#":
                        count += 1
                else:
                    if ar[c-1][d] == "#":
                        count += 1
                    if ar[c][d+1] == "#":
                        count += 1
                    if ar[c-1][d+1] == "#":
                        count += 1
                    if ar[c-1][d-1] == "#":
                        count += 1
                    if ar[c][d-1] == "#":
                        count += 1
            else:
                if d == 0:
                    if ar[c-1][d] == "#":
                        count += 1
                    if ar[c][d+1] == "#":
                        count += 1
                    if ar[c-1][d+1] == "#":
                        count += 1
                    if ar[c+1][d+1] == "#":
                        count += 1
                    if ar[c+1][d] == "#":
                        count += 1
                elif d == b-1:
                    if ar[c-1][d] == "#":
                        count += 1
                    if ar[c-1][d-1] == "#":
                        count += 1
                    if ar[c][d-1] == "#":
                        count += 1
                    if ar[c+1][d-1] == "#":
                        count += 1
                    if ar[c+1][d] == "#":
                        count += 1
                else:
                    if ar[c-1][d] == "#":
                        count += 1
                    if ar[c][d+1] == "#":
                        count += 1
                    if ar[c-1][d+1] == "#":
                        count += 1
                    if ar[c-1][d-1] == "#":
                        count += 1
                    if ar[c][d-1] == "#":
                        count += 1
                    if ar[c+1][d-1] == "#":
                        count += 1
                    if ar[c+1][d+1] == "#":
                        count += 1
                    if ar[c+1][d] == "#":
                        count += 1
            br[c][d] = str(count)
for b in br:
    print("".join(b))

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split())
s=[]
for i in range(h):
    s.append(str(input()))

slist=[list(s[i]) for i in range(h)]

ans=[[0 for i in range(w+2)] for j in range(h+2)]
for in range(h):
    for j in range(w):
        if(slist[i][j]=='#'):
            ans[i][j] += 1
            ans[i][j+1] += 1
            ans[i][j+2] += 1
            ans[i+1][j] += 1
            ans[i+1][j+2] += 1
            ans[i+2][j] += 1
            ans[i+2][j+1] += 1
            ans[i+2][j+2] += 1

for i in range(H):
    ansstr =""
    for j in range(W):
        if(Slist[i][j] == '.'):
            ansstr += str(ans[i+1][j+1])
        elif(Slist[i][j] == '#'):
            ansstr += Slist[i][j]
    print(ansstr)

Submission status: Runtime Error

Solution code:
h,w = map(int,input().split())
mine_list = [list(input()) for i in range(h)]

for id1 in range(h):
        outcome = ''
        for id2 in range(w):
                if mine_list[id1][id2] == '.':
                        count = 0
                        if id1 == 0:
                                if id2 == 0:
                                        if mine_list[id1][id2+1] == '#':
                                                count += 1
                                        if mine_list[id1+1][id2] == '#':
                                                count += 1
                                        if mine_list[id1+1][id2+1] == '#':
                                                count += 1
                                elif id2 == w-1:
                                        if mine_list[id1][id2-1] == '#':
                                                count += 1
                                        if mine_list[id1+1][id2-1] == '#':
                                                count += 1
                                        if mine_list[id1+1][id2] == '#':
                                                count += 1
                                else:
                                        if mine_list[id1][id2-1] == '#':
                                                count += 1
                                        if mine_list[id1][id2+1] == '#':
                                                count += 1
                                        if mine_list[id1+1][id2-1] == '#':
                                                count += 1
                                        if mine_list[id1+1][id2] == '#':
                                                count += 1
                                        if mine_list[id1+1][id2] == '#':
                                                count += 1
                        elif id1 == h-1:
                                if id2 == 0:
                                        if mine_list[id1-1][id2] == '#':
                                                count += 1
                                        if mine_list[id1-1][id2+1] == '#':
                                                count += 1
                                        if mine_list[id1][id2+1] == '#':
                                                count += 1
                                elif id2 == w-1:
                                        if mine_list[id1-1][id2-1] == '#':
                                                count += 1
                                        if mine_list[id1-1][id2] == '#':
                                                count += 1
                                        if mine_list[id1][id2-1] == '#':
                                                count += 1
                                else:
                                        if mine_list[id1-1][id2-1] == '#':
                                                count += 1
                                        if mine_list[id1-1][id2] == '#':
                                                count += 1
                                        if mine_list[id1-1][id2+1] == '#':
                                                count += 1
                                        if mine_list[id1][id2-1] == '#':
                                                count += 1
                                        if mine_list[id1][id2+1] == '#':
                                                count += 1
                        else:
                                if id2 == 0:
                                        if mine_list[id1-1][id2] == '#':
                                                count += 1
                                        if mine_list[id1-1][id2+1] == '#':
                                                count += 1
                                        if mine_list[id1][id2+1] == '#':
                                                count += 1
                                        if mine_list[id1+1][id2] == '#':
                                                count += 1
                                        if mine_list[id1+1][id2+1] == '#':
                                                count += 1
                                elif id2 == w-1:
                                        if mine_list[id1-1][id2-1] == '#':
                                                count += 1
                                        if mine_list[id1-1][id2] == '#':
                                                count += 1
                                        if mine_list[id1][id2-1] == '#':
                                                count += 1
                                        if mine_list[id1+1][id2-1] == '#':
                                                count += 1
                                        if mine_list[id1+1][id2] == '#':
                                                count += 1
                                else:
                                        if mine_list[id1-1][id2-1] == '#':
                                                count += 1
                                        if mine_list[id1-1][id2] == '#':
                                                count += 1
                                        if mine_list[id1-1][id2+1] == '#':
                                                count += 1
                                        if mine_list[id1][id2-1] == '#':
                                                count += 1
                                        if mine_list[id1][id2+1] == '#':
                                                count += 1
                                        if mine_list[id1+1][id2-1] == '#':
                                                count += 1
                                        if mine_list[id1+1][id2] == '#':
                                                count += 1
                                        if mine_list[id1+1][id2+1] == '#':
                                                count += 1
                        outcome += str(count)
                else:
                        outcome += '#'
        print(outcome)

Submission status: Runtime Error

Solution code:


H,W=map(int,input().split())
field=[[0]*W for i in range(H)]


tmp_str=input()
if(tmp_str[0]=="#"):
    field[0][0]="#"
    field[0][1]+=1
    field[1][1]+=1
    field[1][0]+=1


for i in range(1,W-1):
    if(tmp_str[i]=="#"):
        for k in range(0,2):
            for l in range(-1,2):
                try:
                    field[k][i+l]+=1
                except:
                    pass
        field[0][i]="#"

if(tmp_str[W-1]=="#"):
    for j in range(0,2):
        for k in range(-1,1):
            try:
                field[j][W-1+k]+=1
            except:
                pass
    field[0][W-1]="#"


    
for i in range(1,H-1):
    tmp_str=input()
    if(tmp_str[0]=="#"):
       for j in range(-1,2):
           for k in range(0,2):
               try:
                   field[i+j][k]+=1
               except:
                    pass
       field[i][0]="#"

    for j in range(1,W-1):
        if(tmp_str[j]=="#"):
            for k in range(-1,2):
                for l in range(-1,2):
                    try:
                        field[i+k][j+l]+=1
                    except:
                        pass
            field[i][j]="#"

    if(tmp_str[W-1]=="#"):
        for j in range(-1,2):
            for k in range(-1,1):
                try:
                    field[i+j][W-1+k]+=1
                except:
                    pass
        field[i][W-1]="#"




tmp_str=input()
if(tmp_str[0]=="#"):
    for j in range(-1,1):
        for k in range(0,2):
            try:
                field[H-1+j][k]+=1
            except:
                pass
    field[H-1][0]="#"


for i in range(1,W-1):
    if(tmp_str[i]=="#"):
        for k in range(-1,1):
            for l in range(-1,2):
                try:
                    field[H-1+k][i+l]+=1
                except:
                    pass
        field[H-1][i]="#"

if(tmp_str[W-1]=="#"):
    for j in range(-1,1):
        for k in range(-1,1):
            try:
                field[H-1+j][W-1+k]+=1
            except:
                pass
    field[H-1][W-1]="#"

for i in range(H):
    print("".join(list(map(str,field[i]))))

Submission status: Runtime Error

Solution code:
H,W=map(int,input().split())
field=[[0]*W for i in range(H)]


tmp_str=input()
if(tmp_str[0]=="#"):
    field[0][0]="#"
    field[0][1]+=1
    field[1][1]+=1
    field[1][0]+=1


for i in range(1,W-1):
    if(tmp_str[i]=="#"):
        for k in range(0,2):
            for l in range(-1,2):
                try:
                    field[k][i+l]+=1
                except:
                    pass
        field[0][i]="#"

if(tmp_str[W-1]=="#"):
    for j in range(0,2):
        for k in range(-1,1):
            try:
                field[j][W-1+k]+=1
            except:
                pass
    field[0][W-1]="#"


    
for i in range(1,H-1):
    tmp_str=input()
    if(tmp_str[0]=="#"):
       for j in range(-1,2):
           for k in range(0,2):
               try:
                   field[i][k]+=1
                except:
                    pass
        field[i][0]="#"

    for j in range(1,W-1):
        if(tmp_str[j]=="#"):
            for k in range(-1,2):
                for l in range(-1,2):
                    try:
                        field[i+k][j+l]+=1
                    except:
                        pass
            field[i][j]="#"

    if(tmp_str[W-1]=="#"):
        for j in range(-1,2):
            for k in range(-1,1):
                try:
                    field[i+j][W-1+k]+=1
                except:
                    pass
        field[i][W-1]="#"




tmp_str=input()
if(tmp_str[0]=="#"):
    for j in range(-1,1):
        for k in range(0,2):
            try:
                field[H-1+j][k]+=1
            except:
                pass
    field[H-1][0]="#"


for i in range(1,W-1):
    if(tmp_str[i]=="#"):
        for k in range(-1,1):
            for l in range(-1,2):
                try:
                    field[H-1+k][i+l]+=1
                except:
                    pass
        field[H-1][i]="#"

if(tmp_str[W-1]=="#"):
    for j in range(-1,1):
        for k in range(-1,1):
            try:
                field[H-1+j][W-1+k]+=1
            except:
                pass
    field[H-1][W-1]="#"

for i in range(H):
    print("".join(list(map(str,field[i]))))

Submission status: Runtime Error

Solution code:


H,W=map(int,input().split())
field=[[0]*W for i in range(H)]


tmp_str=input()
if(tmp_str[0]=="#"):
    field[0][0]="#"
    field[0][1]+=1
    field[1][1]+=1
    field[1][0]+=1


for i in range(1,W-1):
    if(tmp_str[i]=="#"):
        for k in range(0,2):
            for l in range(-1,2):
                try:
                    field[k][i+l]+=1
                except:
                    pass
        field[0][i]="#"

if(tmp_str[W-1]=="#"):
    for j in range(0,2):
        for k in range(-1,1):
            try:
                field[j][W-1+k]+=1
            except:
                pass
    field[0][W-1]="#"


    
for i in range(1,H-1):
    tmp_str=input()
    if(tmp_str[0]=="#"):
        field[i][0]="#"
        field[i][1]+=1
        field[i+1][1]+=1
        field[i+1][0]+=1
        try:
            field[i-1][0]+=1
        except:
            pass
        try:
            field[i-1][1]+=1
        except:
            pass

    for j in range(1,W-1):
        if(tmp_str[j]=="#"):
            for k in range(-1,2):
                for l in range(-1,2):
                    try:
                        field[i+k][j+l]+=1
                    except:
                        pass
            field[i][j]="#"

    if(tmp_str[W-1]=="#"):
        for j in range(-1,2):
            for k in range(-1,1):
                try:
                    field[i+j][W-1+k]+=1
                except:
                    pass
        field[i][W-1]="#"




tmp_str=input()
if(tmp_str[0]=="#"):
    for j in range(-1,1):
        for k in range(0,2):
            try:
                field[H-1+j][k]+=1
            except:
                pass
    field[H-1][0]="#"


for i in range(1,W-1):
    if(tmp_str[i]=="#"):
        for k in range(-1,1):
            for l in range(-1,2):
                try:
                    field[H-1+k][i+l]+=1
                except:
                    pass
        field[H-1][i]="#"

if(tmp_str[W-1]=="#"):
    for j in range(-1,1):
        for k in range(-1,1):
            try:
                field[H-1+j][W-1+k]+=1
            except:
                pass
    field[H-1][W-1]="#"

for i in range(H):
    print("".join(list(map(str,field[i]))))

Submission status: Runtime Error

Solution code:
H, W = [int(s) for s in input().rstrip().split()]
sqare = [list('.' * (W+2)) for _ in range(H+2)]
for i in range(1, H+1):
    S = list(input().rstrip())
    sqare[i][1:H+1] = S

bomb = [[0 for _ in range(W+2)] for _ in range(H+2)]

for i in range(1, H+1):
    for j in range(1, W+1):
        if sqare[i][j] != '#':
            sqare[i][j] = 0
            for x in range(i-1, i+2):
                for y in range(j-1, j+2):                
                    if not(x == i and y == j) and sqare[x][y] == '#':
                        sqare[i][j] += 1

for i in range(1, H+1):
    for j in range(1, W+1):
        print(sqare[i][j], end='')
    print('')

Submission status: Runtime Error

Solution code:
H, W = [int(s) for s in input().rstrip().split()]
sqare = [list('.' * (W+2)) for _ in range(H+2)]
for i in range(1, H+1):
    S = list(input().rstrip())
    sqare[i][1:H+1] = S

bomb = [[0 for _ in range(W+2)] for _ in range(H+2)]

for i in range(1, H+1):
    for j in range(1, W+1):
        for x in range(i-1, i+2):
            for y in range(j-1, j+2):
                if not(x == i and y == j) and sqare[x][y] == '#':
                    bomb[i][j] += 1

for i in range(1, H+1):
    for j in range(1, W+1):
        if sqare[i][j] == '.':
            print(bomb[i][j], end='')
        else:
            print(sqare[i][j], end='')                        
    print('')

Submission status: Runtime Error

Solution code:
H, W = [int(s) for s in input().rstrip().split()]
sqare = [list('.' * (W+2)) for _ in range(H+2)]
for i in range(1, H+1):
    S = list(input().rstrip())
    sqare[i][1:H+1] = S

bomb = [[0 for _ in range(W+2)] for _ in range(H+2)]    
for i in range(1, H+1):
    for j in range(1, W+1):
        for x in range(i-1, i+2):
            for y in range(j-1, j+2):
                if not(x == i and y == j) and sqare[x][y] == '#':
                    bomb[i][j] += 1

for i in range(1, H+1):
    for j in range(1, W+1):
        if sqare[i][j] == '.':
            print(bomb[i][j], end='')
        else:
            print(sqare[i][j], end='')                        
    print('')

Submission status: Runtime Error

Solution code:
import numpy as np
ans = []
H, W = map(int, input().split())
S = []
S.append('.'*(W+2))
for i in range(H):
    S.append('.'+input() + '.')
S.append('.'*(W+2))

for y in range(1, H+1):
    for x in range(1, W+1):
        if S[y][x] == '.':
            cnt = S[y][x-1].count('#')+S[y][x+1].count('#')+S[y-1][x-1:x+2].count('#')+S[y+1][x-1:x+2].count('#')
            ans.append(cnt)
        else:
            ans.append('#')
np_ans = np.array(ans)
re_ans = np.reshape(np_ans, (H, W))
for i in re_ans:
    print(''.join(i))

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
S = ["..................................................."]
for i in range(H):
    S.append(input())
for i in range(H+1):
    S[i] = '.' + S[i] + '.'
S.append("...................................................")
ans = [[0] * W for i in range(H)]

for i in range(1,H+1):
    for j in range(1,W+1):
        if S[i][j] == '#':
            ans[i-1][j-1] = '#'
        else:
            count = []
            for a in range(i-1, i+2):
                for b in range(j-1, j+2):
                    count.append(S[a][b])
            ans[i-1][j-1] = count.count('#')

for i in range(H):
    yoko = ''
    for j in range(W):
        yoko += str(ans[i][j])
    print(yoko)

Submission status: Runtime Error

Solution code:
import numpy as np
h,w=map(int, input().split())
a=[list(input()) for i in range(h)]
a=np.array(a)
for i in range(h):
    for j in range(w):
        if a[i][j]=='.':
            a[i][j]=sum(sum(a[max(i-1,0):min(i+2,w),max(j-1,0):min(j+2,w)]=='#'))
for i in a:
    print(''.join(i))