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

Solution (Python):
H, W = map(int, input().split())
S = [input() for i in range(H)]
C = [[0 for i in range(W)] for j 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 S[i][j] == '.':
      for k in range(8):
        if 0 <= j + dx[k] < W and 0 <= i + dy[k] < H:
          if S[i +dy[k]][j + dx[k]] == '
            C[i][j] += 1
          else:
            pass
        else:
          pass
    else:
      C[i][j] = '

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

Solution (Python):
h, w = map(int, input().split())
s = [['.' for _ in range(w + 2)]]

for _ in range(h):
    s.append(['.'] + list(input()) + ['.'])

s.append(['.' for _ in range(w + 2)])

for i in range(1, h + 1):
    for j in range(1, w + 1):
        if s[i][j] == '.':
            count = 0
            for k in range(i - 1, i + 2):
                count += s[k][j - 1:j + 2].count('
                s[i][j] = count


for i in range(1, h + 1):
    print(''.join(map(str, s[i][1:w + 1])))

Solution (Python):
H,W=list(map(int,input().split()))
ans=[[0 for _ in range(W+2)] for _ in range(H+2)]
for i in range(H):
    for j,x in enumerate(input()):
        if x=='
            ans[i+1][j+1]=-10
            for k in (-1,0,1):
                for m in (-1,0,1):
                    ans[i+1+k][j+1+m]+=1
for x in ans:
    for i,y in enumerate(x):
        if y <0:
            x[i]='
for x in ans[1:-1]:
    for y in x[1:-1]:
        print(y,end='')
    print('')

Solution (Python):
from sys import stdin


def main() -> None:
    h, w = map(int, input().split())
    s = [input() for _ in range(h)]

    ans = []
    for i in range(h):
        ans += [[0] * w]

    for i in range(h):
        for j in range(w):
            if s[i][j] == "
                ans[i][j] = 9
                for x in (-1, 0, 1):
                    for y in (-1, 0, 1):
                        if 0 <= i + y < h and 0 <= j + x < w:
                            ans[i + y][j + x] += 1

    for i in range(h):
        for j in range(w):
            if ans[i][j] >= 9:
                print("
            else:
                print(ans[i][j], end="")
        print()


def next_str() -> str:
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

Solution (Python):
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))

Solution (Python):
board = []
direction = [[1,0],[1,1],[0,1],[-1,1],[-1,0],[-1,-1],[0,-1],[1,-1]]
h, w = map(int, input().split(" "))
for i in range(h):
	board.append([k for k in input()])

for i in range(h):
	for j in range(w):
		if board[i][j] == ".":
			board[i][j] = "0"
			for k in range(8):
				x = j + direction[k][0]
				y = i + direction[k][1]
				if 0 <= x < w and 0 <= y < h:
					if board[y][x] == "
						board[i][j] = str(1 + int(board[i][j]))
for i in range(h):
	for j in range(w):
		print(board[i][j], end="")
	print("")

Solution (Python):
h,w=map(int,input().split())
s=['-'*(w+2)]
for i in range(h):
    s.append('-'+input()+'-')
s.append('-'*(w+2))
for j in range(1,h+1):
    t=[]
    for k in range(1,w+1):
        if s[j][k]=='
            t.append('
        else:
            c=[s[j-1][k-1],s[j][k-1],s[j+1][k-1],s[j-1][k],s[j+1][k],s[j-1][k+1],s[j][k+1],s[j+1][k+1]]
            t.append(str(c.count('
    t=''.join(t)
    print(t)

Solution (Python):

h, w = map(int, input().split())

mine_set = set()
next_to_grid_list = [(1, 0), (1, -1), (0, -1), (-1, -1), (-1, 0),
                     (-1, 1), (0, 1), (1, 1)]


def add_number_for_dot(mine):
    for next_to_grid in next_to_grid_list:
        if is_constrained(mine[0] + next_to_grid[0], mine[1] + next_to_grid[1]):
            if type(grids[mine[0] + next_to_grid[0]][mine[1] + next_to_grid[1]]) is int:
                grids[mine[0] + next_to_grid[0]][mine[1] + next_to_grid[1]] += 1


def is_constrained(i, j):
    if 0 <= i < h and 0 <= j < w:
        return True
    else:
        return False



grids = []
for i in range(h):
    grids.append(list(input()))
    for j in range(w):
        if grids[i][j] == "
            mine_set.add((i, j))
        else:
            grids[i][j] = 0


for mine in mine_set:
    add_number_for_dot(mine)


for i in range(h):
    s_i = [str(grid) if type(grid) is int else grid for grid in grids[i]]
    print("".join(s_i))

Solution (Python):
h,w = map(int, input().split())
s = []
s.append((". " * (w + 2)).split())
for i in range(h):
    b = "." + input() + "."
    s.append(list(b))
s.append((". " * (w + 2)).split())
for i in range(1,h + 1):
    for f in range(1, w + 1):
        if s[i][f] == "
            for x in range(-1, 2, 1):
                for y in range(-1, 2, 1):
                    if s[i+x][f+y] == ".":
                        s[i+x][f+y] = 1
                    elif isinstance(s[i+x][f+y], int):
                        s[i+x][f+y] += 1
for i in range(1, h + 1):
    ans = "".join(map(str, s[i][1:w+1])).replace(".","0")
    print(ans)

Solution (Python):

def countbomb(i,j):
    bomb = 0
    for y in range(i-1,i+2):
        for x in range(j-1,j+2):
            if a[y][x] == '
                bomb += 1
    return bomb      
            
h, w = list(map(int, input().split()))
a = [['w']*(w+2) for _ in range(h+2)]
for i in range(1,h+1):
    si = list(input())
    a[i][1:w+1] = si

for i in range(1,h+1):
    for j in range(1,w+1):
        if a[i][j] != '.':
            continue
        cnt = countbomb(i,j)
        a[i][j] = cnt
for i in range(1,h+1):
    si = a[i][1:w+1]
    print(''.join(map(str,si)))

Solution (Python):
h,w = map(int,input().split())
area = [input() for i in range(h)]

for i in range(h):
  for j in range(w):
    count = 0
    if area[i][j] == ".":
      for s in range(-1,2):
        for t in range(-1,2):
          if 0 <= i + s <h and 0 <= j+t < w:
            if area[i+s][j+t] == '
              count += 1
          else:
            continue
      print(count, end='')
    else:
      print("
  print()

Solution (Python):
H,W = map(int, input().split())
S = [input() for i in range(H)]

count = []
for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            cnt = 0
            for x in [-1, 0, 1]:
                for y in [-1, 0, 1]:
                    if 0 <= i+x < H and 0 <= j+y < W:
                        if S[i+x][j+y] == "
                            cnt += 1
            print(cnt,end="")
        else:
            print("
    print()

Solution (Python):
h, w = map(int, input().split())
a = [input() for _ in range(h)]
for i in range(h):
    for j in range(w):
        ans = 0
        if a[i][j] == ".":
            for s in range(-1, 2):
                for t in range(-1, 2):
                    if 0 <= i + s < h  and 0 <= j + t < w:
                            if a[i+s][j+t] == "
                                ans += 1
                    else:
                        continue
            print(ans, end="")
        else:
            print("
    print()

Solution (Python):
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('
            ans.append(str(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))

Solution (Python):
H,W = map(int, input().split())
S = []

for _ in range(H):
  S.append([s for s in input()])

for h in range(H):
  for w in range(W):
    if S[h][w] == ".":
      a = 0
      for x in [-1, 0, 1]:
        for y in [-1, 0, 1]:
          if 0 <= h+x < H and 0 <= w+y < W:
            if S[h+x][w+y] == "
              a += 1
      S[h][w] = str(a)

for _ in range(H):
  print("".join(S[_]))

Solution (Python):
h, w = [int(m) for m in input().split(" ")]
s = [input() for i in range(h)]

s = [[{".": 0, "

for h_i in range(h):
    for w_i in range(w):
        if 10 <= s[h_i][w_i]:
            for y in range(h_i-1, h_i+2):
                for x in range(w_i-1, w_i+2):
                    if 0 <= y < h and 0 <= x < w:
                        s[y][x] += 1

print("\n".join(["".join(["

Solution (Python):
h,w=map(int,input().split())
s=[list(input()) for i in range(h)]
dx=[1,1,1,0,0,-1,-1,-1]
dy=[-1,0,1,1,-1,-1,0,1]
for i in range(h):
    for j in range(w):
        if s[i][j]==".":
            cnt=0
            for k in range(8):
                x=i+dx[k]
                y=j+dy[k]
                if x>=0 and x<h and y>=0 and y<w and s[x][y]=="
                    cnt+=1
            s[i][j]=str(cnt)
for i in s:
    print ("".join(i))

Solution (Python):
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)

Solution (Python):
hw = input()
hw = hw.split()
h = int(hw[0])  
w = int(hw[1])  

board_input = []
board_output = []

for i in range(h):
    b = input()
    board_input.append(b)

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

for i in range(h):
    s = ""
    for j in range(w):
        if board_input[i][j] == '
            s += '
            continue

        num = 0
        for d in range(8):
            ni = i + dx[d]
            nj = j + dy[d]
            if ni > h - 1 or nj > w - 1 or ni < 0 or nj < 0:
                continue
            if board_input[ni][nj] == '
                num += 1
                
        s += str(num)
    board_output.append(s)


for i in range(h):
    print(board_output[i])

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


R = [(1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)]
for i in range(H):
    for j in range(W):
        if T[i][j] == ".":
            rec = 0
            for dx, dy in R:
                nx, ny = i + dx, j + dy
                if 0 <= nx < H and 0 <= ny < W and T[nx][ny] == "
                    rec += 1

            T[i][j] = str(rec)

for i in range(H):
    print("".join(T[i]))

Solution (Python):
def fa():  
    global ans
    print(ans)


def getN():
    return int(input())


def getNM():
    return map(int, input().split())


def getList():
    return list(map(int, input().split()))

def check_mine(i,j,place):
    if place[i][j] == "
        return "

    num = 0
    for x in range(i-1, i+2):
        for y in range(j-1, j+2):
            try:
                if place[x][y] == "
                    if x >= 0 and y >= 0:
                        num += 1
            except:
                pass

    return str(num)

h, w = getList()

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


for i in range(h):
    ans = []
    for j in range(w):
        ans.append(check_mine(i,j,place))
    print("".join(ans))

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

ans = ["" for i in range(h)]

for i in range(h):
    for j in range(w):
        if s[i][j] == "
            ans[i] += "
        else:
            count = 0
            if i - 1 >= 0:
                if j - 1 >= 0:
                    if s[i-1][j-1] == "
                        count += 1
                if s[i-1][j] == "
                    count += 1
                if j + 1 <= w-1:
                    if s[i-1][j+1] == "
                        count += 1
            if j - 1 >= 0:
                if s[i][j-1] == "
                    count += 1
            if j + 1 <= w-1:
                if s[i][j+1] == "
                    count += 1
            if i + 1 <= h-1:
                if j - 1 >= 0:
                    if s[i+1][j-1] == "
                        count += 1
                if s[i+1][j] == "
                    count += 1
                if j + 1 <= w-1:
                    if s[i+1][j+1] == "
                        count += 1
            ans[i] += str(count)

for i in ans:
    print(i)

Solution (Python):
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

h,w = li()
field = [["." for _ in range(w+2)]]
for _ in range(h):
    field.append(["."] + lc() + ["."])
field.append(["." for _ in range(w+2)])

dxs = [0, 1, 1, 1, 0, -1, -1, -1]
dys = [-1, -1, 0, 1, 1, 1, 0, -1]

for hi in range(1,h+1):
    for wj in range(1,w+1):
        if field[hi][wj] == "
            continue
        ans = 0
        for dy,dx in zip(dys,dxs):
            if field[hi+dy][wj+dx] == "
                ans += 1
        
        field[hi][wj] = str(ans)
        
for hi in range(1,h+1):
    print("".join(field[hi][1:-1]))

Solution (Python):
H,W = map(int,input().split())
S = [input() for i in range(H)]

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

ans = [''] * H
for y in range(H):
    for x in range(W):
        if S[y][x] == '
            ans[y] += '
        else:
            b = 0
            for dx,dy in dxy:
                nx,ny = x+dx, y+dy
                if not 0 <= nx < W: continue
                if not 0 <= ny < H: continue
                if S[ny][nx] == '
                    b += 1
            ans[y] += str(b)

print(*ans,sep='\n')

Solution (Python):
H, W = map(int, input().split())
S = []
for h in range(H):
  S.append(list(input()))


for h in range(H):
    for w in range(W):
        cnt = 0
        if S[h][w]==".":
            if w > 0:
                cnt += int(S[h][w-1] == "
            if w < W-1:
                cnt += int(S[h][w+1] == "
                
            if h > 0:
                cnt += int(S[h-1][w] == "
                if w > 0:
                    cnt += int(S[h-1][w-1] == "
                if w < W-1:
                    cnt += int(S[h-1][w+1] == "
                    
            if h < H-1:
                cnt += int(S[h+1][w] == "
                if w > 0:
                    cnt += int(S[h+1][w-1] == "
                if w < W-1:
                    cnt += int(S[h+1][w+1] == "
            
            S[h][w] = str(cnt)

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

Solution (Python):
hw_list = list(map(int, input().split()))
h = hw_list[0]
w = hw_list[1]
row_list = ['.'*(w+2)]

def mine_check(area, x, y):
    mine = 0
    if area[y-1][x-1] == '
        mine += 1
    if area[y-1][x] == '
        mine += 1
    if area[y-1][x+1] == '
        mine += 1
    if area[y][x-1] == '
        mine += 1
    if area[y][x+1] == '
        mine += 1
    if area[y+1][x-1] == '
        mine += 1
    if area[y+1][x] == '
        mine += 1
    if area[y+1][x+1] == '
        mine += 1
    return mine

for i in range(h):
    row_list.append('.'+ input()+ '.')
row_list.append('.'*(w+2))

for y in range(1, h+1):
    temp_list = []
    for x in range(1, w+1):
        if row_list[y][x] == '
            temp_list.append('
        else:
            temp_list.append(str(mine_check(row_list, x, y)))
    print(''.join(temp_list))

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

a=[]
a.append(["_"]*(w+2))
for i in range(1,h+1):
  a.append(["_"] + list(input()) + ["_"])
a.append(["_"]*(w+2))

b=a
for i in range(1,h+1):
  for j in range(1,w+1):
    if a[i][j] != "
      b[i][j] = str((a[i-1][j-1]=="

for i in range(1,h+1):
  print("".join(b[i][1:w+1]))

Solution (Python):
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]=='.':
            b=a[max(i-1,0):min(i+2,h),max(j-1,0):min(j+2,w)].flatten()
            a[i][j]=sum(b=='
for i in a:
    print(''.join(i))

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

index=0
liForli=[]
while index < h:
    li = list(input())
    liForli.append(li)
    index+=1

index2=0
while index2 < len(liForli):
    index3=0
    while index3 < w:
        if liForli[index2][index3]=="
            pass
        else:
            liForli[index2][index3]=0
        index3+=1
    index2+=1

index4=0
while index4 < len(liForli):
    index5=0
    while index5 < w:
        if liForli[index4][index5]=="
            if index4+1 < h:
                if index5+1 < w and liForli[index4+1][index5+1]!="
                    liForli[index4+1][index5+1]+=1
                if index5-1 > -1 and liForli[index4+1][index5-1]!="
                    liForli[index4+1][index5-1]+=1
                if liForli[index4+1][index5]!="
                    liForli[index4+1][index5]+=1
            if index4-1 > -1:
                if index5+1 < w and liForli[index4-1][index5+1]!="
                    liForli[index4-1][index5+1]+=1
                if index5-1 > -1 and liForli[index4-1][index5-1]!="
                    liForli[index4-1][index5-1]+=1
                if liForli[index4-1][index5]!="
                    liForli[index4-1][index5]+=1
            if index5+1 < w and liForli[index4][index5+1]!="
                liForli[index4][index5+1]+=1
            if index5-1 > -1 and liForli[index4][index5-1]!="
                liForli[index4][index5-1]+=1
        index5+=1
    index4+=1

for li in liForli:
    print("".join(list(map(str, li))))

Solution (Python):
h,w = map(int, input().split())
list_prob = []
list_prob.append((list("."*(w+2))))
for i in range(0,h):
    list_prob.append(list("." + str(input()) + "."))
list_prob.append(list("."*(w+2)))
def decis_num(i,j):
    decis_str = \
    list_prob[i-1][j-1] + list_prob[i-1][j] + list_prob[i-1][j+1] + \
    list_prob[i][j-1] + list_prob[i][j+1] + \
    list_prob[i+1][j-1] + list_prob[i+1][j] + list_prob[i+1][j+1]
    return decis_str.count("

for i in range(1,h+1):
    for j in range(1,w+1):
        if list_prob[i][j] == "
            continue
        else:
            list_prob[i][j] = str(decis_num(i,j))
list_ans = []
for row in list_prob:
    list_ans.append(row[1:w+1])
del list_ans[0]
del list_ans[-1]
for row in list_ans:
    print("".join(row))

Solution (Python):

I = [-1,0,1]
J = [-1,0,1]

H, W = map(int,input().split(' '))
S = [input() for i in range(H)]

for i in range(len(S)):
    new_line = ''
    for j in range(len(S[i])):
        if S[i][j]=='.':
            count = 0
            for x in I:
                for y in J:
                    if 0 <= x+i < len(S) and 0 <= y+j < len(S[i]):
                        if S[x+i][y+j] == '
                            count = count + 1
            new_line = new_line + str(count)
        else:
            new_line = new_line + '

    print(new_line)

Solution (Python):
il = lambda: list(map(int, input().split()))
ils = lambda n, s="int(input())": [eval(s) for _ in range(n)]

h, w = il()
s = ils(h, "list(input())")
for i in range(h):
    for j in range(w):
        cnt = 0
        if s[i][j] == "
            continue
        for k, l in zip([-1, -1, -1, 0, 1, 1, 1, 0], [-1, 0, 1, 1, 1, 0, -1, -1]):
            if 0 <= i+k < h and 0 <= j+l < w:
                if s[i + k][j + l] == "
                    cnt += 1
        s[i][j] = cnt
for i in s:
    for j in i:
        print(j, end="")
    print("")

Solution (Python):
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] == '.':
            S[i][j] = str(
                sum(S[x][y] == '
                    for x in range(max(0, i - 1), min(H, i + 2))
                    for y in range(max(0, j - 1), min(W, j + 2))
                )
            )
for s in S:
    print(''.join(s))

Solution (Python):
h,w = map(int,input().split())
ss = []
ssc = []
for i in range(h):
    ss.append(list(input()))
    ssc.append([0]*w)

def hfunc1(i,j):
    if ss[i][j] != "
        ssc[i][j] += 1

def hfunc2(i,j):
    xs = -1
    xe = 2
    ys = -1
    ye = 2

    if i == 0:
        xs = 0
    if i == h-1:
        xe = 1
    if j == 0:
        ys = 0
    if j == w-1:
        ye = 1 

    for x in range(xs,xe):
        for y in range(ys,ye):
                hfunc1(i+x,j+y)
    
for i in range(h):
    for j in range(w):
        if ss[i][j] == "
            ssc[i][j] = "
            hfunc2(i,j)

ans = ""
for x in ssc:
    for y in x:
        ans += str(y)
    ans += "\n"
print(ans)

Solution (Python):
h,w=map(int,input().split())
l=[list(input()) for i in range(h)]
for x in range(h):
 for y in range(w):
  if l[x][y]=='.':
   c=0
   if x>0 and y>0:
    if l[x-1][y-1]=='
   if x>0:
    if l[x-1][y]=='
   if x>0 and y+1<w:
    if l[x-1][y+1]=='
   if y>0:
    if l[x][y-1]=='
   if y+1<w:
    if l[x][y+1]=='
   if x+1<h and y>0:
    if l[x+1][y-1]=='
   if x+1<h:
    if l[x+1][y]=='
   if x+1<h and y+1<w:
    if l[x+1][y+1]=='
   l[x][y]=str(c)
for j in range(h):
  l[j]=''.join(l[j])
  print(l[j])

Solution (Python):
import numpy as np
H, W = map(int, input().split())

S = []
for h in range(H):
    S.append(input())


ans = np.zeros((H+2,W+2),dtype = int)

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

for h in range(H):
    for w,s in enumerate(S[h]):
        if s == '
            x = w + 1
            y = h + 1
            for del_x in dx:
                for del_y in dy:
                    if not (del_x == 0 and del_y == 0):
                        ans[y+del_y][x+del_x] += 1
for h in range(H):
    ans2 = ''
    for w in range(W):
        if S[h][w] == '
            ans2 += '
        else:
            ans2 += str(ans[h+1][w+1])

    print(ans2)

Solution (Python):
H, W = [int(_) for _ in input().split()]

S = ["."*(H+2)] + ["." + input() + "." for i in range(H)] + ["."*(H+2)]

for y in range(H):
    for x in range(W):
        c = S[y+1][x+1]
        if c != "
            c = str(sum([S[i][x:x+3].count("
        print(c, sep="", end="")
    print()

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

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

ans_matrix = []
for h in range(H):
    line = []
    for w in range(W):
        line.append(0)
    ans_matrix.append(line)

for h in range(H):
    for w in range(W):

        if matrix[h][w] == "

            for dh in range(-1, 1 + 1):
                for dw in range(-1, 1 + 1):
                    
                    mat_h = h + dh
                    mat_w = w + dw
                    
                    if mat_h < 0 or H <= mat_h or mat_w < 0 or W <= mat_w:
                        continue

                    ans_matrix[mat_h][mat_w] += 1

for h in range(H):
    for w in range(W):
        
        if matrix[h][w] == "
            print("
        else:
            print(ans_matrix[h][w], end="")
    
    print()

Solution (Python):
H, W = map(int, input().split())
HW = []
for i in range(H):
    HW.append(list(input()))
cnt = [[0 for i in range(W)] for j in range(H)]
for i in range(H):
    for j in range(W):
        if HW[i][j] == "
            if i != 0 and j != 0:
                cnt[i - 1][j - 1] += 1
            if i != 0:
                cnt[i - 1][j] += 1
            if i != 0 and j != W - 1:
                cnt[i - 1][j + 1] += 1
            if j != 0:
                cnt[i][j - 1] += 1
            if j != W - 1:
                cnt[i][j + 1] += 1
            if i != H - 1 and j != 0:
                cnt[i + 1][j - 1] += 1
            if i != H - 1:
                cnt[i + 1][j] += 1
            if i != H - 1 and j != W - 1:
                cnt[i + 1][j + 1] += 1
for i in range(H):
    for j in range(W):
        if HW[i][j] == "
            print("
        else:
            print(str(cnt[i][j]), end = "")
    print()
print()

Solution (Python):
h,w=map(int,input().split())
s,t=[list(input()) for i in range(h)],[[0 for j in range(w+2)] for i in range(h+2)]
for i in range(h):
	for j in range(w):
		if s[i][j]=='.':
			continue
		for p in range(9):
			t[i+p//3][j+p%3]+=1
for i in range(h):
	for j in range(w):
		if s[i][j]=='.':
			s[i][j]=str(t[i+1][j+1])
	print("".join(s[i]))

Solution (Python):
h, w = list(map(int, input().split()))
s = [input() for _ in range(h)]
s_large = [''.join(['.']*(w+2))]\
          + ['.'+s[i]+'.' for i in range(h)]\
          + [''.join(['.']*(w+2))]



for i in range(h):
    for j in range(w):
        n = 0
        if s[i][j] == '
            continue
        for ii in [i, i+1, i+2]:
            for jj in [j, j+1, j+2]:
                if s_large[ii][jj] == '
                    n += 1
        s[i] = s[i][:j]+str(n)+s[i][j+1:]

for i in range(h):
    print(s[i])

Solution (Python):
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


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

Solution (Python):
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    H, W = map(int, input().split())
    f = []
    for _ in range(H):
        f.append(input())

    ans = [[0] * W for _ in range(H)]
    for y in range(H):
        for x in range(W):
            if f[y][x] == "
                ans[y][x] = "
                continue
            num = 0
            for i in range(8):
                ny, nx = dy8[i] + y, dx8[i] + x
                if inside(ny, nx, H, W) and f[ny][nx] == "
                    num += 1

            ans[y][x] = num

    for line in ans:
        print(*line, sep="")


if __name__ == '__main__':
    main()

Solution (Python):
import copy
H, W=map(int, input().split())
S=[['.' for _ in range(W+2)]]+[['.']+list(input())+['.'] for _ in range(H)]+[['.' for _ in range(W+2)]]
S0=copy.deepcopy(S)
for i in range(1, H+1):
    for j in range(1, W+1):
        ct=0
        if S[i][j]=='.':
            for a in range(-1,2):
                for b in range(-1,2):
                    if S[i+a][j+b]=='
                        ct+=1
            S0[i][j]=str(ct)

S1=[]
for i in range(H+2):
    S1.append(''.join(S0[i]))

for i in range(1,H+1):
    print(S1[i][1:W+1])

Solution (Python):

h,w=map(int,input().split())
s=[list('.'*(w+2))]
s.extend([list('.'+input()+'.') for i in range(h)])
s.append(list('.'*(w+2)))


for i in range(1,h+1):
    for j in range(1,w+1):
        if s[i][j]=='.':
            cnt=0
            cnt += s[i-1][j-1:j+2].count('
            cnt += s[i][j-1:j+2].count('
            cnt += s[i+1][j-1:j+2].count('
            s[i][j] = str(cnt)

for i in s[1:-1]:
    print(''.join(i[1:-1]))

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

for r in range(h):
    for c in range(w):
        if s[r][c] == '
            continue
        counter = 0
        for y in range(3):
            for x in range(3):
                nr = r + y - 1
                nc = c + x - 1
                if 0 <= nr < h and 0 <= nc < w and s[nr][nc] == '
                    counter += 1
        res[r][c] = str(counter)

for row in res:
    print(''.join(row))

Solution (Python):
h, w = [int(v) for v in input().split()]
s = [list('.' * (w + 2))]
s.extend([list('.' + input() + '.') for i in range(h)])
s.append(list('.' * (w + 2)))

for i in range(1, h + 1):
    for j in range(1, w + 1):
        if s[i][j] == '.':
            cnt = 0
            cnt += s[i-1][j-1:j+2].count('
            cnt += s[i][j-1:j+2].count('
            cnt += s[i+1][j-1:j+2].count('
            s[i][j] = str(cnt)

for v in s[1:-1]:
    print(''.join(v[1:-1]))