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())
S = [["."] * (W + 2)]
for _ in range(H):
    S.append([".", *list(input()), "."])
S.append(["."] * (W + 2))

ans = [[-1] * W for _ in range(H)]

for i in range(1, H + 1):
    for j in range(1, W + 1):
        if S[i][j] == "#":
            continue
        cnt = 0
        if S[i - 1][j - 1] == "#":
            cnt += 1
        if S[i][j - 1] == "#":
            cnt += 1
        if S[i + 1][j - 1] == "#":
            cnt += 1
        if S[i - 1][j] == "#":
            cnt += 1
        if S[i + 1][j] == "#":
            cnt += 1
        if S[i - 1][j + 1] == "#":
            cnt += 1
        if S[i][j + 1] == "#":
            cnt += 1
        if S[i + 1][j + 1] == "#":
            cnt += 1
        ans[i - 1][j - 1] = cnt

for i in ans:
    p = ["#" if x == -1 else x for x in i]
    print(*p, sep="")

Submission status: Runtime Error

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

for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            continue
        count = 0
        for a in range(i-1, i+2):
            for b in range(j-1, j+2):
                c += all((min(a,b)>=0, a < h, b < w)) and s[a][b] == '#'

            if s[i][j] == '.':
                s[i][j] = c
for c in s:
    print(c)

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split())
field=[]
nfield=[[] for i in range(h)]
for i in range(n):
  field.append(input())
def check(a,b):
  num=0
  if field[a][b]=="#":
    return
  for i in range(a-1,a+2):
    for j in range(b-1,b+2):
      try:
        if field[i][j]=="#":
          num+=1
      except:
        pass
  return num
for i in range(h):
  for j in range(w):
    if field[i][j]==".":
      nfield[i][j]=check(i,j)
    else:
      nfield[i][j]="#"
for i in range(h):
  for j in range(w):
    if j != w-1:
      print(nfield[i],end="")
    else:
      print(nfield[i])

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
import numpy as np
x = np.empty((H,W), dtype=object)
for i in range(H):
  x[i,] = map(int, input().split())

temp_list = []
for i in range(H):
  for j in range(W):
    if x[i,j] == "#":
      pass
    elif i == 0 and j == 0:
      temp_list = [x[i,j+1],x[i+1,j],x[i+1,j+1]]
      counts = temp_list.count("#")
      x[i,j] = counts
    elif i == 0 and j == W-1:
      temp_list = [x[i,j-1],x[i+1,j],x[i+1,j-1]]
      counts = temp_list.count("#")
      x[i,j] = counts
    elif i == H-1 and j == 0:
      temp_list = [x[i-1,j],x[i-1,j+1],x[i,j+1]]
      counts = temp_list.count("#")
      x[i,j] = counts
    elif i == H-1 and j == W-1:
      temp_list = [x[i-1,j-1],x[i-1,j],x[i,j-1]]
      counts = temp_list.count("#")
      x[i,j] = counts
    elif i == 0:
      temp_list = [x[i,j-1],x[i,j+1],x[i+1,j-1],x[i+1,j],x[i+1,j+1]]
      counts = temp_list.count("#")
      x[i,j] = counts
    elif i == H-1:
      temp_list = [x[i,j-1],x[i,j+1],x[i-1,j-1],x[i-1,j],x[i-1,j+1]]
      counts = temp_list.count("#")
      x[i,j] = counts
    elif j == 0:
      temp_list = [x[i-1,j],x[i-1,j+1],x[i,j+1],x[i+1,j],x[i+1,j+1]]
      counts = temp_list.count("#")
      x[i,j] = counts
    elif j == W-1:
      temp_list = [x[i-1,j-1],x[i-1,j],x[i,j-1],x[i+1,j-1],x[i+1,j]]
      counts = temp_list.count("#")
      x[i,j] = counts
    else:
      temp_list = [x[i-1,j-1],x[i-1,j],x[i-1,j+1],x[i,j-1],x[i,j+1],x[i+1,j-1],x[i+1,j],x[i+1,j+1]]
      counts = temp_list.count("#")
      x[i,j] = counts

