Buggy python submission (verdict: Runtime Error):
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('')

Fixed submission:
H, W = [int(s) for s in input().rstrip().split()]
S = [list(input().rstrip()) for _ in range(H)]

for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            continue
        bomb = 0
        for x in range(i-1, i+2):
            for y in range(j-1, j+2):
                if 0 <= x < H and 0 <= y < W and S[x][y] == '#':
                    bomb += 1
        S[i][j] = str(bomb)

for s in S:
    print(''.join(s))

Buggy python submission (verdict: Runtime Error):
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('')

Fixed submission:
H, W = [int(s) for s in input().rstrip().split()]
S = [list(input().rstrip()) for _ in range(H)]

for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            continue
        bomb = 0
        for x in range(i-1, i+2):
            for y in range(j-1, j+2):
                if 0 <= x < H and 0 <= y < W and S[x][y] == '#':
                    bomb += 1
        S[i][j] = str(bomb)

for s in S:
    print(''.join(s))

Buggy python submission (verdict: Runtime Error):
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('')

Fixed submission:
H, W = [int(s) for s in input().rstrip().split()]
S = [list(input().rstrip()) for _ in range(H)]

for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            continue
        bomb = 0
        for x in range(i-1, i+2):
            for y in range(j-1, j+2):
                if 0 <= x < H and 0 <= y < W and S[x][y] == '#':
                    bomb += 1
        S[i][j] = str(bomb)

for s in S:
    print(''.join(s))