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())
slist=[input() for i in range(h)]
for i in range(h):
  s=slist[i]
  s_new = ""
  if i==0:
    t=slist[1]
    for j in range(w):
      if j==0 and s[0]==".":
        m=0
        if s[1]=="#":
          m+=1
        if t[0]=="#":
          m+=1
        if t[1]=="#":
          m+=1
        s_new += str(m)
      elif j==w-1 and s[w-1]==".":
        m=0
        if s[w-2]=="#":
          m+=1
        if t[w-2]=="#":
          m+=1
        if t[w-1]=="#":
          m+=1
        s_new += str(m)
      elif s[j]==".":
        m=0
        if s[j-1]=="#":
          m+=1
        if s[j+1]=="#":
          m+=1
        if t[j-1]=="#":
          m+=1
        if t[j]=="#":
          m+=1
        if t[j+1]=="#":
          m+=1
        s_new += str(m)
      else:
        s_new += "#"
    print(s_new)
  elif i==h-1:
    r = slist[i-1]
    for j in range(w):
      if j==0 and s[0]==".":
        m=0
        if s[1]=="#":
          m+=1
        if r[0]=="#":
          m+=1
        if r[1]=="#":
          m+=1
        s_new += str(m)
      elif j==w-1 and s[w-1]==".":
        m=0
        if s[w-2]=="#":
          m+=1
        if r[w-2]=="#":
          m+=1
        if r[w-1]=="#":
          m+=1
        s_new += str(m)
      elif s[j]==".":
        m=0
        if s[j-1]=="#":
          m+=1
        if s[j+1]=="#":
          m+=1
        if r[j-1]=="#":
          m+=1
        if r[j]=="#":
          m+=1
        if r[j+1]=="#":
          m+=1
        s_new += str(m)
      else:
        s_new += "#"
    print(s_new)
  else:
    r = slist[i-1]
    t = slist[i+1]
    for j in range(w):
      if j==0 and s[j]==".":
        m=0
        if r[j]=="#":
          m+=1
        if r[j+1]=="#":
          m+=1
        if s[j+1]=="#":
          m+=1
        if t[j+1]=="#":
          m+=1
        if t[j]=="#":
          m+=1
        s_new += str(m)
      elif j==w-1 and s[j]==".":
        m=0
        if r[j]=="#":
          m+=1
        if r[j-1]=="#":
          m+=1
        if s[j-1]=="#":
          m+=1
        if t[j-1]=="#":
          m+=1
        if t[j]=="#":
          m+=1
        s_new += str(m)
      elif s[j]==".":
        m=0
        if r[j]=="#":
          m+=1
        if r[j-1]=="#":
          m+=1
        if s[j-1]=="#":
          m+=1
        if t[j-1]=="#":
          m+=1
        if r[j+1]=="#":
          m+=1
        if s[j+1]=="#":
          m+=1
        if t[j+1]=="#":
          m+=1
        if t[j]=="#":
          m+=1
        s_new += str(m)
      else:
        s_new += "#"
    print(s_new)

Submission status: Runtime Error

Solution code:
H,W = map(int,input().split())
f = list(str(input()) for i in range(H))

for i in range(H):
  for j in range(W):
    if f[i][j] == "#":
      continue
    
    count = 0
    if i > 0 and j > 0:
      if f[i-1][j-1] == "#":
        count+=1
    if i > 0:
      if f[i-1][j] == "#":
        count+=1
    if i > 0 and j < W-1:
      if f[i-1][j+1] == "#":
        count+=1
    if j > 0:
      if f[i][j-1] == "#":
        count+=1
    if j < W-1:
      if f[i][j+1] == "#":
        count+=1
    if i < H-1 and j > 0:
      if f[i+1][j-1] == "#":
        count+=1
    if i < H-1:
      if f[i+1][j] == "#":
        count+=1
    if i < H-1 and j < W-1:
      if f[i+1][j+1] == "#":
        count+=1
    
    f[i][j] = str(count)
    
for i in range(H):
  print(f[i])

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
S = []
for _ in range(H):
    S.append(list(input()))