printlist = [""] * H
for i in range(H):
  for j in range(W):
    printlist[i] += str(x[i,j]) 

for i in range(H):
    print(printlist[i])

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
import numpy as np
x = np.empty((H,W), dtype=object)
for i in range(H):
  x[i,] = map(int, input().split())

temp_list = []
for i in range(H):
  for j in range(W):
    if x[i,j] == "#":
      continue
    elif i == 0 and j == 0:
      temp_list = [x[i,j+1],x[i+1,j],x[i+1,j+1]]
      counts = temp_list.count("#")
      x[i,j] = counts
    elif i == 0 and j == W-1:
      temp_list = [x[i,j-1],x[i+1,j],x[i+1,j-1]]
      counts = temp_list.count("#")
      x[i,j] = counts
    elif i == H-1 and j == 0:
      temp_list = [x[i-1,j],x[i-1,j+1],x[i,j+1]]
      counts = temp_list.count("#")
      x[i,j] = counts
    elif i == H-1 and j == W-1:
      temp_list = [x[i-1,j-1],x[i-1,j],x[i,j-1]]
      counts = temp_list.count("#")
      x[i,j] = counts
    elif i == 0:
      temp_list = [x[i,j-1],x[i,j+1],x[i+1,j-1],x[i+1,j],x[i+1,j+1]]
      counts = temp_list.count("#")
      x[i,j] = counts
    elif i == H-1:
      temp_list = [x[i,j-1],x[i,j+1],x[i-1,j-1],x[i-1,j],x[i-1,j+1]]
      counts = temp_list.count("#")
      x[i,j] = counts
    elif j == 0:
      temp_list = [x[i-1,j],x[i-1,j+1],x[i,j+1],x[i+1,j],x[i+1,j+1]]
      counts = temp_list.count("#")
      x[i,j] = counts
    elif j == W-1:
      temp_list = [x[i-1,j-1],x[i-1,j],x[i,j-1],x[i+1,j-1],x[i+1,j]]
      counts = temp_list.count("#")
      x[i,j] = counts
    else:
      temp_list = [x[i-1,j-1],x[i-1,j],x[i-1,j+1],x[i,j-1],x[i,j+1],x[i+1,j-1],x[i+1,j],x[i+1,j+1]]
      counts = temp_list.count("#")
      x[i,j] = counts

printlist = [""] * H
for i in range(H):
  for j in range(W):
    printlist[i] += str(x[i,j]) 

for i in range(H):
    print(printlist[i])

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split())
field=[]
for i in range(n):
  field.append(input())
def check(a,b):
  num=0
  if field[a][b]=="#":
    return
  for i in range(a-1,a+2):
    for j in range(b-1,b+2):
      try:
        if field[i][j]=="#":
          num+=1
      except:
        pass
  return num
for i in range(h):
  for j in range(w):
    if field[i][j]==".":
      field[i][j]==check(i,j)
for i in range(h):
  print(field[i])

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
import numpy as np
x = np.zeros((H,W))
for i in range(H):
  x[i,] = map(int, input().split())

temp_list = []
for i in range(H):
  for j in range(W):
    if x[i,j] == "#":
      continue
    elif i == 0 and j == 0:
      temp_list = [x[i,j+1],x[i+1,j:j+1]]
      counts = temp_list.count("#")
      x[i,j] = counts
    elif i == 0 and j == W:
      temp_list = [x[i,j-1],x[i+1,j:j+1]]
      counts = temp_list.count("#")
      x[i,j] = counts
    elif i == H and j == 0:
      temp_list = [x[i-1,j:j+1],x[i,j+1]]
      counts = temp_list.count("#")
      x[i,j] = counts
    elif i == H and j == W:
      temp_list = [x[i-1,j-1:j],x[i,j-1]]
      counts = temp_list.count("#")
      x[i,j] = counts
    elif i == 0:
      temp_list = [x[i,j-1],x[i,j+1],x[i+1,j-1:j+1]]
      counts = temp_list.count("#")
      x[i,j] = counts
    elif i == H:
      temp_list = [x[i,j-1],x[i,j+1],x[i-1,j-1:j+1]]
      counts = temp_list.count("#")
      x[i,j] = counts
    elif j == 0:
      temp_list = [x[i-1,j:j+1],x[i,j+1],x[i+1,j:j+1]]
      counts = temp_list.count("#")
      x[i,j] = counts
    elif j == W:
      temp_list = [x[i-1,j-1:j],x[i,j-1],x[i+1,j-1:j]]
      counts = temp_list.count("#")
      x[i,j] = counts
    else:
      temp_list = [x[i-1,j-1:J+1],x[i,j-1],x[i,j+1],x[i+1,j-1:j+1]]
      counts = temp_list.count("#")
      x[i,j] = counts
      
