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=[list(input()) for _ in range(H)]
dx=[-1,0,1,-1,1,-1,0,1]
dy=[-1,-1,-1,0,0,1,1,1]

for i in range(H):
  for j in range(W):
    if S[i][j]=='.':
      num=0
      for (x,y) in zip(dx,dy):
        if 0<=i+x<H and 0<=j+y<W and S[i+x][j+y]=='
          num+=1
      S[i][j]=str(num)

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

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

def cange(x):
  if x == '.':
    return 0
  else:
    return 1

zerofill = [ '.' for _ in range(W+2)] 

L.append(zerofill)
for _ in range(H):
  L.append(['.']+list(input())+['.'])
L.append(zerofill)

for i in range(1,H+1):
  for j in range(1,1+W):
    if L[i][j] == '.':
      cnt = 0
      for x in [-1,0,1]:
        for y in [-1,0,1]:
          if not (x == 0 and y == 0):
            cnt += cange(L[i+x][j+y])
      print(cnt,end='')
    else:
      print('
  print()

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

for i in range(h):
    for j in range(w):
        if s[i][j]=='.':
            c = 0
            for iw in range(i-1,i+2):
                for jw in range(j-1,j+2):
                    if iw<0 or h<=iw or jw<0 or w<=jw:
                        continue
                    elif s[iw][jw]=="
                        c+=1
            s[i][j]=str(c)
for s_ in s:
    print(''.join(s_))

Solution (Python):
def main():
    H,W = map(int, input().split())
    S = [input() for i in range(H)]
    
    
    
    
    
    
    
    
    
    
    
    i = 0
    T = S
    
    
    for i in range(H):
        Ten = ''
        
        for j in range(W):
            if S[i][j] == "
                Ten += '
                
            else:
                count = 0
                
                for k in range(3):
                    
                    for l in range(3):
                        if 0 <= i + (k - 1) < H and 0 <= j + (l-1) < W and S[i+(k-1)][j+(l-1)] == '
                            count = count + 1
                Ten += str(count)
    
    
        print(Ten)
        
main()

Solution (Python):
h,w = map(int,input().split())
s = [list(input()) for i in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j]=='.':
            c = 0
            for iw in range(i-1,i+2):
                for jw in range(j-1,j+2):
                    if iw<0 or h<=iw or jw<0 or w<=jw:
                        continue
                    elif s[iw][jw]=="
                        c+=1
            s[i][j]=str(c)
for s_ in s:
    print(''.join(s_))

Solution (Python):
H,W = map(int,input().split())
L = []
ANS = [['
for i in range(H):
  L.append(list(input()))
dx = [0,0,1,1,1,-1,-1,-1]
dy = [1,-1,1,-1,0,1,-1,0]
for i in range(H):
  for j in range(W):
    cnt = 0
    if L[i][j] == '
        continue
    else:
      for k in range(8):
        if i+dy[k] < 0 or i+dy[k] >= H or j+dx[k] < 0 or j+dx[k] >= W:
          None
        else:
          if L[i+dy[k]][j+dx[k]] == '
            cnt += 1
      ANS[i][j] = cnt
for i in range(H):
  for j in range(W):
    print(ANS[i][j],end = '')
  print()

Solution (Python):
H, W = [int(_) for _ in input().split()]
cbd = [list(input()) for _ in range(H)]
for i in range(H): 
    for j in range(W):
        if cbd[i][j] == ".":
            c = 0
            for iw in range(i-1,i+2):
                for jw in range(j-1,j+2):
                    if iw < 0 or H <= iw or jw < 0 or W <= jw:
                        continue
                    elif cbd[iw][jw] == "
                        c += 1
            cbd[i][j] = str(c)
for i in range(H):
    print("".join(cbd[i]))

Solution (Python):

def look(S, i,j):
    if S[i][j] is '
    h = len(S)
    w = len(S[0])
    cnt=0
    for ii in range(-1, 2):
        for jj in range(-1, 2):
            if ii+i<0 or ii+i >= h or jj+j<0 or jj+j >= w or (ii==0 and jj==0): continue
            t = S[i+ii][j+jj]
            if t is '
    return cnt


h,w=map(int,input().split())
mat = [input() for _ in range(h)]

for i in range(h):
    for j in range(w):
        print(look(mat, i, j), end='')
    print('')

Solution (Python):
h, w = map(int, input().split())
s = [input() for _ in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            sum = 0
            for a in range(max(i-1, 0), min(i+2, h)):
                for b in range(max(j-1, 0), min(j+2, w)):
                    if s[a][b] == "
                        sum += 1
            print(sum, end="")
        else:
            print("
    print()

Solution (Python):
h,w = map(int,input().split())
s = [list(input()) for i in range(h)]
ans = []
line = [0 for i in range(w)]
ad = ["." for i in range(w+2)]

for i in range(h):
    s[i].insert(0,".")
    s[i].append(".")
s.insert(0,ad)
s.append(ad)



for i in range(1,h+1):
    for j in range(1,w+1):
        cnt =[]
        if s[i][j] =="
            line[j-1] = "
        else:
            for k in range(3):
                for l in range(3):
                    cnt.append(s[i-1+k][j-1+l])
            line[j-1] = str(cnt.count("
        del cnt
    ans.append("".join(line))
for i in range(h):
    print(ans[i])

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


'''generating a grid expanded by '&'. For example,

            &&&&&



            &&&&&

'''

expanded_grid = [list('&' * (W + 2))]
for row in rows:
    expanded_grid.append(list('&' + row + '&'))
expanded_grid.append(list('&' * (W + 2)))

for i in range(H):
    for j in range(W):
        if (grid[i])[j] == '.':
            EightPiece = [
                (expanded_grid[i])[j],
                (expanded_grid[i])[j+1],
                (expanded_grid[i])[j + 2],

                (expanded_grid[i+1])[j],
                (expanded_grid[i+1])[j+2],

                (expanded_grid[i+2])[j],
                (expanded_grid[i+2])[j+1],
                (expanded_grid[i+2])[j+2],
            ]

            (grid[i])[j] = str(EightPiece.count('

for row_in_the_form_of_list in grid:
    print(''.join(row_in_the_form_of_list))

Solution (Python):
a = input().split()
H = int(a[0])
W = int(a[1])

ans = []
for i in range(H+2):
 ans.append([])
 for j in range(W+2):
   ans[i].append(0)

S = []
S.append([])
for j in range(W+2):
   S[0].append('.')
for i in range(H):
  s = input()
  s = list(s)
  s.insert(0,'.')
  s.append('.')
  S.append(s)
S.append([])
for j in range(W+2):
   S[-1].append('.')

for i in range(H+2):
  if((i != 0)and(i != H+1)):
   for j in range(W+2):
    if((j != 0)and(j != W+1)):
      if(S[i][j] == '
        ans[i][j] = '
      else:
       if(S[i-1][j] == '
        ans[i][j] += 1
       if(S[i+1][j] == '
        ans[i][j] += 1
       if(S[i][j+1] == '
        ans[i][j] += 1
       if(S[i][j-1] == '
        ans[i][j] += 1 
       if(S[i-1][j+1] == '
        ans[i][j] += 1
       if(S[i-1][j-1] == '
        ans[i][j] += 1
       if(S[i+1][j+1] == '
        ans[i][j] += 1
       if(S[i+1][j-1] == '
        ans[i][j] += 1
        
for i in range(H+2):
  if((i != 0)and(i != H+1)):
   ans[i].pop(0)
   ans[i].pop(-1)
   for j in range(W):
    ans[i][j] = str(ans[i][j])
   print(''.join(ans[i]))

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

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

Solution (Python):
h, w = map(int, input().split())
S = [list(input()) for i in range(h)]
          
for i in range(h):
    for j in range(w):
        if S[i][j] == '.':
            cnt = 0
            for k in range(-1, 2):
                for l in range(-1, 2):
                    ni = i + k
                    nj = j + l
                    if 0 <= ni < h and 0 <= nj < w and S[ni][nj] == '
                        cnt += 1                    
            S[i][j] = cnt
                        
for i in range(h):
    print(''.join(map(str, S[i])))

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

for i in range(h):
    for j in range(w):
        if S[i][j] == '.':
            S[i][j] = 0
            
for i in range(h):
    for j in range(w):
        if S[i][j] == '
            for k in range(-1, 2):
                for l in range(-1, 2):
                    ni = i + k
                    nj = j + l
                    if 0 <= ni < h and 0 <= nj < w and S[ni][nj] != '
                        S[ni][nj] += 1
                        
for i in range(h):
    print(''.join(map(str, S[i])))

Solution (Python):
h,w=map(int,input().split())
s=[]
s.append(["$"]*(w+2))
for i in range(h):
    s.append(list("$"+input()+"$"))
s.append(["$"]*(w+2))
c=[]
for j in range(h+2):
    v=[]
    for k in range(w+2):
        v.append(0)
    c.append(v)
for y in range(1,h+1):
    for x in range(1,w+1):
        if s[y-1][x-1]=="
            c[y][x]+=1
        if s[y-1][x]=="
            c[y][x]+=1
        if s[y-1][x+1]=="
            c[y][x]+=1
        if s[y][x-1]=="
            c[y][x]+=1
        if s[y][x+1]=="
            c[y][x]+=1
        if s[y+1][x-1]=="
            c[y][x]+=1
        if s[y+1][x]=="
            c[y][x]+=1
        if s[y+1][x+1]=="
            c[y][x]+=1
for y in range(1,h+1):
    ans=""
    for x in range(1,w+1):
        if s[y][x]==".":
            ans+=str(c[y][x])
        else:
            ans+=s[y][x]
    print(ans)

Solution (Python):

h,w = map(int, input().split())
ss = [list(map(str,str(input()))) for _ in range(h)]

def count_bombs(ss,i,j):
    count=0
    if ss[i][j]=='
        return '
    for y in [-1,0,1]:
        for x in [-1,0,1]:

            if 0<=i+y<h and 0<=j+x<w and ss[i+y][j+x]=='
                count+=1
    return str(count)

for i in range(h):
    for j in range(w):
        ss[i][j] = count_bombs(ss,i,j)

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

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

result = [[0 for _ in range(W+1)]for _ in range(H+1)]
for i in range(H):
  for j in range(W):
    if(S[i][j] == '
      result[i][j] = '
      if(result[i-1][j-1] != '
        result[i-1][j-1] += 1
      if(result[i-1][j] != '
        result[i-1][j] += 1
      if(result[i-1][j+1] != '
        result[i-1][j+1] += 1
      if(result[i][j-1] != '
        result[i][j-1] += 1
      if(result[i][j+1] != '
        result[i][j+1] += 1
      if(result[i+1][j-1] != '
        result[i+1][j-1] += 1
      if(result[i+1][j] != '
        result[i+1][j] += 1
      if(result[i+1][j+1] != '
        result[i+1][j+1] += 1

for r in result[:-1]:
  print(''.join(list(map(str,r[:W]))))

Solution (Python):
h,w=map(int,input().split())
mapdata=[]
for i in range(h):
  line=(str(input()))
  line2=list(line)
  mapdata.append(line2)
result=[]
k=[]
def get_bomb(i,j):
  count=0
  for x in (i-1,i,i+1):
    for y in (j-1,j,j+1):
      if 0<=x<=h-1 and 0<=y<=w-1:
        if mapdata[x][y]=='
          count+=1
  return count
for i in range(h):
  for j in range(w):
    if mapdata[i][j]=='.':
      k.append(str(get_bomb(i,j)))
    else:
      k.append('
  result.append(k)
  k=[]
for i in range(len(result)):
  result2=''.join(result[i])
  print(result2)

Solution (Python):
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools

def j(q):
    if q==1: print("Yes")
    else:print("No")
    exit(0)


def ct(x,y):
    if (x>y):print("")
    elif (x<y): print("")
    else: print("")

def ip():
    return int(input())

def swap(s,pos):
    s[pos]-=1
    s[pos+1]+=1
    print(s)
    if pos == n-2: return s
    if s[pos+2] == 0: swap(s,pos+1)
    return s



h,w= (int(i) for i in input().split())      










a = []

for i in range(h):
    a.append(input())
adj = [[0 for i in range(w)] for j in range(h)]
for i in range(h):
    for j in range(w):
        for x in range(-1, 2):
            for y in range(-1, 2):
                if x+y or x*y:
                    if 0 <= i + x < h and 0 <= j + y < w:
                        if a[i + x][j + y] == '
for i in range(h):
    for j in range(w):
        if a[i][j] == "
        else :print(adj[i][j],end='')
    print()

Solution (Python):

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

H, W = map(int, input().split())
field = []

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

for y in range(H):
    for x in range(W):

        if field[y][x] == '
            continue

        cnt = 0

        for k in range(8):
            ny = y + dy[k]
            nx = x + dx[k]

            if ny < 0 or H <= ny\
                    or nx < 0 or W <= nx:
                continue

            if field[ny][nx] == '
                cnt += 1

        field[y][x] = str(cnt)

for y in range(H):
    print("".join(field[y]))

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

H, W = map(int, input().split())
field = [list(input()) for _ in range(H)]

def count_bombs(i, j):
    search_target = []
    if i != 0:
        search_target += field[i-1][max(0,j-1):min(W,j+2)]
    if i != H-1:
        search_target += field[min(H-1,i+1)][max(0,j-1):min(W,j+2)]
    search_target += field[i][max(0,j-1):min(W,j+2)]
    bombs = str(sum(1 if x == '
    return bombs


for i in range(H):
    for j in range(W):
        if field[i][j] == '.':
            field[i][j] = count_bombs(i, j)

for i in range(H):
    print("".join(field[i]), end='')

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

for y in range(h):
  for x in range(w):
    if s[y][x] =='.':
      cnt = 0
      for dx, dy in delta:
        if 0 <= x + dx < w and 0<= y + dy < h and s[y + dy][x + dx] == '
          cnt += 1
      s[y][x] = str(cnt)

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

Solution (Python):
import copy
y,x = map(int,input().split())
maps = []


def f(i,x,maps): 
    l = []
    if i > 0  and x > 0:
        try:
            l.append(maps[i-1][x-1])
        except:
            pass
        try:
            l.append(maps[i-1][x])
        except:
            pass
        try:
            l.append(maps[i-1][x+1])
        except:
            pass
        try:
            l.append(maps[i][x-1])        
        except:
            pass
        try:
            l.append(maps[i][x+1])        
        except:
            pass
        try:
            l.append(maps[i+1][x-1])        
        except:
            pass
        try:
            l.append(maps[i+1][x])   
        except:
            pass
        try:
            l.append(maps[i+1][x+1])        
        except:
            pass
    elif i > 0 and x == 0:
        try:
            l.append(maps[i-1][x])
        except:
            pass
        try:
            l.append(maps[i-1][x+1])    
        except:
            pass
        try:
            l.append(maps[i][x+1])        
        except:
            pass
        try:
            l.append(maps[i+1][x])   
        except:
            pass
        try:
            l.append(maps[i+1][x+1])
        except:
            pass
    elif i == 0 and x > 0:
        try:
            l.append(maps[i][x-1])       
        except:
            pass
        try:
            l.append(maps[i][x+1])
        except:
            pass
        try:
            l.append(maps[i+1][x-1])
        except:
            pass
        try:
            l.append(maps[i+1][x])   
        except:
            pass
        try:
            l.append(maps[i+1][x+1])
        except:
            pass
    elif i == 0 and x == 0:
        try:
            l.append(maps[i][x+1])    
        except:
            pass
        try:
            l.append(maps[i+1][x])           
        except:
            pass
        try:
            l.append(maps[i+1][x+1])        
        except:
            pass

    return l


for i in range(y):
    s = str(input())
    maps.append([s[i] for i in range(x)])
maps2 = copy.deepcopy(maps)
for i in range(y):
    for j in range(x):
        r = maps[i][j]
        ll = f(i,j,maps)

        if r == ".":
            k = ll.count("
            maps2[i][j] = str(k)

for i in range(y):
    print(''.join(maps2[i]))

Solution (Python):
H, W = map(int, input().split())
S = []
for _ in [0]*H:
    S.append(list(input().rstrip()))

delta = [[-1, -1], [-1, 0], [-1, 1],
        [0, -1], [0, 1],
        [1, -1], [1, 0], [1, 1]]
for x in range(H):
    for y in range(W):
        if S[x][y] == '.':
            cnt = 0
            for dx, dy in delta:
                if 0 <= x + dx < H and 0 <= y + dy < W:
                    if S[x+dx][y+dy] == '
                        cnt += 1
            S[x][y] = str(cnt)

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

Solution (Python):
def check(arr, x, y):
    d = ((0, -1), (0, 1), (1, -1), (1, 0), (1, 1), (-1, -1), (-1, 0), (-1, 1))

    if arr[x][y] == '
        return -1
    else:
        cnt = 0
        for dx, dy in d:
            try:
                if (x+dx) >=0 and (y+dy) >= 0:
                    if arr[x + dx][y + dy] == '
                        cnt += 1
            except:
                pass
    return cnt    

h, w = map(int, input().split())
s = []
for _ in range(h):
    s.append(input())
ans = []
for x in range(h):
    for y in range(w):
        val = check(s, x, y)
        if val == -1:
            ans.append('
        else:
            ans.append(val)

for i in range(h*w):
    print(ans[i], end="")
    if (i+1)%w == 0:
        print()

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



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

for i in range(h):
    temp = []
    for j in range(w):
        count = 0
        if s[i][j] == '
            temp.append('
            continue
        for k in range(len(dx)):
            xx = j + dx[k]
            yy = i + dy[k]
            if (xx < 0) or (xx > w - 1) or (yy < 0) or (yy > h - 1):
                continue
            
            if s[yy][xx] == '
                count += 1
        temp.append(str(count))
    t.append(temp)
for i in range(h):
    row = ''
    for x in t[i]:
        row += x
    print(row)

Solution (Python):
from sys import stdin
h, w = [int(x) for x in stdin.readline().rstrip().split()]
matrix = [stdin.readline().rstrip() for _ in range(h)]
for i in range(h):
    matrix[i] = [matrix[i][x:x+1] for x in range(len(matrix[i]))]
    matrix[i] = [0 if x == '.' else x for x in matrix[i]]
for i in range(h):
    for j in range(w):
        if matrix[i][j] == '
            for n in range(-1, 2):
                for m in range(-1, 2):
                    i_n = i + n
                    j_m = j + m
                    if h > i_n >= 0 and w > j_m >= 0 :
                    	if matrix[i_n][j_m] != '
                        	matrix[i_n][j_m] += 1
for i in range(h):
  for j in range(w):
  	print('{}'.format(matrix[i][j]), end = '')
  print('')

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

for i in range(1, h + 1):
    for j in range(1, w + 1):
        if A[i][j] == '.':
            cnt = 0
            for k in range(-1, 2):
                for l in range(-1, 2):
                    if A[i + k][j + l] == '
                        cnt += 1
            A[i][j] = str(cnt)
            
for i in range(1, h + 1):
    print(''.join(A[i][1:w + 1]))

Solution (Python):
import sys
size=input()
size=size.split()
H=int(size[0])
W=int(size[1])
string_input=[]
mine_state=[]
no_state=[]
count_list=[[0 for i in range(W)] for j in range(H)]
dx=[1,0,-1,0,1,1,-1,-1]
dy=[0,1,0,-1,1,-1,1,-1]
for num in range(H):
    s=input()
    string_input.append(s)
for i in range(H):
    for j in range(W):
        if string_input[i][j]=='.':
            no_state.append((i,j))
        else:
            mine_state.append((i,j))
for i in range(H):
    for j in range(W):
        if (i,j) in no_state:
            count=0
            for d in range(8):
                if (i+dx[d],j+dy[d]) in  mine_state:
                    count+=1
                count_list[i][j]=count
        else:
            count_list[i][j]='
for i in range (H):
    for j in range(W):
        sys.stdout.write(str(count_list[i][j]))
    print()

Solution (Python):
H, W = map(int, input().split())
map = [list('.' * (W + 2)) for _ in range(H + 2)]
Smap = [input() for _ in range(H)]



for line in range(1, H + 1):
    for row in range(1, W + 1):
        mapper = Smap[line - 1][row - 1]
        map[line][row] = mapper

for line in range(1, H + 1):
    for row in range(1, W + 1):

        bomb_counter = 0
        for counter_line in range(-1, 2):
            for counter_row in range(-1, 2):
                if counter_line == 0 and counter_row == 0:
                    pass
                elif map[counter_line + line][counter_row + row] == '
                    bomb_counter += 1
        if map[line][row] != '
            map[line][row] = str(bomb_counter)

for i in range(1, len(map)):
    print('.'.join(map[i]).replace('.', ''))

Solution (Python):
int_h, int_w = map(int, input().split())
l_h = list()
for i in range(int_h):
    l_h.append(input())

l_temp = list()
l_temp.append(list(map(int, "0" * (int_w + 2))))
for r in l_h:
    l_temp.append(list(map(lambda x: int(x) if x != "

l_temp.append(list(map(int, "0" * (int_w + 2))))





for rownum, row in enumerate(l_temp):
    for colnum, col in enumerate(row):
        if col == "
            for c in [-1, 0, 1]:
                if l_temp[rownum - 1][colnum + c] != "
                    l_temp[rownum - 1][colnum + c] += 1
                if l_temp[rownum + 1][colnum + c] != "
                    l_temp[rownum + 1][colnum + c] += 1
            for c in [-1, 1]:
                if l_temp[rownum][colnum + c] != "
                    l_temp[rownum][colnum + c] += 1


for row in l_temp[1:-1]:
    print("".join(map(str,row[1:-1])))

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


for i in range(h):
  for j in range(w):
    count = 0 
    if s[i][j]==".":
      for k in [[0,1],[1,0],[-1,0],[0,-1],[1,1],[-1,-1],[1,-1],[-1,1]]:
        if 0<=k[0]+i<h and  0<=k[1]+j<w:
          if s[k[0]+i][k[1]+j]=="
            count = count +1
      s[i] = s[i][0:j]+str(count)+s[i][j+1:w]
      
for i in range(h):
  for j in range(w):
    print(s[i][j], end="")
  print()

Solution (Python):
[h,w] = [int(i) for i in input().split()]
s = []
for i in range(h):
    s.append(input())
ans1 = []
if h != 1 and w != 1:
    for i in range(h):
        ans = []
  
        if i != 0 and i != h-1:
            for j in range(w):
            
                if j != 0 and j != w-1:
                    if s[i][j] == ".":
                        ans.append((s[i-1][j]+s[i+1][j]+s[i][j-1]+s[i][j+1]+s[i-1][j-1]+s[i-1][j+1]+s[i+1][j-1]+s[i+1][j+1]).count("
                    else:
                        ans.append(s[i][j])
                elif j == 0:
                    if s[i][j] == ".":
                        ans.append((s[i-1][j]+s[i+1][j]+s[i][j+1]+s[i-1][j+1]+s[i+1][j+1]).count("
                    else:
                        ans.append(s[i][j])
                else:
                    if s[i][j] == ".":
                        ans.append((s[i-1][j]+s[i+1][j]+s[i][j-1]+s[i-1][j-1]+s[i+1][j-1]).count("
                    else:
                        ans.append(s[i][j])
        elif i == 0:
            for j in range(w):
                
                if j != 0 and j != w-1:
                    if s[i][j] == ".":
                        ans.append((s[i+1][j]+s[i][j-1]+s[i][j+1]+s[i+1][j-1]+s[i+1][j+1]).count("
                    else:
                        ans.append(s[i][j])
                elif j == 0:
                    if s[i][j] == ".":
                        ans.append((s[i+1][j]+s[i][j+1]+s[i+1][j+1]).count("
                    else:
                        ans.append(s[i][j])
                else:
                    if s[i][j] == ".":
                        ans.append((s[i+1][j]+s[i][j-1]+s[i+1][j-1]).count("
                    else:
                        ans.append(s[i][j])
        else:
            for j in range(w):
        
                if j != 0 and j != w-1:
                    if s[i][j] == ".":
                        ans.append((s[i-1][j]+s[i][j-1]+s[i][j+1]+s[i-1][j-1]+s[i-1][j+1]).count("
                    else:
                        ans.append(s[i][j])
                elif j == 0:
                    if s[i][j] == ".":
                        ans.append((s[i-1][j]+s[i][j+1]+s[i-1][j+1]).count("
                    else:
                        ans.append(s[i][j])
                else:
                    if s[i][j] == ".":
                        ans.append((s[i-1][j]+s[i][j-1]+s[i-1][j-1]).count("
                    else:
                        ans.append(s[i][j])
        ans1.append(ans)
    for i in range(h):
        for j in range(w):
            print(ans1[i][j],end = "")
        print("")

elif h != 1 and w == 1:
    
    ans = []
    for i in range(h):
        if i !=0 and i != h-1:
            if s[i][0] == ".":
                ans.append((s[i-1][0]+s[i+1][0]).count("
            else:
                ans.append(s[i][0])
        elif i == 0:
            if s[i][0] == ".":
                ans.append((s[i+1][0]).count("
            else:
                ans.append(s[i][0])
        else:
            if s[i][0] == ".":
                ans.append((s[i-1][0]).count("
            else:
                ans.append(s[i][0])

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

elif h == 1 and w != 1:
    
    ans = []
    for j in range(w):
        if j != 0 and j!= w-1:
            if s[0][j] == ".":
                ans.append((s[0][j-1]+s[0][j+1]).count("
            else:
                ans.append(s[0][j])
        elif j == 0:
            if s[0][j] == ".":
                ans.append((s[0][j+1]).count("
            else:
                ans.append(s[0][j])
        else:
            if s[0][j] == ".":
                ans.append((s[0][j-1]).count("
            else:
                ans.append(s[0][j])
    for j in range(w):
        print(ans[j],end = "")
else:
    ans = []
    if s[0][0] == ".":
        ans.append(0)
    else:
        ans.append(s[0][0])
    print(ans[0])

Solution (Python):
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001


H,W = map(int,input().split())

def rangeCheck(row,col):
    return row >= 0 and row <= H-1 and col >= 0 and col <= W-1

diff_row = [-1,-1,-1,0,0,1,1,1]
diff_col = [-1,0,1,-1,1,-1,0,1]

table = [list(str(input())) for _ in range(H)]

for row in range(H):
    for col in range(W):
        if table[row][col] != '.':continue
        count = 0
        for i in range(8):
            adj_row = row+diff_row[i]
            adj_col = col+diff_col[i]
            if rangeCheck(adj_row,adj_col) == False:continue
            if table[adj_row][adj_col] == '

        table[row][col] = str(count)

for row in range(H):
    for col in range(W):
        print("%c"%(table[row][col]),end="")
    print("")

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

from itertools import product
def num(i,j):
    c=0
    for p,q in product([-1,0,1],repeat=2):
        if 0<=i+p<H and 0<=j+q<W and S[i+p][j+q]=='
            c+=1
    return c

for i in range(H):
    for j in range(W):
        if S[i][j]=='.':
            S[i][j]=str(num(i,j))
    print(''.join(S[i]))

Solution (Python):
h,w=map(int,input().split())
s=[list(input().replace(".","0")) for i in range(h)]
for i in range(h):
  for j in range(w):
    if s[i][j]=="
      for k in range(-1,2):
        for l in range(-1,2):
          if 0<=i+k<h and 0<=j+l<w and s[i+k][j+l]!="
              s[i+k][j+l]=str(int(s[i+k][j+l])+1)
for i in range(h):
  for j in range(w):
    print(s[i][j], end="")
  print()

Solution (Python):
H,W = map(int,input().split())
L = []
blank = ['.' for _ in range(W+2)]
L.append(blank)

def cnt(x):
    if x == '
        return 1
    else:
        return 0

for _ in range(H):
    L.append(['.']+list(input())+['.'])
L.append(blank)

for i in range(1,H+1):
    for j in range(1,W+1):
        if L[i][j] == '
            print('
        else:
            c = 0
            for x in [-1,0,1]:
                for y in [-1,0,1]:
                    if not (x==y==0):
                        c += cnt(L[i+x][j+y])
            print(c,end='')
    print()

Solution (Python):
H,W = map(int,input().split())
L = []
blank = ['.' for _ in range(W+2)]
L.append(blank)
def cnt(x):
    if x == '
        return 1
    else:
        return 0

for _ in range(H):
    L.append(['.']+list(input())+['.'])
L.append(blank)
for i in range(1,H+1):
    for j in range(1,W+1):
        if L[i][j] == '
            print('
        else:
            c = cnt(L[i-1][j])+cnt(L[i][j-1])+cnt(L[i+1][j])+cnt(L[i][j+1])+cnt(L[i-1][j-1])+cnt(L[i+1][j-1])+cnt(L[i+1][j+1])+cnt(L[i-1][j+1])
            print(c,end='')
    print()