# print(S)
for i in range(H):
    for j in range(W):
        if S[i][j] == '.':
            bomb_num = 0
            if i == 0:
                if j == 0:
                    for m in range(2):
                        for k in range(2):
                            if m == 0 and k == 0:
                                continue
                            if S[i+m][j+k] == '#':
                                bomb_num += 1
                        S[i][j] = str(bomb_num)
                elif j == W-1:
                    for m in range(2):
                        for k in range(2):
                            if m == 0 and k == 1:
                                continue
                            if S[i+m][j+k-1] == '#':
                                bomb_num += 1
                        S[i][j] = str(bomb_num)
                else:
                    for m in range(2):
                        for k in range(3):
                            if m == 0 and k == 1:
                                continue
                            if S[i+m][j+k-1] == '#':
                                bomb_num += 1
                        S[i][j] = str(bomb_num)
            elif i == H-1:
                if j == 0:
                    for m in range(2):
                        for k in range(2):
                            if m == 1 and k == 0:
                                continue
                            if S[i+m-1][j+k] == '#':
                                bomb_num += 1
                        S[i][j] = str(bomb_num)
                elif j == W-1:
                    for m in range(2):
                        for k in range(2):
                            if m == 1 and k == 1:
                                continue
                            if S[i+m-1][j+k-1] == '#':
                                bomb_num += 1
                        S[i][j] = str(bomb_num)
                else:
                    for m in range(2):
                        for k in range(3):
                            if m == 1 and k == 1:
                                continue
                            if S[i+m-1][j+k-1] == '#':
                                bomb_num += 1
                        S[i][j] = str(bomb_num)
            elif j == 0 and (1 <= i and i <= H-2):
                for m in range(3):
                    for k in range(2):
                        if m == 1 and k == 0:
                            continue
                        if S[i+m-1][j+k] == '#':
                            bomb_num += 1
                    S[i][j] = str(bomb_num)
            elif j == W-1 and (1 <= i and i <= H-2):
                for m in range(3):
                    for k in range(2):
                        if m == 1 and k == 1:
                            continue
                        if S[i+m-1][j+k-1] == '#':
                            bomb_num += 1
                    S[i][j] = str(bomb_num)
            else:
                for m in range(3):
                    for k in range(3):
                        if m == 1 and k == 1:
                            continue
                        if S[i+m-1][j+k-1] == '#':
                            bomb_num += 1
                S[i][j] = str(bomb_num)

for i in range(H):
    answer = ''.join(S[i])
    print(answer)

Submission status: Runtime Error

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


def count_bomb(x, y):
    bomb = 0
    one_steps = ((1, 0), (-1, 0), (0, 1), (0, -1), (1, 1), (1, -1), (-1, 1), (-1, -1))
    for dx, dy in one_steps:
        nx, ny = x + dx, y + dy
        if (0 <= nx < H) and (0 <= ny <= W):
            if graph[nx][ny] == "#":
                bomb += 1
    return bomb


for x in range(H):
    for y in range(W):
        if graph[x][y] == ".":
            graph[x][y] = count_bomb(x, y)
for line in graph:
    print(line)

Submission status: Runtime Error

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

li=[]
for i in range(h):
    li.append(list(input()))

new_li=[[0]*w for i in range(h)]

#＃の位置をリストに集める
sharp_li=[]
for i in range(h):
    for j in range(w):
        if li[i][j]=='#':
            sharp_li.append([i,j])   

            
for k in range(len(sharp_li)):
    #y行X列を扱う
    y=sharp_li[k][0]
    x=sharp_li[k][1]
    
    #tryの例外処理だとうまくいかなかったので、端の場合を自力で書いて場合わけする
    if x==0:
        xli=[0,1]
    elif x==w-1:
        xli=[w-2,w-1]
    else:
        xli=[x-1,x,x+1]
    
    if y==0:
        yli=[0,1]
    elif y==h-1:
        yli=[h-2,h-1]
    else:
        yli=[y-1,y,y+1]
        
        
    for l in xli:
        for m in yli:
            new_li[m][l]+=1           #m行l列なので
           
        
ans=[]             
for n in range(h):
    stred=list(map(str,new_li[n]))
    ans.append(stred)

#もともとの爆弾の部分を＃に戻す

for o in range(len(sharp_li)):
    ans[sharp_li[o][0]][sharp_li[o][1]]='#'


for p in range(h):
    tans=''.join(ans[p])
    print(tans)

Submission status: Runtime Error

Solution code:
h,w = list(map(int,input().split()))
s=[i for i in range(h)]
for i in range(h):
  s[i] = input()