for i in range(H):
  print(x[i,])

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
S = [input() for _ in range(H)]
S_ans = [[0 for i in range(W)] for j in range(H)]

for j in range(H):
    for i in range(W):
        if S[j][i] == '#':
            S_ans[j][i] = '#'

            # 左端のケース
            if j == 0:
                # 上下端のケース
                if i == 0 and i == H -1:
                    if j + 2 <= H:
                        if S[j + 1][i]:
                            S_ans[j + 1][i] += 1
                # 上端のケース
                elif i == 0:
                    if j + 2 <= H:
                        if S[j + 1][i] == '.':
                            S_ans[j + 1][i] += 1
                    if i + 2 <= W:
                        if S[j][i + 1] == '.':
                            S_ans[j][i + 1] += 1
                    if j + 2 <= H and i + 2 <= W:
                        if S[j + 1][i + 1] == '.':
                            S_ans[j + 1][i + 1] += 1
                # 下端のケース
                elif i == W - 1:
                    if j + 2 <= H:
                        if S[j + 1][i] == '.':
                            S_ans[j + 1][i] += 1
                    if i >= 1:
                        if S[j][i - 1] == '.':
                            S_ans[j][i - 1] += 1
                    if j + 2 <= H and i >= 1:
                        if S[j + 1][i - 1] == '.':
                            S_ans[j + 1][i - 1] += 1
                # 上下の端ではないケース
                else:
                    if j + 2 <= H:
                        if S[j + 1][i] == '.':
                            S_ans[j + 1][i] += 1
                    if i + 2 <= W:
                        if S[j][i + 1] == '.':
                            S_ans[j][i + 1] += 1
                    if j + 2 <= H and i + 2 <= W:
                        if S[j + 1][i + 1] == '.':
                            S_ans[j + 1][i + 1] += 1
                    if i >= 1:
                        if S[j][i - 1] == '.':
                            S_ans[j][i - 1] += 1
                    if j + 2 <= H and i >= 1:
                        if S[j + 1][i - 1] == '.':
                            S_ans[j + 1][i - 1] += 1
            # 右端のケース
            elif j == H - 1:
                # 上下端のケース
                if i == 0 and i == W -1:
                    if j >= 1:
                        if S[j - 1][i]:
                            S_ans[j - 1][i] += 1
                # 上端のケース
                elif i == 0:
                    if j - 1 >= 0:
                        if S[j - 1][i] == '.':
                            S_ans[j - 1][i] += 1
                    if i + 2 <= W:
                        if S[j][i + 1] == '.':
                            S_ans[j][i + 1] += 1
                    if j - 1 >= 0 and i + 2 <= W:
                        if S[j - 1][i + 1] == '.':
                            S_ans[j - 1][i + 1] += 1
                # 下端のケース
                elif i == W - 1:
                    if j - 1 >= 0:
                        if S[j - 1][i] == '.':
                            S_ans[j - 1][i] += 1
                    if i >= 1:
                        if S[j][i - 1] == '.':
                            S_ans[j][i - 1] += 1
                    if j - 1 > 0 and i >= 1:
                        if S[j - 1][i - 1] == '.':
                            S_ans[j - 1][i - 1] += 1
                # 上下の端ではないケース
                else:
                    if j - 1 >= 0:
                        if S[j - 1][i] == '.':
                            S_ans[j - 1][i] += 1
                    if i + 2 <= W:
                        if S[j][i + 1] == '.':
                            S_ans[j][i + 1] += 1
                    if j - 1 >= 0 and i + 2 <= W:
                        if S[j - 1][i + 1] == '.':
                            S_ans[j - 1][i + 1] += 1
                    if i >= 1:
                        if S[j][i - 1] == '.':
                            S_ans[j][i - 1] += 1
                    if j - 1 > 0 and i >= 1:
                        if S[j - 1][i - 1] == '.':
                            S_ans[j - 1][i - 1] += 1
            # 左右の端ではないケース
            else:
                # 上下端のケース
                if i == 0 and i == W - 1:
                    if j + 2 <= H:
                        if S[j + 1][i]:
                            S_ans[j + 1][i] += 1
                    if j >= 1:
                        if S[j - 1][i]:
                            S_ans[j - 1][i] += 1
                # 上橋のケース
                elif i == 0:
                    if j - 1 >= 0:
                        if S[j - 1][i] == '.':
                            S_ans[j - 1][i] += 1
                    if j + 2 <= H:
                        if S[j + 1][i] == '.':
                            S_ans[j + 1][i] += 1
                    if i + 2 <= W:
                        if S[j][i + 1] == '.':
                            S_ans[j][i + 1] += 1
                        if S[j + 1][i + 1] == '.':
                            S_ans[j + 1][i + 1] += 1
                        if S[j - 1][i + 1] == '.':
                            S_ans[j - 1][i + 1] += 1
                # 下端のケース
                elif i == W - 1:
                    if j - 1 >= 0:
                        if S[j - 1][i] == '.':
                            S_ans[j - 1][i] += 1
                    if j + 2 <= H:
                        if S[j + 1][i] == '.':
                            S_ans[j + 1][i] += 1
                    if i >= 1:
                        if S[j][i - 1] == '.':
                            S_ans[j][i - 1] += 1
                        if S[j + 1][i - 1] == '.':
                            S_ans[j + 1][i - 1] += 1
                        if S[j - 1][i - 1] == '.':
                            S_ans[j - 1][i - 1] += 1
                # 上下の端ではないケース
                else:
                    if j - 1 >= 0:
                        if S[j - 1][i] == '.':
                            S_ans[j - 1][i] += 1
                    if j + 2 <= H:
                        if S[j + 1][i] == '.':
                            S_ans[j + 1][i] += 1
                    if i + 2 <= W:
                        if S[j][i + 1] == '.':
                            S_ans[j][i + 1] += 1
                        if S[j + 1][i + 1] == '.':
                            S_ans[j + 1][i + 1] += 1
                        if S[j - 1][i + 1] == '.':
                            S_ans[j - 1][i + 1] += 1
                    if i >= 1:
                        if S[j][i - 1] == '.':
                            S_ans[j][i - 1] += 1
                        if S[j + 1][i - 1] == '.':
                            S_ans[j + 1][i - 1] += 1
                        if S[j - 1][i - 1] == '.':
                            S_ans[j - 1][i - 1] += 1

