Buggy python submission (verdict: Runtime Error):
H,W = (int(i) for i in input().split())

original = [input() for i in range(H)]
sujimaru = [[0 for i in range(W+2)for j in range(H+2)]]

for j in range(H):
    for i in range(W):
        if(original[i][j] == "#"):
            sujimaru[i][j] += 1
            sujimaru[i+1][j] += 1
            sujimaru[i+2][j] += 1
            sujimaru[i][j+1] += 1
            sujimaru[i+2][j+1] += 1
            sujimaru[i][j+2] += 1
            sujimaru[i+1][j+2] += 1
            sujimaru[i+2][j+2] += 1

d = [""]*H
for j in range(H):
    for i in range(W):
        if(original[j][i] == "."):
            d[j] += str(sujimaru[j+1][i+1])
        else:
            d[j] += "#"

for s in d:
    print(d)

Fixed submission:
H,W = (int(i) for i in input().split())

#囲い付きで入力　上下左右斜めを確認するとき用
firstline = "*"*(W+2)
bomb = [firstline]
for i in range(H):
    line = "*" + input() + "*"
    bomb.append(line)
lastline = "*"*(W+2)
bomb.append(lastline)

#答えの配列
answer = [[0]*W for i in range(H)]
for i in range(H):
    for j in range(W):
        if bomb[i+1][j+1] == "#":
            answer[i][j] = "#"
        else:
            if bomb[i+1+1][j+1+1] == "#":
                answer[i][j] += 1
            if bomb[i+1+1][j+1+0] == "#":
                answer[i][j] += 1
            if bomb[i+1+1][j+1-1] == "#":
                answer[i][j] += 1
            if bomb[i+1+0][j+1+1] == "#":
                answer[i][j] += 1
            if bomb[i+1+0][j+1-1] == "#":
                answer[i][j] += 1
            if bomb[i+1-1][j+1+1] == "#":
                answer[i][j] += 1
            if bomb[i+1-1][j+1+0] == "#":
                answer[i][j] += 1
            if bomb[i+1-1][j+1-1] == "#":
                answer[i][j] += 1

#print(answer)
for i in range(H):
    tmp = ""
    for j in range(W):
        tmp += str(answer[i][j])
    print(tmp)

Buggy python submission (verdict: Runtime Error):
H,W = (int(i) for i in input().split())

original = [input() for i in range(H)]
sujimaru = [[0 for i in range(W+2)for j in range(H+2)]]

for j in range(H):
    for i in range(W):
        if(original[i][j] == "#"):
            sujimaru[i][j] += 1
            sujimaru[i+1][j] += 1
            sujimaru[i+2][j] += 1
            sujimaru[i][j+1] += 1
            sujimaru[i+2][j+1] += 1
            sujimaru[i][j+2] += 1
            sujimaru[i+1][j+2] += 1
            sujimaru[i+2][j+2] += 1

d = [""]*H
for j in range(H):
    for i in range(W):
        if(original[j][i] == "."):
            d[j] += str(sujimaru[j+1][i+1])
        else:
            d[j] += "#"

for s in d:
    print(s)

Fixed submission:
H,W = (int(i) for i in input().split())

#囲い付きで入力　上下左右斜めを確認するとき用
firstline = "*"*(W+2)
bomb = [firstline]
for i in range(H):
    line = "*" + input() + "*"
    bomb.append(line)
lastline = "*"*(W+2)
bomb.append(lastline)

#答えの配列
answer = [[0]*W for i in range(H)]
for i in range(H):
    for j in range(W):
        if bomb[i+1][j+1] == "#":
            answer[i][j] = "#"
        else:
            if bomb[i+1+1][j+1+1] == "#":
                answer[i][j] += 1
            if bomb[i+1+1][j+1+0] == "#":
                answer[i][j] += 1
            if bomb[i+1+1][j+1-1] == "#":
                answer[i][j] += 1
            if bomb[i+1+0][j+1+1] == "#":
                answer[i][j] += 1
            if bomb[i+1+0][j+1-1] == "#":
                answer[i][j] += 1
            if bomb[i+1-1][j+1+1] == "#":
                answer[i][j] += 1
            if bomb[i+1-1][j+1+0] == "#":
                answer[i][j] += 1
            if bomb[i+1-1][j+1-1] == "#":
                answer[i][j] += 1

#print(answer)
for i in range(H):
    tmp = ""
    for j in range(W):
        tmp += str(answer[i][j])
    print(tmp)