#0行、0列、hー1行、wー1列が場合わけ、ただし4隅は重複
#s[0][0],s[0][w-1],s[h-1][0],s[h-1][w-1]
count = [[0 for i in range(w)]for j in range(h)]

for i in range(h):
  for j in range(w):
    if s[i][j]=="#":
      if i==0:
        if j==0:
          count[i+1][j]+=1
          count[i+1][j+1]+=1
          count[i][j+1]+=1
        elif j==w-1:
          count[i][j-1]+=1
          count[i+1][j-1]+=1
          count[i+1][j]+=1
        else:
          count[i][j-1]+=1
          count[i][j+1]+=1
          count[i+1][j-1]+=1
          count[i+1][j]  +=1
          count[i+1][j+1]+=1
      elif i==h-1:
        if j==0:
          count[i][j+1]+=1
          count[i-1][j]+=1
          count[i-1][j+1]+=1
        elif j==w-1:
          count[i][j-1]+=1
          count[i-1][j-1]+=1
          count[i-1][j]+=1
        else:
          count[i][j-1]+=1
          count[i][j+1]+=1
          count[i-1][j-1]+=1
          count[i-1][j]+=1
          count[i-1][j+1]+=1
      else:
        if j==0:
          count[i-1][j]+=1
          count[i-1][j+1]+=1
          count[i][j+1]+=1
          count[i+1][j]+=1
          count[i+1][j+1]+=1
        elif j==w-1:
          count[i-1][j-1]+=1
          count[i-1][j]+=1
          count[i][j-1]+=1
          count[i+1][j-1]+=1
          count[i+1][j]+=1
        else:
          count[i-1][j-1]+=1
          count[i-1][j]+=1
          count[i-1][j+1]+=1
          count[i][j-1]+=1
          count[i][j+1]+=1
          count[i+1][j-1]+=1
          count[i+1][j]+=1
          count[i+1][j+1]+=1

for i in range(h):
  ans=""
  for j in range(w):
    if s[i][j]!="#":
  	  ans+=str(count[i][j])
    else:
      ans+="#"
  print(ans)

Submission status: Runtime Error

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

li=[]
for i in range(h):
    li.append(list(input()))

new_li=[[0]*w for i in range(h)]

#＃の位置をリストに集める
sharp_li=[]
for i in range(h):
    for j in range(w):
        if li[i][j]=='#':
            sharp_li.append([i,j])

            
for k in range(len(sharp_li)):
    x=sharp_li[k][0]
    y=sharp_li[k][1]
    
    #tryの例外処理だとうまくいかなかったので、端の場合を自力で書いて場合わけする
    if x==0:
        xli=[0,1]
    elif x==w-1:
        xli=[w-2,w-1]
    else:
        xli=[x-1,x,x+1]
    
    if y==0:
        yli=[0,1]
    elif y==h-1:
        yli=[h-2,h-1]
    else:
        yli=[y-1,y,y+1]
        
        
    for l in xli:
        for m in yli:
            new_li[l][m]+=1
           
        
ans=[]             
for n in range(h):
    stred=list(map(str,new_li[n]))
    ans.append(stred)

#もともとの爆弾の部分を＃に戻す

for o in range(len(sharp_li)):
    ans[sharp_li[o][0]][sharp_li[o][1]]='#'


for p in range(h):
    tans=''.join(ans[p])
    print(tans)

Submission status: Runtime Error

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