for i in range(H):
    print(''.join([str(s) for s in S_ans[i]]))

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())

Ss = [[-1 if c == "#" else 0 for c in input()] for _ in range(H)]

def plus(i, j):
  if 0 <= i < H and 0 <= j < W:
    if Ss[i][j] >= 0:
      Ss[i][j] += 1

for i in range(H):
  for j in range(W):
    for x, y in ((x,y) for x in range(-1, 2) for y in range(-1, 2):
      if x != 0 or y != 0:
        plus(i, j)

for i in range(H):
  for j in range(W):
    print("#" if Ss[i][j] == -1 else Ss[i][j], end="")

Submission status: Runtime Error

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

ls = ['.' for i in range(w)]

s.insert(0,ls)
s.insert(-1,ls)

for i in range(h+2):
    s[i].insert(0,".")
    s[i].insert(-1,".")

for j in range(1,h+1):
    for k in range(1,w+1):
        
        if s[i][j] == ".":
            ls = [ls[j-1][k-1],ls[j-1][k],ls[j-1][k+1],ls[j][k-1],ls[j][k+1],ls[j+1][k-1],ls[j+1][k],ls[j+1][k+1]]
    
            s[i][j] = ls.count("#")

ls = ls[1:h+1][1:w+1]
for l in range(h):
    print(''.join(ls[l]))

Submission status: Runtime Error

Solution code:
import numpy as np

H,W = (int(n) for n in input().split())
arr =np.zeros((H,W),dtype=int)

mines = []
for h in range(H):
    row = list(input())
    for w in range(W):
        if(row[w]=="#"):
            arr[h-1:h+2,w-1:w+2] += 1
            mines.append((h,w))
            
arr = arr.astype(str)
for mine in mines:
    arr[mine] = "#"
print(mine.)

for row in arr :
    print("".join(row))

Submission status: Runtime Error

Solution code:
H,W = map(int,input().split())

matrix = []
for i in range(H):
    matrix.append(list(input()))

for h in range(H):
    for w in range(W):
        if matrix[h][w] != '#':
            matrix[h][w] = str(check_nmine(h,w,matrix))
            
for i in matrix:
    print("".join(i))
    
def check_nmine(h,w,matrix):
    count=0
    #h+1 -1 （いっぱい書く）
    if h-1 >= 0 and w-1 >= 0:
        if(matrix[h-1][w-1] == '#'):
            count += 1
    if h-1 >= 0 and w >= 0:
        if(matrix[h-1][w] == '#'):
            count += 1
    if h-1 >= 0 and w+1 < W:
        if(matrix[h-1][w+1] == '#'):
            count += 1
            
    if h >= 0 and w-1 >= 0:
        if(matrix[h][w-1] == '#'):
            count += 1
    if h >= 0 and w+1 < W:
        if(matrix[h][w+1] == '#'):
            count += 1
            
    if h+1 < H and w-1 >= 0:
        if(matrix[h+1][w-1] == '#'):
            count += 1
    if h+1 < H and w >= 0:
        if(matrix[h+1][w] == '#'):
            count += 1
    if h+1 < H and w+1 < W:
        if(matrix[h+1][w+1] == '#'):
            count += 1
            
    return count

Submission status: Runtime Error

Solution code:
H,W = map(int,input().split())

# make iremono
matrix = []

for i in range(H):
    matrix.append(list(input()))

#rows = sample_input.split("\n")
#matrix = [list(r) for r in rows]

ans = matrix.copy()

for h in range(H):
    for w in range(W):
        if matrix[h][w] != '#':
            ans[h][w] = str(check_nmine(h,w,matrix))
            
for i in ans:
    print("".join(i))
    
def check_nmine(h,w,matrix):
    count=0
    #h+1 -1 （いっぱい書く）
    if h-1 >= 0 and w-1 >= 0:
        if(matrix[h-1][w-1] == '#'):
            count += 1
    if h-1 >= 0 and w >= 0:
        if(matrix[h-1][w] == '#'):
            count += 1
    if h-1 >= 0 and w+1 < W:
        if(matrix[h-1][w+1] == '#'):
            count += 1
            
    if h >= 0 and w-1 >= 0:
        if(matrix[h][w-1] == '#'):
            count += 1
    if h >= 0 and w+1 < W:
        if(matrix[h][w+1] == '#'):
            count += 1
            
    if h+1 < H and w-1 >= 0:
        if(matrix[h+1][w-1] == '#'):
            count += 1
    if h+1 < H and w >= 0:
        if(matrix[h+1][w] == '#'):
            count += 1
    if h+1 < H and w+1 < W:
        if(matrix[h+1][w+1] == '#'):
            count += 1
            
    return count

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
data = []
for i in range(H):
  S.append(input())
# 参考https://atcoder.jp/contests/abc075/submissions/5409794
for i in range(H):
  for j in range(W):
    if S[i][j] == ".":
      cnt = 0
      if i != 0:
        cnt += S[i-1][min(0, j-1) : min(j+1, W-1) + 1].count("#")
      cnt += S[i][min(0, j-1) : min(j+1, W-1) + 1].count("#")
      if i != H-1:
        cnt += S[i+1][min(0, j-1) : min(j+1, W-1) + 1].count("#")
      S[i][j] = cnt
for i in range(H):
	print("".join(S[i]))

Submission status: Runtime Error

Solution code:
#https://atcoder.jp/contests/abc075/tasks/abc075_b?lang=ja
H, W = map(int, input().split())
s = [list(input()) for _ in range(H)]
for i in range(H):
    for j in range(W):
        count = 0
        if s[i][j] == ".":
            if i > 0 and j > 0 and s[i-1][j-1] == "#": #
                count +=1
            if i > 0 and s[i-1][j]=="#": #上
                count +=1
            if i > 0 and j <W-1 and s[i-1][j+1] =="#": #
                count +=1  
            if j < W-1 and s[i][i+1] =="#": #右
                count +=1
            if i < H-1 and j<W-1 and s[i+1][j+1] =="#":
                count +=1
            if i < H-1 and s[i+1][j] =="#": #下
                count +=1
            if i<H-1 and j<0 and s[i+1][j-1] =="#":
                count +=1
            if j > 0 and s[i][j-1] == "#":   #左
                count +=1
            s[i][j] = str(count)         
        else:
            pass
for i in range(H):
    print("".join(s[i]))

Submission status: Runtime Error

Solution code:
h, w = map(int,input().split())
s = []
dx = [-1,0,1,-1,1,-1,0,1]
dy = [1,1,1,0,0,-1,-1,-1]
for _ in range(h):
  s.append(input())
type(s[1][1])
  
for i in range(h):
  for j in range(w):
    if s[i][j] == '.':
      num = 0
      for k in range(8):
        ni = i + dx[k]
        nj = j + dy[k]
        if ni < 0 or h <= ni :
            continue
        if nj < 0 or w <= nj :
            continue
        if (s[ni][nj] =='#'):
            num +=1
        s[i] = s[i][:j] + str(num) + s[i][j+1:]

for x in range(h):
  print("".join(s[x]))

Submission status: Runtime Error

Solution code:
h, w = map(int,input().split())
s = []
dx = [-1,0,1,-1,1,-1,0,1]
dy = [1,1,1,0,0,-1,-1,-1]
for _ in range(h):
  s.append(input())
type(s[1][1])
  
for i in range(h):
  for j in range(w):
    if s[i][j] == '.':
      num = 0
      for k in range(8):
        ni = i + dx[k]
        nj = j + dy[k]
        if ni < 0 or h <= ni :
            continue
        if nj < 0 or w <= nj :
            continue
        if (s[ni][nj] =='#'):
            num +=1
        s[i] = s[i][:j] + str(num) + s[i][j+1:]
            
print('\n'.join(s))

Submission status: Runtime Error

Solution code:
H,W=map(int,input().split())
Ws=W+2
Hs=H+2
root= [[0] * Ws for i in range(Hs)]
c=0
for i in range(H):
    I =""
    I = input()
    print(I)
    for j in range(W):
        print("youso is ",I[j])
        k = I[j]
        root[i+1][j+1]=k
root2= [[0] * W for i in range(H)]

for i in range(H):
    
    for j in range(W):
        if root[i+1][j+1] == ".":
            c=0
            if root[i+1+1][j+1+1]=="#":
                c+=1
            if root[i+1+1][j+1]=="#":
                c+=1
            if root[i+1+1][j-1+1]=="#":
                c+=1
            if root[i+1-1][j+1+1]=="#":
                c+=1
            if root[i+1-1][j+1]=="#":
                c+=1
            if root[i+1-1][j-1+1]=="#":
                c+=1
            if root[i+1+1][j+1+1]=="#":
                c+=1
            if root[i+1+1][j+1-1]=="#":
                c+=1
              

            root2[i][j]=c
        else:root2[i][j]="#"
        
for i in range(H):
    print(root2[H])

Submission status: Runtime Error

Solution code:
def main():
    h, w = map(int, input().split())
    grid = []
    for height in range(0, h):
        grid.append(list(input()))

    replaced = []
    for height in range(0, h):
        replaced.append([0] * w)

    dx = [0, 0, 1, 1, 1, -1, -1, -1]
    dy = [1, -1, 1, -1, 0, 1, -1, 0]

    for height in range(0, h):
        for width in range(0, w):
            if grid[height][width] == '#':
                replaced[height][width] = '#'
            for i in range(0, 8):
                if (height + dy[i] < 0) or (height + dy[i] >= h) or (width + dx[i] < 0) or (width + dx[i] >= w):
                    continue
                if (grid[height + dy[i]][width + dx[i]]) == '#':
                    replaced[height][width] += 1

    for height in range(0, h):
        for width in range(0, w):
            print(replaced[height][width], end='')
        print()


if __name__ == "__main__":
  main()

Submission status: Runtime Error

Solution code:

# スペース区切りの整数の入力
h, w = map(int, input().split())


#　2次元行列のリストを作る。
list1 = [[0 for i in range(h)] for j in range(w)]
print(list1)

#list1[1][2] = 1
#list1[0][0] = "#"
#list1[1][1] = "."

#print(list1)
#print(list1[-1][-1])
#print(list1[0][0])

#list1[0:] = [int(input()) for i in range(h)]

#print(list1)

s = [0] * w

i = 0
for i in range(0,w):
	s[i] = input()

print(s)

print(list1)
print(list(s[0]))

list1[:][0] = list(s[0])
list1[:][1] = list(s[1])
list1[:][2] = list(s[2])

print(list1)



#list = [[int(i) for i in input().split()] for i in range(h)]

#print(list)

Submission status: Runtime Error

Solution code:
h, w = map(int, input().split())
s = ["a"*(w+2)] + ["a" + input() + "a" for i in range(h)] + ["a"*(w+2)]

for i in range(1, h+1):
  for j in range(1, w+1):
    if s[i][j] != "#":
      c = [s[i-1][j-1], s[i-1][j], s[i-1][j+1], s[i][j-1], s[i][j+1], s[i+1][j-1], s[i+1][j], s[i+1][j+1]]
      s[i][j] = str(c.count("#"))
      
for i in s:
  print(i)

Submission status: Runtime Error

Solution code:
import copy

H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]
ans = copy.deepcopy(S)

dx = [1, 1, 0, -1, -1, -1, 0, 1]
dy = [0, -1, -1, -1, 0, 1, 1, 1]

for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            cnt = 0
            for dir in range(8):
                try:
                    cnt += (S[i + dx[dir]][j + dy[dir]] == "#")
                except:
                    pass
            ans[i][j] = cnt
for h in range(H):
    print("".join(ans[h]))

Submission status: Runtime Error

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

def count(ch):
  return 1 if ch == '#' else 0

for i in range(H):
  for j in range(W):
    num = 0
    if mine[i][j] == '#':
      continue
    else:
      for k in range(-1,2):
        for l in range(-1,2):
          num += (1 if mine[i+k][j+l]=='#' else 0) 
      mine[i][j] = num
      
for i in range(1,H+1):
  for j in range(1,W+1):
    print(mine[i][j],end='')
  print()

Submission status: Runtime Error

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

def count(ch):
  return 1 if ch == '#' else 0

for i in range(H):
  for j in range(W):
    num = 0
    if mine[i][j] == '#':
      continue
    else:
      for k in range(-1,2):
        for l in range(-1,2):
          num += (1 if mine[i+k][j+l]=='#' else 0) 
      
for i in range(1,H+1):
  for j in range(1,W+1):
    print(mine[i][j],end='')
  print()