for i in range(h):
    ans = ""
    for j in range(w):
        if s[i][j] == "#":
            ans += "#"
        else:
            ans += str(sum(k[max(0, j-1):min(w, j+2)]) for k in s[max(0, i-1):min(h, i+2)]
        print(ans)

Submission status: Runtime Error

Solution code:
H,W=map(int,input().split())
l=[""]*W
ll=[["" for i in range(W)] for j in range(H)] 
for i in range(H):
  l[i]=[i for i in input()] 
for h in range(H):
  for w in range(W):
    if l[h][w]=="#":
      ll[h][w]="#"
    else:  
      cnt=0
      for hh in [-1,0,1]:
        for ww in [-1,0,1]:
          if 0<=h+hh<H and 0<=w+ww<W:
            if l[h+hh][w+ww]=="#":
              cnt+=1
      ll[h][w]=str(cnt)   
for i in range(H):
  print("".join(ll[i]))

Submission status: Runtime Error

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

A = [''] * H

di = [(1,0),(-1,0),(0,1),(0,-1),(1,1),(1,-1),(-1,1),(-1,-1)]

for h in range(H):
    for w in range(W):
        if S[h][w] == '#':
            A[h] += '#'
        else:
            c = 0
            for d in di:
                h1 = h + d[0]
                w1 = w + d[1]
                if 0 <= h1 < H and 0 <= w1 < W:
                    if S[h1][w1] == '#':
                        c += 1
            A[h] += str(c)

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

Submission status: Runtime Error

Solution code:
a

Submission status: Runtime Error

Solution code:


def main()->None:
    # gridの処理
    # 近傍の座標をdx=[-1,0,1], dy=[-1,0,1]を用いて
    # (xx, yy) が　xx = x + dx , yy = y + dy　とできる
    # 参考：http://prd-xxx.hateblo.jp/entry/2017/10/19/205331
    # 入力のグリッドから一点ずつ座標指定して選んでその周囲８マスを調べる。
    H, W = map(int, input().split())
    src = [input() for _ in range(H)]
    ans = []
    for row in src:
        ans.append(list(row))


    dxdy = [(-1,-1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)]
    for y in range(H):
        for x in range(W):
            if src[y][x] == "#":continue
            c = 0
            for dx, dy in dxdy:
                # 探索範囲はx:0~W, y:0~Hでその周囲８マスを探索する
                if x+dx < 0 or x+dx > W-1 or y+dy < 0 or y+dy > H-1: continue
                if src[y+dy][x+dx] == "#": c += 1
        ans[y][x] = c
    
    for row in ans:
        print("".join(list(map(str, row))))




if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
H,W = map(int, input().split())
S = [list(input()) for _ in range(H)] #データ形式はS[i][j]

eight = [[-1,-1],[0,-1],[1,-1], # 周囲8マスの定義
         [-1,0],[1,0],
         [-1,1],[0,1],[1,1]]

for i in range(H):
  for j in range(W):
    if S[i][j] == '#':
      for e in eight:
        target = S[i+e[0]][j+e[1]]
        if target and target != '#':
          if target == '.' :
            S[i+e[0]][j+e[1]] = 1
          else :
            S[i+e[0]][j+e[1]] += 1

for i in range(H):
  for j in range(W):
    print(S[i][j], end='')
  if i < H: print('')

Submission status: Runtime Error

Solution code:
H,W = map(int, input().split())
S = [list(input()) for _ in range(H)] #データ形式はS[i][j]

eight = [[-1,-1],[0,-1],[1,-1], # 周囲8マスの定義
         [-1,0],[1,0],
         [-1,1],[0,1],[1,1]]

for i in range(H):
  for j in range(W):
    if S[i][j] == '#':
      for e in eight:
        target = S[i+e[0]][j+e[1]]
        if target and target != '#':
          if target == '.' :
            S[i+e[0]][j+e[1]] = 1
          else :
            S[i+e[0]][j+e[1]] += 1

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

Submission status: Runtime Error

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

d = [[-1,-1],[0,-1],[1,-1],
     [-1, 0],       [1, 0],
     [-1, 1],[0, 1],[1, 1]]

for hi in range(h):
  for wi in range(w):
    if f[hi][wi]=='#':
      pass
    else:
      count = 0
      for dx,dy in d:
        x = dx+wi
        y = dy+hi        
        if (0<= x < w) and (0<= y <h) :
          if ff[y][x] == '#':
            count += 1
      ff[hi][wi] = str(count)
      
for fi in ff:
  print(''.join(fi))

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
matrix = [input() for i in range(H)] 
ans = ""  
for h in range(H):
        for w in range(W):
                bomb = 0 
                for i in range(-1, 2): 
                        if 0 <= h - 1 and 0 <= w + i < W:
                                if matrix[h - 1][w + i] == "#":
                                        bomb += 1
                        if h + 1 < H and 0 <= w + i < W:
                                if matrix[h + 1][w + i] == "#":
                                        bomb += 1
                for i in range(-1, 2, 2): 
                        if 0 <= w + i < W:
                                if matrix[h][w + i] == "#":
                                        bomb += 1
                if matrix[h][w] == "#":
                        ans += "#" 
                else:
                        ans += str(bomb)
                if w % (W - 1) == 0 and w != 0:
                        ans += "\n"
print(ans)

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
Map = []
for _ in range(N):
  temp = input()
  Map.append(list(temp))

def check(x):
  answer = 0
  if x == '#':
    answer +=1
  return answer
    

Answer = []
for i in range(N):
  for j in range(M):
    if Map[i][j] =='#':
      Answer.append('#')
    else:
      counter = 0
      if 0 < i and 0 < j < M-1:
        counter += check(Map[i-1][j-1])+check(Map[i-1][j])+check(Map[i-1][j+1])
      elif 0 < i and j ==0:
        counter += check(Map[i-1][j])+check(Map[i-1][j+1])
      elif 0 < i and j == M-1:
        counter += check(Map[i-1][j-1])+check(Map[i-1][j])
      if i < N-1 and 0 < j < M-1:
        counter += check(Map[i+1][j-1])+check(Map[i+1][j])+check(Map[i+1][j+1])
      elif i < N-1 and j == 0:
        counter += check(Map[i+1][j])+check(Map[i+1][j+1])
      elif i < N-1 and j == M-1:
        counter += check(Map[i+1][j-1])+check(Map[i+1][j])
      if 0 < j:
        counter += check(Map[i][j-1])
      if j < M-1:
        counter += check(Map[i][j+1])
      Answer.append(counter)
for i in range(N):
  output = ''
  for j in range(M):
    output += str(Answer[i*M+j])
  print(output)

Submission status: Runtime Error

Solution code:
h,w = map(int,input().split())
Array = [list(map(str,input())) for _ in range(h)]
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 Array[i][j]='#':
      continue
    num=0
    for d in range(8):
      ni = i+dy[d]
      nj = j+dx[d]
      if ni<0 or h<=ni:
        continue
      if nj<0 or w<=nj:
        continue
      if Array[ni][nj]=='#':
        num=num+1
    Array[i][j]=str(num)
    
for i in Array:
  print(*i,sep='')

Submission status: Runtime Error

Solution code:
h,w = map(int,input().split())
Array = [list(map(str,input())) for _ in range(h)]
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 Array[i][j]='#':
      continue
    num=0
    for d in range(8):
      ni = i+dy[d]
      nj = j+dx[d]
      if ni<0 or h<=ni:
        continue
      if nj<0 or w<=nj:
        continue
      if Array[ni][nj]=='#':
        num=num+1
    Array[i][j]=str(num)
    
for i in Array:
  print(*i)

Submission status: Runtime Error

Solution code:
h,w = map(int,input().split())
Array = [list(map(str,input())) for _ in range(h)]
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 Array[i][j]='#':
      continue
    num=0
    for d in range(8):
      ni = i+dy[d]
      nj = j+dx[d]
      if ni<0 or h<=ni:
        continue
      if nj<0 or w<=nj:
        continue
      if Array[ni][nj]=='#':
        num=num+1
    Array[i][j]=str(num)
    
for i in Array:
  print(i)

Submission status: Runtime Error

Solution code:
h,w = map(int,input().split())
Array = [list(map(str,input())) for _ in range(h)]
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 Array[i][j]='#':
      continue
    num=0
    for d in range(8):
      ni = i+dy[d]
      nj = j+dx[d]
      if ni<0 or h<=ni:
        continue
      if nj<0 or w<=nj:
        continue
      if Array[ni][nj]=='#':
        num=num+1
    Array[i][j]=char(num)
    
for i in Array:
  print(i)

Submission status: Runtime Error

Solution code:
h,w = map(int,input().split())
Array = [list(map(int,input())) for _ in range(h)]
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 Array[i][j]='#':
      continue
    num=0
    for d in range(8):
      ni = i+dy[d]
      nj = j+dx[d]
      if ni<0 or h<=ni:
        continue
      if nj<0 or w<=nj:
        continue
      if Array[ni][nj]=='#':
        num=num+1
    Array[i][j]=char(num)
    
for i in Array:
  print(i)

Submission status: Runtime Error

Solution code:
h,w = map(int,input().split())
Array = [list(map(int,input().split())) for _ in range(h)]
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 Array[i][j]='#':
      continue
    num=0
    for d in range(8):
      ni = i+dy[d]
      nj = j+dx[d]
      if ni<0 or h<=ni:
        continue
      if nj<0 or w<=nj:
        continue
      if Array[ni][nj]=='#':
        num=num+1
    Array[i][j]=char(num)
    
for i in Array:
  print(*i)

Submission status: Runtime Error

Solution code:
h,w = map(int,input().split())
Array = [list(map(int,input().split())) for _ in range(h)]
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 Array[i][j]='#':
      continue
    num=0
    for d in range(8):
      ni = i+dy[d]
      nj = j+dx[d]
      if ni<0 or h<=ni:
        continue
      if nj<0 or w<=nj:
        continue
      if Array[ni][nj]=='#':
        num=num+1
    Array[i][j]=char(num)
    
for i in Array:
  print(*Array)

Submission status: Runtime Error

Solution code:
h,w = map(int,input().split())
Array = [list(map(int, input().split())) for _ in range(h)]
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 Array[i][j]='#':
      continue
    num=0
    for d in range(8):
      ni = i+dy[d]
      nj = j+dx[d]
      if ni<0 or h<=ni:
        continue
      if nj<0 or w<=nj:
        continue
      if Array[ni][nj]=='#':
        num=num+1
    Array[i][j]=char(num)
    
for i in Array:
  print(*Array)

Submission status: Runtime Error

Solution code:
h,w = map(int, input().split())
Array = [list(map(int, input().split())) for _ in range(h)]
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 Array[i][j]='#':
      continue
    num=0
    for d in range(8):
      ni = i+dy[d]
      nj = j+dx[d]
      if ni<0 or h<=ni:
        continue
      if nj<0 or w<=nj:
        continue
      if Array[ni][nj]=='#':
        num=num+1
    Array[i][j]=char(num)
    
for i in Array:
  print(*Array)

Submission status: Runtime Error

Solution code:
h,w = map(int, input().split())
Array = [list(map(int, input().split())) for _ in range(h)]
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 Array[i][j]='#':
      continue
      
    num=0
    for d in range(8):
      ni = i+dy[d]
      nj = j+dx[d]
      if ni<0 or h<=ni:
        continue
      if nj<0 or w<=nj:
        continue
      if Array[ni][nj]=='#':
        num=num+1
        
    Array[i][j]=char(num)
    
for i in Array:
  print(*Array)

Submission status: Runtime Error

Solution code:
h,w = map(int, input().split())
Array = [list(map(int, input().split())) for _ in range(h)]
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 Array[i][j]='#':
      continue
      
    num=0
    for d in range(8):
      ni = i+dy[d]
      nj = j+dx[d]
      if ni<0 or h<=ni:
        continue
      if nj<0 or w<=nj:
        continue
      if Array[ni][nj]=='#':
        num=num+1
        
    Array[i][j]=char(num + '0')
    
for i in Array:
  print(*Array)

Submission status: Runtime Error

Solution code:
h,w = int(input())
Array = [list(map(int, input().split())) for _ in range(h)]
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 Array[i][j]='#':
      continue
      
    num=0
    for d in range(8):
      ni = i+dy[d]
      nj = j+dx[d]
      if ni<0 or h<=ni:
        continue
      if nj<0 or w<=nj:
        continue
      if Array[ni][nj]=='#':
        num=num+1
        
    Array[i][j]=char(num + '0')
    
for i in Array:
  print(*Array)

Submission status: Runtime Error

Solution code:
h,w = int(input())
Array = [list(map(int, input().split())) for _ in range(h)]
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 Array[i][j]='#':
      continue
      
    num=0
    for d in range(8):
      ni = i+dx[d]
      nj = j+dy[d]
      if ni<0 or h<=ni:
        continue
      if nj<0 or w<=nj:
        continue
      if Array[ni][nj]=='#':
        num=num+1
        
    Array[i][j]=char(num + '0')
    
for i in Array:
  print(*Array)

Submission status: Runtime Error

Solution code:
h,w = int(input())
Array = [list(map(int, input().split())) for _ in range(h)]
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 Array[i][j]='#':
      continue
      
    num=0
    for d in range(8):
      ni = i+dx[d]
      nj = j+dj[d]
      if ni<0 or h<=ni:
        continue
      if nj<0 or w<=nj:
        continue
      if Array[ni][nj]=='#':
        num=num+1
        
    Array[i][j]=char(num + '0')
    
for i in Array:
  print(*Array)

Submission status: Runtime Error

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