Submission status: Runtime Error

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

def count(ch):
  return 1 if ch == '#' else 0

for i in range(H):
  for j in range(W):
    if mine[i][j] == '#':
      continue
    else:
      num = 0
      if (i == 0):
        if(j == 0):
          mine[0][0] = count(mine[0][1]) + count(mine[1][1])+count(mine[1][0])
        elif(j == W-1):
          mine[0][W-1] = count(mine[0][W-2]) + count(mine[1][W-2])+count(mine[1][W-1])
        else:
          mine[0][j] = count(mine[0][j-1]) + count(mine[0][j+1])+count(mine[1][j-1])+count(mine[1][j])+count(mine[1][j+1])
      elif(i == H-1):
        if(j == 0):
          mine[H-1][0] = count(mine[H-1][1]) + count(mine[H-2][1])+count(mine[H-2][0])
        elif(j == W-1):
          mine[H-1][W-1] = count(mine[H-1][W-2]) + count(mine[H-2][W-2])+count(mine[H-2][W-1])
        else:
          mine[H-1][j] = count(mine[H-1][j-1]) + count(mine[H-1][j+1])+count(mine[H-2][j-1])+count(mine[H-2][j])+count(mine[H-2][j+1])
      elif(j == 0):
        mine[i][0] = count(mine[i-1][0]) + count(mine[i+1][0])+count(mine[i-1][1])+count(mine[i][1])+count(mine[i+1][1])
      elif(j == W-1):
        mine[i][W-1] = count(mine[i-1][W-1]) + count(mine[i+1][W-1])+count(mine[i-1][W-2])+count(mine[i][W-2])+count(mine[i+1][W-2])
      else:
        mine[i][j] = count(mine[i-1][j-1])+count(mine[i][j-1])+count(mine[i+1][j-1])+count(mine[i-1][j])+count(mine[i][j])+count(mine[i+1][j])+count(mine[i-1][j+1])+count(mine[i][j+1])+count(mine[i+1][j+1])
for i in range(H):
  for j in range(W):
    print(mine[i][j],end='')
  print()

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split())
s=[input() for _ in range(h)]
for i in range(h):
  l = ""
  for j in range(w):
    if s[i][j] == "#":
      l += "#"
    else:
      l += sum(s[t][max(0,j-1):min(w,j+2)].count("#") for t in [max(0,i-1):min(h,i+2)])
print(l)

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split())
l=[[0]*(w+2)]
for i in range(h):
  a=list(input())
  a.insert(0,0)
  a.append(0)
  l.append(a)
l.append([0]*(w+2))
pointx=[-1,0,1]
pointy=[-1,0,1]
for i in range(1,h+1):
  for j in range(1,w+1):
    if l[i][j]=='.':
      count=0
      for k in pointx:
        for m in pointy:
          if l[i+k][i+m]=='#':
            count+=1
      l[i][j]=str(count)

del l[0]
del l[h]
for i in range(h):
  l[i]=l[i][1:w+1]
for i in l:
  print(''.join(i))

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split())
l=[[0]*(w+2)]
for i in range(h):
  a=list(input())
  a.insert(0,0)
  a.append(0)
  l.append(a)
l.append([0]*(w+2))
pointx=[-1,0,1]
pointy=[-1,0,1]
for i in range(1,h+1):
  for j in range(1,w+1):
    count=0
    if l[i][j]=='.':
      for k in pointx:
        for m in pointy:
          if l[i+k][i+m]=='#':
            count+=1
      l[i][j]=str(count)

del l[0]
del l[h]
for i in range(h):
  l[i]=l[i][1:w+1]
for i in l:
  print(''.join(i))

Submission status: Runtime Error

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

for i in range(h):
  for j in range(w):
    if s[i][j]=='#':
      continue
    cnt=0
    for dx in [-1,0,1]:
      for dy in [-1,0,1]:
        if not(0<=dx+i<=h and 0<=dy+j<=w):
          continue
        if s[i+dx][j+dy]=='#':
          cnt+=1
    s[i][j]=str(cnt)
for m in s:
  print(''.join(m))