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-----
3 5
.....
.#.#.
.....

-----Sample Output-----
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.
[{"code": "# \u611a\u76f4\nh, w = map(int, input().split())\ntable = [list(input()) for _ in range(h)]\nfor i in range(h):\n    for j in range(w):\n        if table[i][j] == \".\":\n            num = 0\n            for y in [-1, 0, 1]:\n                for x in [-1, 0, 1]:\n                    if 0 <= i + y < h and 0 <= j + x < w:\n                        if table[i + y][j + x] == \"#\":\n                            num += 1\n            table[i][j] = str(num)\nfor t in table:\n    print(\"\".join(t))", "passed": true, "time": 0.24, "memory": 14248.0, "status": "done"}, {"code": "h,w=map(int,input().split())\nl = [input() for _ in range(h)]\nk = [['#' for x in range(w) ] for _ in range(h)]\ndx = [0,0,1,-1,1,1,-1,-1]\ndy = [1,-1,0,0,1,-1,1,-1]\nfor i in range(h):\n    for j in range(w):\n        if l[i][j] == '.':\n            cnt = 0\n            for di in range(8):\n                x = j+dx[di]\n                y = i+dy[di]\n                if x<0 or y<0 or x >=w or y >=h:\n                    continue\n                if l[y][x] == '#':\n                    cnt +=1\n            k[i][j] = cnt\nfor i in range(h):\n    print(''.join(map(str, k[i])))", "passed": true, "time": 0.24, "memory": 14156.0, "status": "done"}, {"code": "import sys\nH, W = map(int, input().split())\nif H == 1:\n    if W == 1:\n        s = input()\n        if s == \"#\":\n            print(\"#\")\n        else:\n            print(0)\n    else:\n        cnt = [0 for _ in range(W)]\n        s = list(input())\n        for w in range(W):\n            if w == 0:\n                cnt[w] += s[w+1] == \"#\"\n            elif w == W-1:\n                cnt[w] += s[w-1] == \"#\"\n            else:\n                cnt[w] += s[w+1] == \"#\"\n                cnt[w] += s[w-1] == \"#\"\n        for w in range(W):\n            if s[w] == \"#\":\n                cnt[w] = \"#\"\n        ans = map(str, cnt)\n        print(\"\".join(ans))\n    return\nif W == 1:\n    cnt = [0 for _ in range(H)]\n    s = []\n    for h in range(H):\n        s.append(input())\n    for h in range(H):\n        if h == 0:\n            cnt[h] += s[h+1] == \"#\"\n        elif h == H-1:\n            cnt[h] += s[h-1] == \"#\"\n        else:\n            cnt[h] += s[h-1] == \"#\"\n            cnt[h] += s[h+1] == \"#\"\n    for h in range(H):\n        if s[h] == \"#\":\n            print(\"#\")\n        else:\n            print(cnt[h])\n    return\n    \nS = []\ncnt = [[0 for _ in range(W)] for _ in range(H)]\nfor h in range(H):\n    s = list(input())\n    for w in range(W):\n        if w == 0:\n            cnt[h][w] += s[w+1] == \"#\"\n        elif w == W-1:\n            cnt[h][w] += s[w-1] == \"#\"\n        else:\n            cnt[h][w] += s[w+1] == \"#\"\n            cnt[h][w] += s[w-1] == \"#\"\n    S.append(s)\n    \nfor h in range(H):\n    for w in range(W):\n        if h == 0:\n            cnt[h][w] += S[h+1][w] == \"#\"\n            if w == 0:\n                cnt[h][w] += S[h+1][w+1] == \"#\"\n            elif w == W-1:\n                cnt[h][w] += S[h+1][w-1] == \"#\"\n            else:\n                cnt[h][w] += S[h+1][w-1] == \"#\"\n                cnt[h][w] += S[h+1][w+1] == \"#\"\n        elif h == H-1:\n            cnt[h][w] += S[h-1][w] == \"#\"\n            if w == 0:\n                cnt[h][w] += S[h-1][w+1] == \"#\"\n            elif w == W-1:\n                cnt[h][w] += S[h-1][w-1] == \"#\"\n            else:\n                cnt[h][w] += S[h-1][w-1] == \"#\"\n                cnt[h][w] += S[h-1][w+1] == \"#\"\n        else:\n            cnt[h][w] += S[h+1][w] == \"#\"\n            if w == 0:\n                cnt[h][w] += S[h+1][w+1] == \"#\"\n            elif w == W-1:\n                cnt[h][w] += S[h+1][w-1] == \"#\"\n            else:\n                cnt[h][w] += S[h+1][w-1] == \"#\"\n                cnt[h][w] += S[h+1][w+1] == \"#\"\n            cnt[h][w] += S[h-1][w] == \"#\"\n            if w == 0:\n                cnt[h][w] += S[h-1][w+1] == \"#\"\n            elif w == W-1:\n                cnt[h][w] += S[h-1][w-1] == \"#\"\n            else:\n                cnt[h][w] += S[h-1][w-1] == \"#\"\n                cnt[h][w] += S[h-1][w+1] == \"#\"\n                \nfor h in range(H):\n    s = S[h]\n    for w in range(W):\n        if s[w] == \"#\":\n            cnt[h][w] = \"#\"\n    ans = map(str, cnt[h])\n    print(\"\".join(ans))", "passed": true, "time": 0.14, "memory": 14548.0, "status": "done"}, {"code": "H,W = map(int,input().split())\n\nS = [input() for _ in range(H)]\nM = [[\"\"]*W for _ in range(H)]\n\ndef bomb_cnt(i,j):\n  min_h = max(0,i-1)\n  max_h = min(i+2,H)\n  min_w = max(0,j-1)\n  max_w = min(j+2,W)\n  cnt = 0\n  for k in range(min_h,max_h):\n    for g in range(min_w,max_w):\n      if (S[k][g] == \"#\"):\n        cnt += 1\n        \n  return str(cnt)\n\nfor i in range(H):\n  for j in range(W):\n    if S[i][j] == \"#\":\n      M[i][j] = \"#\"\n    else:\n      M[i][j] = bomb_cnt(i,j)\n      \n      \nfor i in range(H):\n  print(*M[i],sep=\"\")", "passed": true, "time": 0.24, "memory": 14240.0, "status": "done"}, {"code": "h, w = list(map(int, input().split()))\ns = [list(map(str, input())) for i in range(h)]\nans = s\n\ndi = [1, 0, -1, 0, 1, -1, -1, 1]\ndj = [0, 1, 0, -1, 1, 1, -1, -1]\n\nfor i in range(h):\n    for j in range(w):\n        if s[i][j] == '#':\n            continue\n        cnt = 0\n        for d in range(8):\n            if i + di[d] <0 or i + di[d] > h - 1 or j + dj[d] < 0 or j + dj[d] > w - 1:\n                continue\n            if s[i + di[d]][j +dj[d]] == '#':\n                cnt += 1\n        ans[i][j] = cnt\n\nfor i in range(h):\n    print((''.join(map(str, ans[i]))))\n", "passed": true, "time": 0.15, "memory": 14136.0, "status": "done"}, {"code": "H,W=map(int,input().split())\nS=[]\nfor i in range(H):\n  S.append(list(input()))\nfor j in range(H):\n  for p in range(W):\n    if S[j][p]==\".\":\n      c=0\n      for h,w in [(1,0),(0,1),(-1,0),(0,-1),(1,1),(-1,-1),(-1,1),(1,-1)]:\n        if 0<=j+h<=H-1 and 0<=p+w<=W-1 and S[j+h][p+w]==\"#\":\n          c+=1\n        S[j][p]=c\nfor i in S:\n  print(*i,sep=\"\")", "passed": true, "time": 0.15, "memory": 14232.0, "status": "done"}, {"code": "def resolve():\n    h,w=map(int,input().split())\n    s=[]\n    for _ in range(h):\n        s.append(list(input()))\n    dx=[-1,-1,-1,0,0,1,1,1]\n    dy=[-1,0,1,-1,1,-1,0,1]\n    for x in range(h):\n        for y in range(w):\n            if s[x][y]=='#':\n                for k in range(8):\n                    nx=x+dx[k]\n                    ny=y+dy[k]\n                    if not(nx<h and 0<=nx and ny<w and 0<=ny) or s[nx][ny]=='#':\n                        continue\n                    if s[nx][ny]=='.':\n                        s[nx][ny]='1'\n                    else:\n                        s[nx][ny]=str(ord(s[nx][ny])-ord('0')+1)\n    for i in range(h):\n        for j in range(w):\n            if s[i][j]=='.':\n                s[i][j]='0'\n    for i in range(h):\n        print(''.join(s[i]))\nresolve()", "passed": true, "time": 0.25, "memory": 14308.0, "status": "done"}, {"code": "H,W=map(int,input().split())\nS=[list(input()) for _ in range(H)]\n\ndi=[1,1,0,-1,-1,-1,0,1]\ndj=[0,1,1,1,0,-1,-1,-1]\n\nfor i in range(H):\n    for j in range(W):\n        ans=0\n        if S[i][j]=='#':\n            continue\n        for k in range(8):\n            ni=i+di[k]\n            nj=j+dj[k]\n            if ni<0 or nj<0 or ni>=H or nj>=W:\n                continue\n            if S[ni][nj]=='#':\n                ans+=1\n        S[i][j]=str(ans)\nfor i in range(H):\n    for j in range(W):\n        print(S[i][j],end='')\n    print()\n", "passed": true, "time": 0.16, "memory": 14272.0, "status": "done"}, {"code": "h,w = map(int,input().split())\nl = [[\".\"]*(w+2)]\nfor i in range(h):\n    l.append([\".\"] + [i for i in input()] + [\".\"])\nl.append([\".\"]*(w+2))\n \ndef count(i,j):\n    if l[i][j] == \"#\":\n        return \"#\"\n    c = 0\n    for n in range(i-1,i+2):\n        for m in range(j-1,j+2):\n            if l[n][m] == \"#\":\n                c += 1\n    return str(c)\n \nans = [\"\".join([count(i,j) for j in range(1,1+w)]) for i in range(1,1+h)]\n \nprint(\"\\n\".join(ans))", "passed": true, "time": 0.23, "memory": 14324.0, "status": "done"}, {"code": "h, w = map(int, input().split())\ns = []\nt = []\nfor i in range(h):\n    s.append(input())\n\nfor i in range(h):\n    t.append([])\n    for j in range(w):\n        mines = 0\n        if s[i][j] == '.':\n            if i > 0 and j > 0:\n                if s[i - 1][j - 1] == '#':\n                    mines += 1\n            if i < h - 1 and j > 0:\n                if s[i + 1][j - 1] == '#':\n                    mines += 1\n            if i > 0 and j < w - 1:\n                if s[i - 1][j + 1] == '#':\n                    mines += 1\n            if i < h - 1 and j < w - 1:\n                if s[i + 1][j + 1] == '#':\n                    mines += 1\n            if i > 0:\n                if s[i - 1][j] == '#':\n                    mines += 1\n            if i < h - 1:\n                if s[i + 1][j] == '#':\n                    mines += 1\n            if j > 0:\n                if s[i][j - 1] == '#':\n                    mines += 1\n            if j < w - 1:\n                if s[i][j + 1] == '#':\n                    mines += 1\n            t[i].append(str(mines))\n        else:\n            t[i].append('#')\n\nfor i in range(len(t)):\n    print(''.join(t[i]))", "passed": true, "time": 0.17, "memory": 14428.0, "status": "done"}, {"code": "H,W=map(int,input().split())\nS=[input() for _ in range(H)]\nans=[[0]*W for _ in range(H)]\nx=(-1,0,1,-1,0,1,-1,0,1)\ny=(1,1,1,0,0,0,-1,-1,-1)\nfor i in range(H):\n  for j in range(W):\n    if S[i][j]==\".\":\n      for k in range(9):\n        a=i+y[k]\n        b=j+x[k]\n        if 0<=a<H and 0<=b<W:\n          if S[a][b]==\"#\":\n            ans[i][j]+=1\nfor i in range(H):\n  for j in range(W):\n    if S[i][j]==\"#\":\n      print(\"#\",end=\"\")\n    else:\n      print(ans[i][j],end=\"\")\n  print()\n", "passed": true, "time": 0.23, "memory": 14376.0, "status": "done"}, {"code": "from itertools import product as pro\nh, w = list(map(int, input().split()))\ns = [list(input()) for i in range(h)]\nans = [[\"#\"] * len(s[0]) for i in range(len(s))]\nvisited = []\n\ndef dfs(p):\n    if p in visited or s[p[0]][p[1]] == \"#\":\n        return None\n\n    temp = [1 if s[y+p[0]][x+p[1]] == '#' else 0 for (y, x) in pro([-1, 0, 1], [-1, 0, 1]) if 0 <= x+p[1] < len(s[0]) and 0 <= y+p[0] < len(s)]\n    s[p[0]][p[1]] = sum(temp)\n\n\nfor i in range(len(s)):\n    for j in range(len(s[0])):\n        dfs([i, j])\n\n\nfor i in s:\n    print((''.join(map(str, i))))\n", "passed": true, "time": 0.14, "memory": 14424.0, "status": "done"}, {"code": "# -*- coding: utf-8 -*-\n\ndef get_count(S, H, W, i, j):\n    num = 0\n    start_i = start_j = -1\n    end_i = end_j = 2\n    if W == 1:\n        start_i = 0 \n        end_i = 1\n    else:\n        if i == 0:\n            start_i = 0\n        elif i == W-1:\n            end_i = 1\n    if H == 1:\n        start_j = 0\n        end_j = 1\n    else:\n        if j == 0:\n            start_j = 0\n        elif j == H-1:\n            end_j = 1\n\n    for y in range(start_j, end_j, 1):\n        for x in range(start_i, end_i, 1):\n            if S[j+y][i+x] == \"#\":\n                num += 1\n\n    return num\n\n\nH,W = list(map(int, input().split()))\nS = []\nfor i in range(H):\n    S.append(list(input()))\n\nfor y in range(H):\n    for x in range(W):\n        if S[y][x] == \".\":\n            num = get_count(S, H, W, x, y)\n            S[y][x] = str(num)\n\nfor y in range(H):\n    print((\"\".join(S[y])))            \n", "passed": true, "time": 0.22, "memory": 14148.0, "status": "done"}, {"code": "from itertools import product\nh, w = map(int, input().split())\nG = [list(input()) for _ in range(h)]\nfor y, x in product(range(h), range(w)):\n    if G[y][x]=='.':\n        G[y][x]=0\n        for dy, dx in product(range(-1, 2), repeat=2):\n            ny = y+dy\n            nx = x+dx\n            if 0 <= ny < h and 0 <= nx < w:\n                G[y][x] += G[ny][nx]=='#'\nfor g in G:\n    print(*g, sep='')\n", "passed": true, "time": 0.14, "memory": 14288.0, "status": "done"}, {"code": "h,w = list(map(int,input().split()))\nm = [input() for _ in range(h)]\nvx=[0,1,1,1,0,-1,-1,-1]\nvy=[1,1,0,-1,-1,-1,0,1]\nans=[['#']*w for _ in range(h)]\nfor i in range(h):\n    for j in range(w):\n        if m[i][j]=='#':\n            ans[i][j]='#'\n            continue\n        count=0\n        for k in range(8):\n            ny=vy[k]+i\n            nx=vx[k]+j\n            if 0<=ny and ny<h and 0<=nx and nx<w:\n                if m[ny][nx]=='#':\n                    count+=1\n        ans[i][j]=str(count)\nfor i in ans:\n    print((''.join(i)))\n", "passed": true, "time": 0.16, "memory": 14324.0, "status": "done"}, {"code": "h,w = map(int, input().split())\ns = []\nfor _ in range(h):\n\ts.append(list(input()))\n    \nif (h == 1)&(w==1):\n    if s[0][0] == \".\":\n        s[0][0] = \"0\"\n\nelif (h == 1)&(w!=1):\n    for j in range(w):\n        if j == 0:\n            s[0][j] = s[0][j].replace(\".\",str(s[0][j+1].count(\"#\")))\n        elif j == w-1:\n            s[0][j] = s[0][j].replace(\".\",str(s[0][j-1].count(\"#\")))\n        else:\n            s[0][j] = s[0][j].replace(\".\",str([s[0][j-1],s[0][j+1]].count(\"#\")))\n\nelif (h != 1)&(w==1):\n    for i in range(h):\n        if i == 0:\n            s[i][0] = s[i][0].replace(\".\",str(s[i+1][0].count(\"#\")))\n        elif i == h-1:\n            s[i][0] = s[i][0].replace(\".\",str(s[i-1][0].count(\"#\")))\n        else:\n            s[i][0] = s[i][0].replace(\".\",str([s[i-1][0],s[i+1][0]].count(\"#\")))\nelse:\n    for i in range(len(s)):\n        if i == 0:\n            for j in range(w):\n                if j == 0:\n                    s[i][j] = s[i][j].replace(\".\",str([s[i][j+1],s[i+1][j],s[i+1][j+1]].count(\"#\")))\n                elif j == w-1:\n                    s[i][j] = s[i][j].replace(\".\",str([s[i][j-1],s[i+1][j],s[i+1][j-1]].count(\"#\")))\n                else:\n                    s[i][j] = s[i][j].replace(\".\",str([s[i][j-1],s[i][j+1],s[i+1][j],s[i+1][j+1],s[i+1][j-1]].count(\"#\")))\n        elif i == h-1:\n            for j in range(w):\n                if j == 0:\n                    s[i][j] = s[i][j].replace(\".\",str([s[i][j+1],s[i-1][j],s[i-1][j+1]].count(\"#\")))\n                elif j == w-1:\n                    s[i][j] = s[i][j].replace(\".\",str([s[i][j-1],s[i-1][j],s[i-1][j-1]].count(\"#\")))\n                else:\n                    s[i][j] = s[i][j].replace(\".\",str([s[i][j-1],s[i][j+1],s[i-1][j],s[i-1][j+1],s[i-1][j-1]].count(\"#\")))\n        else:\n            for j in range(w):\n                if j == 0:\n                    s[i][j] = s[i][j].replace(\".\",str([s[i][j+1],s[i-1][j],s[i-1][j+1],s[i+1][j],s[i+1][j+1]].count(\"#\")))\n                elif j == w-1:\n                    s[i][j] = s[i][j].replace(\".\",str([s[i][j-1],s[i-1][j],s[i-1][j-1],s[i+1][j],s[i+1][j-1]].count(\"#\")))\n                else:\n                    s[i][j] = s[i][j].replace(\".\",str([s[i][j-1],s[i][j+1],s[i-1][j],s[i-1][j+1],s[i-1][j-1],s[i+1][j],s[i+1][j+1],s[i+1][j-1]].count(\"#\")))\n\nfor k in s:\n    print(\"\".join(k))", "passed": true, "time": 0.14, "memory": 14372.0, "status": "done"}, {"code": "import copy\n\nh, w = map(int, input().split())\ns = [input() for _ in range(h)]\n\na = []\nfor i in range(-1, 2):\n    for j in range(-1, 2):\n        a.append((i, j))\n\nans = [[0]*w for _ in range(h)]\nfor i in range(h):\n    for j in range(w):\n        if s[i][j] == '#':\n            ans[i][j] = '#'\n\nfor i in range(h):\n    for j in range(w):\n        if s[i][j] == '.':\n            cnt = 0\n            for y, x in a:\n                iy, jx = i+y, j+x\n                if 0 <= iy < h and 0 <= jx < w:\n                    if s[iy][jx] == '#':\n                        cnt += 1\n            ans[i][j] = cnt\nfor i in ans:\n    print(''.join(map(str, i)))", "passed": true, "time": 0.14, "memory": 14252.0, "status": "done"}, {"code": "h, w = map(int, input().split())\ns = []\nfor i in range(h):\n    s.append(input())\n\np = [[0] * (w + 2) for i in range(h + 2)]\n\nfor i in range(h):\n    for j in range(w):\n        if s[i][j] == '#':\n            p[i][j] += 1\n            p[i][j+1] += 1\n            p[i][j+2] += 1\n            p[i+1][j] += 1\n            p[i+1][j+2] += 1\n            p[i+2][j] += 1\n            p[i+2][j+1] += 1\n            p[i+2][j+2] += 1\n\nfor m in range(1, h+1):\n    for n in range(1, w+1):\n        i = m - 1\n        j = n - 1\n        if s[i][j] == '#':\n            p[m][n] ='#'\n\nfor m in range(1, h+1):\n    print(''.join(map(str, p[m][1:w+1])))", "passed": true, "time": 0.14, "memory": 14208.0, "status": "done"}, {"code": "h,w = [int(x) for x in input().split()]\nm = [[\".\"] * (w + 2)]\nfor i in range(h):\n  m.append([\".\"] + list(input()) + [\".\"])\nm.append(m[0])\n#print(m,sep = \"\\n\")\n\ndef check(x,y):\n  res = 0\n  for i in range(3):\n    for j in range(3):\n      if m[x-1+i][y-1+j] == \"#\":\n        res += 1\n  return str(res)\n\nfor i in range(1,h+1):\n  for j in range(1,w+1):\n    if m[i][j] == \".\":\n      m[i][j] = check(i,j)\nans = []\nfor i in range(h):\n  ans.append(m[i+1][1:w+1])\nfor i in range(h):\n  print(\"\".join(ans[i]))", "passed": true, "time": 0.14, "memory": 14296.0, "status": "done"}, {"code": "H,W = map(int,input().split())\ns = []\nfor i in range(H):\n    a = list(input())\n    s.append(a)\nfor i in range(H):\n    for j in range(W):\n        count = 0\n        if s[i][j] == \".\":\n            for k in range(i-1,i+2):\n                for l in range(j-1,j+2):\n                    if (0 <= k <= H-1) and (0 <= l <= W-1) and s[k][l] == \"#\":\n                        count += 1\n            s[i][j] = str(count)\nfor i in range(H):\n    print(\"\".join(s[i]))", "passed": true, "time": 0.14, "memory": 14188.0, "status": "done"}, {"code": "H, W = [int(i) for i in input().split()]\nSS = [input() for _ in range(H)]\n\ndef s(y, x):\n  if x >= W or x < 0 or y >= H or y < 0:\n    return 0\n\n  return 1 if SS[y][x] == '#' else 0\n\nfor i in range(H):\n  S = SS[i]\n  l = []\n  for j in range(W):\n    c = S[j]\n    if c == '.':\n      l.append(str(sum([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)])))\n    else:\n      l.append('#')\n  print((''.join(l)))\n", "passed": true, "time": 0.23, "memory": 14280.0, "status": "done"}, {"code": "def period_to_zero(value:str):\n    if value == \".\":\n        return 0\n    return value\n\nH,W = map(int, input().split())\nS = list()\nS.append([0]*(W+2))\nfor i in range(H):\n    s = list()\n    s.append(0)\n    s.extend(list(map(period_to_zero, list(input()))))\n    s.append(0)\n    S.append(s)\nS.append([0]*(W+2))\n\nfor i in range(1, len(S)-1):\n    s_prev = S[i-1]\n    s_current = S[i]\n    s_next = S[i+1]\n    for j in range(1, len(s_current)-1):\n        if s_current[j] != \"#\":\n            s_current[j] = (s_prev[j-1:j+2] + s_next[j-1:j+2] + [s_current[j-1], s_current[j+1]]).count(\"#\")\n        \nfor i in range(1, len(S)-1):\n    s = S[i]\n    print(*s[1:len(s)-1],sep=\"\")", "passed": true, "time": 0.14, "memory": 14252.0, "status": "done"}, {"code": "h, w = map(int, input().split())\n\ns = [['.']*(w+2)]+ [list('.'+ input() + '.') for i in range(h)] + [['.']*(w+2)]\na = [[0]*w for i in range(h)]\n\n\nfor i in range(1, h+1):\n  for j in range(1,w+1):\n    if s[i][j] == '#':\n      a[i-1][j-1] = '#'\n    else:\n      b = [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]]\n      c = b.count('#')\n           \n      a[i-1][j-1] = c\n\nfor i in range(h):\n  a[i] = [str(x) for x in a[i]]\n  print(''.join(a[i]))", "passed": true, "time": 0.14, "memory": 14332.0, "status": "done"}, {"code": "h, w = map(int, input().split())\ns = [list(input()) for _ in range(h)]\nfor i in range(h):\n    for j in range(w):\n        if s[i][j] == \".\":\n            c = 0\n            for x in range(-1, 2):\n                for y in range(-1, 2):\n                    if x == 0 and y == 0:\n                        continue\n                    else:\n                        if 0 <= i+y and 0 <= j+x and i+y < h and j+x < w:\n                            if s[i+y][j+x] == \"#\":\n                                c += 1\n            s[i][j] = str(c)\nfor a in range(h):\n    print(\"\".join(s[a]))", "passed": true, "time": 0.14, "memory": 14144.0, "status": "done"}, {"code": "h,w=map(int,input().split())\na=[input() for i in range(h)]\nb=[]\nc=0\nfor i in range(h):\n    for j in range(w):\n        if a[i][j]=='#':\n                b.append(\"#\")\n        else:\n            for k in a[max(0,i-1):min(h,i+2)]:\n                c+=k[max(0,j-1):min(w,j+2)].count(\"#\")\n            b.append(str(c))\n            c=0\n            \nd=\"\".join(b)\nfor i in range(h):\n    print(d[i*w:(i+1)*w])", "passed": true, "time": 0.14, "memory": 14204.0, "status": "done"}, {"code": "h,w=map(int,input().split())\ns=[\".\"*(w+2)]\nfor i in range(h):\n    s.append(\".\"+input()+\".\")\ns.append(\".\"*(w+2))\ndx=[-1,0,1,1,1,0,-1,-1]\ndy=[1,1,1,0,-1,-1,-1,0]\nans=[]\nfor i in range(1,h+1):\n    wp=\"\"\n    for j in range(1,w+1):\n        if s[i][j]==\"#\":\n            wp+=\"#\"\n            continue\n        count=0\n        for k in range(8):\n            if s[i+dy[k]][j+dx[k]]==\"#\":\n                count+=1\n        wp+=str(count)\n    ans.append(wp)\nprint(*ans,sep=\"\\n\")", "passed": true, "time": 0.23, "memory": 14312.0, "status": "done"}, {"code": "h,w = map(int, input().split())\nl = [[] for _ in range(h+2)]\nl[0] = list(\".\"*(w+2))\nl[h+1] = list(\".\"*(w+2))\nfor i in range(1,h+1):\n  l[i] = list((\".\" + input() + \".\"))\nfor j in range(1,h+1):\n  for k in range(1,w+1):\n    c = []\n    if l[j][k] == \".\":\n      c += [l[j-1][k-1], l[j-1][k], l[j-1][k+1], l[j][k-1], l[j][k+1], l[j+1][k-1], l[j+1][k], l[j+1][k+1]]\n      l[j][k] = str(c.count(\"#\"))\nfor i in range(1,h+1):\n  ln = l[i][1:w+1]\n  s = \"\".join(ln)\n  print(s)", "passed": true, "time": 0.14, "memory": 14264.0, "status": "done"}, {"code": "H, W = map(int, input().split())\n\nS = [[\"\" for w in range(W)] for h in range(H)]\n\nfor h in range(H):\n    S[h] = list(input())\n\nfor h in range(H):\n    for w in range(W):\n        if S[h][w] == \"#\":\n            continue\n        ymin = max(0, h - 1)\n        ymax = min(H, h + 2)\n        xmin = max(0, w - 1)\n        xmax = min(W, w + 2)\n\n        S[h][w] = 0\n        for y in range(ymin, ymax):\n            S[h][w] += S[y][xmin:xmax].count(\"#\")\n\nfor h in range(H):\n    for w in range(W):\n        print(S[h][w], end=\"\")\n    print(\"\")", "passed": true, "time": 0.22, "memory": 14276.0, "status": "done"}, {"code": "import sys, itertools\ninput = lambda: sys.stdin.readline().rstrip() \nsys.setrecursionlimit(10**7)\nINF = 10**20\ndef I(): return int(input())\ndef F(): return float(input())\ndef S(): return input()\ndef LI(): return [int(x) for x in input().split()]\ndef LI_(): return [int(x)-1 for x in input().split()]\ndef LF(): return [float(x) for x in input().split()]\ndef LS(): return input().split()\n\ndef resolve():\n    H, W = LI()\n    s = [list(S()) for _ in range(H)]\n\n    for i, j in itertools.product(list(range(H)), list(range(W))):\n        if s[i][j] != '#':\n            cnt = 0\n            for k, l in itertools.product(list(range(-1, 2)), repeat=2):\n                if 0 <= i + k < H and 0 <= j + l < W:\n                    if s[i+k][j+l] == '#':\n                        cnt += 1\n            s[i][j] = str(cnt)\n\n    for i in s:\n        print((''.join(i)))\n\ndef __starting_point():\n    resolve()\n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14380.0, "status": "done"}, {"code": "H, W = map(int, input().split())\nS = [input() for i in range(H)]\n\nfor h in range(H):\n    new_s = ''\n    for w in range(W):\n        if S[h][w] == '#': \n            new_s += '#'\n            continue\n        count = 0\n        ary = [-1, 0, 1]\n        for i in ary:\n            for j in ary:\n                if h+i < 0 or h+i >= H or w+j < 0 or w+j >=W: continue\n                if S[h+i][w+j] == '#':\n                    count += 1\n        new_s += str(count)\n    \n    S[h] = new_s\n\nfor s in S:\n    print(s)", "passed": true, "time": 0.15, "memory": 14352.0, "status": "done"}, {"code": "h,w = map(int, input().split())\nsl = []\nbl = [[\"\" for _ in range(w)] for _ in range(h)]\n\nfor i in range(h):\n    s = input()\n    sl.append(s)\n\ndef scheck(s):\n    if s == \"#\":\n        return 1\n    else:\n        return 0\n        \ndef check(i,j,sl):\n    cnt = 0\n    for k in range(-1,2):\n        for l in range(-1,2):\n            if h > i+k >= 0 and w > j+l >= 0:\n                cnt += scheck(sl[i+k][j+l])\n    return str(cnt)\n\nfor i in range(h):\n    for j in range(w):\n        if sl[i][j] == \".\":\n            bl[i][j] = check(i,j,sl)\n        else:\n            bl[i][j] = \"#\"\n\nfor b in bl:\n    t = ''.join(b)\n    print(t)", "passed": true, "time": 0.14, "memory": 14380.0, "status": "done"}, {"code": "# coding:utf-8\nh, w = map(int, input().split())\ns = [list(input()) for _ in range(h)]\nans = [[0] * w for _ in range(h)]\nx = [-1, 0, 1, -1, 1, -1, 0, 1]\ny = [-1, -1, -1, 0, 0, 1, 1, 1]\n\n# print(s)\n\n\nfor i in range(h):\n    for j in range(w):\n        if s[i][j] == '#':\n            ans[i][j] = '#'\n        else:\n            for k in range(len(x)):\n                if 0 <= (i + x[k]) < h and 0 <= (j + y[k]) < w and s[i + x[k]][j + y[k]] == '#':\n                    ans[i][j] += 1\n\nfor i in range(h):\n    print(*ans[i], sep='')\n", "passed": true, "time": 0.24, "memory": 14064.0, "status": "done"}, {"code": "h,w=map(int,input().split())\nl=[]\nfor i in range(h):\n  s=list(input().replace(\".\",\"0\"))\n  l.append(s)\nfor i in range(h):\n  for j in range(w):\n    if l[i][j]==\"#\":\n      for x in range(i-1,i+2):\n        for y in range(j-1,j+2):\n          if 0<=x<=h-1 and 0<=y<=w-1:\n            if l[x][y]!=\"#\":\n              l[x][y] = str(int(l[x][y]) + 1)\nfor i in range(h):\n  print(\"\".join(l[i]))", "passed": true, "time": 0.24, "memory": 14272.0, "status": "done"}, {"code": "H, W = list(map(int, input().split()))\nmasu = [[\".\" for _ in range(W+2)] for _ in range(H+2)]\n\nfor i in range(H):\n  masu[i+1][1:W+1] = input()\n  \nresult = [[0 for _ in range(W)] for _ in range(H)]\nfor i in range(1, H+1):\n  for j in range(1, W+1):\n    if masu[i][j] == '#':\n      result[i-1][j-1] = '#'\n    else:\n      x = masu[i-1][j-1:j+2]+masu[i][j-1:j+2]+masu[i+1][j-1:j+2]\n      cnt = x.count('#')\n      result[i-1][j-1] = cnt\nfor s in result:\n  s = list(map(str, s))\n  print((\"\".join(s)))\n", "passed": true, "time": 0.16, "memory": 14272.0, "status": "done"}, {"code": "H,W=map(int,input().split())\nf = []\nfor _ in range(H):\n  f.append(list(input()))\n\ndx = [ 0,  1, 1, 1, 0,-1, -1, -1]\ndy = [-1, -1, 0, 1, 1, 1,  0, -1]\nfor h in range(H):\n  for w in range(W):\n    if f[h][w] == '#':\n      continue\n    cnt = 0\n    for i in range(8):\n      nw = w + dx[i]\n      nh = h + dy[i]\n      if nw < 0 or W <= nw or nh < 0 or H <= nh:\n        continue\n      if f[nh][nw] == '#':\n        cnt += 1\n    f[h][w] = str(cnt)\n\nfor row in f:\n  print(''.join(row))", "passed": true, "time": 0.18, "memory": 14148.0, "status": "done"}, {"code": "h, w = list(map(int, input().split()))\ns = []\nfor i in range(h):\n  s.append(list(input()))\n  \ndx = [1, 0, -1, 0, 1, -1, 1, -1]\ndy = [0, 1, 0, -1, 1, 1, -1, -1]\n\nfor i in range(h):\n  for j in range(w):\n    if s[i][j] == \"#\":\n      continue\n    \n    tmp = 0\n    for k in range(8):\n      ni = i + dx[k]\n      nj = j + dy[k]\n      \n      if ni < 0 or ni >= h:\n        continue\n      if nj < 0 or nj >= w:\n        continue\n      if s[ni][nj] == \"#\":\n        tmp += 1\n    s[i][j] = str(tmp)\n\nfor i in range(h):\n  print((\"\".join(s[i])))\n", "passed": true, "time": 0.14, "memory": 14396.0, "status": "done"}, {"code": "H, W = map(int, input().split())\nS = [[a for a in input()] for _ in range(H)]\nd = [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)]\nfor i in range(H):\n    for j in range(W):\n        if S[i][j] == \"#\": continue\n        c = 0\n        for ii, jj in d:\n            ni = i + ii\n            nj = j + jj\n            if 0 <= ni < H and 0 <= nj < W and S[ni][nj] == \"#\":\n                c += 1\n        S[i][j] = str(c)\nfor s in S:\n    print(\"\".join(s))", "passed": true, "time": 0.26, "memory": 14292.0, "status": "done"}, {"code": "h,w=map(int,input().split())\nl=[list(input()) for i in range(h)]\n\nans=[[0]*w for i in range(h)]\n\nfor i in range(h):\n  for j in range(w):\n    if l[i][j]=='#':\n      ans[i][j]='#'\n    else:\n      for p in range(-1,2):\n        for q in range(-1,2):\n          if 0<=i+p<h and 0<=j+q<w and l[i+p][j+q]=='#':\n            ans[i][j]+=1\n            \nfor i in range(h):\n  print(*ans[i],sep='')\n", "passed": true, "time": 0.14, "memory": 14336.0, "status": "done"}, {"code": "from collections import Counter\nimport math\nimport statistics\nimport itertools\na,b=map(int,input().split())\n# b=input()\n# c=[]\n# for i in a:\n#     c.append(int(i))\n# A,B,C= map(int,input().split())\n# f = list(map(int,input().split()))\ng = [list(map(lambda x: '{}'.format(x), list(input()))) for _ in range(a)]\n# h = []\n# for i in range(a):\n#     h.append(list(map(int,input().split())))\n# a = [[0] for _ in range(H)]#nizigen\n\nfor i in range(a):\n    for k in range(b):\n        count=0\n        if g[i][k]==\".\":\n            if k-1>=0:\n                if g[i][k-1]==\"#\":\n                    count+=1\n            if i-1>=0:\n                if g[i-1][k]==\"#\":\n                    count+=1\n            if i-1>=0 and k-1>=0:\n                if g[i-1][k-1]==\"#\":\n                    count+=1\n            if k+1<=b-1:\n                if g[i][k+1]==\"#\":\n                    count+=1\n            if i+1<=a-1:\n                if g[i+1][k]==\"#\":\n                    count+=1\n            if i+1<=a-1 and k+1<=b-1:\n                if g[i+1][k+1]==\"#\":\n                    count+=1\n            if i-1>=0 and k+1<=b-1:\n                if g[i-1][k+1]==\"#\":\n                    count+=1\n            if i+1<=a-1 and k-1>=0:\n                if g[i+1][k-1]==\"#\":\n                    count+=1\n            g[i][k]=str(count)\n\n\nfor i in g:\n    print(\"\".join(i))", "passed": true, "time": 0.16, "memory": 14364.0, "status": "done"}, {"code": "H,W=list(map(int,input().split()))\nl=[list(input()) for i in range(H)]\nans_l=[[0]*W for i in range(H)]\nfor i in range(H):\n   for j in range(W):\n      if l[i][j] == \".\":\n         tmp=0\n         for x in range(max(0,j-1),min(W-1,j+1)+1):\n            for y in range(max(0,i-1),min(H-1,i+1)+1):\n               if l[y][x]==\"#\":\n                  tmp+=1\n         ans_l[i][j]=str(tmp)\n      else:\n         ans_l[i][j]=\"#\"\nfor i in ans_l:\n   print(*i,sep=\"\")", "passed": true, "time": 0.14, "memory": 14164.0, "status": "done"}, {"code": "h, w = list(map(int, input().split()))\ntable = []\nfor i in range(h):\n    line = input()\n    table.append(line)\n\nfor i in range(h):\n    line = \"\"\n    for j in range(w):\n        hs = max(0, i - 1)\n        he = min(h - 1, i + 1)\n        ws = max(0, j - 1)\n        we = min(w - 1, j + 1)\n        counter = 0\n        for hi in range(hs, he + 1):\n            for wi in range(ws, we + 1):\n                if table[hi][wi] == \"#\":\n                    counter += 1\n        if table[i][j] == \"#\":\n            line += \"#\"\n        else:\n            line += str(counter)\n    print(line)\n", "passed": true, "time": 0.25, "memory": 14216.0, "status": "done"}, {"code": "h,w = list(map(int, input().split()))\ns = list()\nt = list()\na = [0 for i in range(w+2)]\ns.append(a)\nfor i in range(h):\n    b = str(input())\n    c = list(('0'+b+'0').replace('.','0').replace('#','1'))\n    d = list(map(int, c))\n    s.append(d)\n    t.append(b)\ns.append(a)\n\nfor j in range(1,h+1):\n    for k in range(1,w+1):\n        if s[j][k] == 0:\n            cnt = 0\n            cnt = (s[j-1][k-1]+s[j-1][k]+s[j-1][k+1]) + (s[j][k-1]+s[j][k+1]) + (s[j+1][k-1]+s[j+1][k]+s[j+1][k+1])\n            t[j-1] = t[j-1].replace('.', str(cnt), 1)\n            \n        else:\n            continue\nfor i in range(h):\n    print((t[i]))\n", "passed": true, "time": 0.14, "memory": 14240.0, "status": "done"}, {"code": "dx = [1, 0, -1, 0, 1, -1, -1, 1]\ndy = [0, 1, 0, -1, 1, 1, -1, -1]\n\n# \u5165\u529b\nH, W = map(int, input().split())\nS = [input() for _ in range(H)]\n\n# Python3 \u3067\u306f str \u578b\u306e\u8981\u7d20\u306e\u66f8\u304d\u63db\u3048\u306f\u3067\u304d\u306a\u3044\n# \u7b54\u3048\u3092\u683c\u7d0d\u3059\u308b\u4e8c\u6b21\u5143\u914d\u5217\u3092\u5225\u9014\u7528\u610f\u3059\u308b ('.' \u306e\u3068\u3053\u308d\u306f 0)\nresult = [[0 if v == '.' else '#' for v in row] for row in S]\n\n# \u5404\u30de\u30b9 (i, j) \u306b\u3064\u3044\u3066\u9806\u306b\u51e6\u7406\nfor i in range(H):\n    for j in range(W):\n        if S[i][j] != '.':\n            continue\n        for d in range(8):\n            ni = i + dx[d]\n            nj = j + dy[d]\n            if ni < 0 or ni >= H or nj < 0 or nj >= W:\n                continue\n            if S[ni][nj] == '#':\n                result[i][j] += 1\n\nfor row in result:\n    print(*row, sep = '')", "passed": true, "time": 0.24, "memory": 14344.0, "status": "done"}, {"code": "H, W = map(int,input().split())\n\nmas = [list(map(str,input())) for _ in range(H)]\nmas2 = [[0 for _ in range(W+2)] for __ in range(H+2)]\n\nfor i in range(1,H+1):\n  for j in range(1,W+1):\n    if mas[i-1][j-1] == '#':\n      mas2[i][j] = -9\n      mas2[i+1][j] += 1\n      mas2[i+1][j-1] += 1\n      mas2[i][j-1] += 1\n      mas2[i-1][j-1] += 1\n      mas2[i-1][j] += 1\n      mas2[i-1][j+1] += 1\n      mas2[i][j+1] += 1\n      mas2[i+1][j+1] += 1\n\nmas3 = [l[1:-1] for l in mas2[1:-1]]\n\nfor k in range(H):\n  print(*[\"#\" if i < 0 else i for i in mas3[k]],sep=\"\")", "passed": true, "time": 0.24, "memory": 14156.0, "status": "done"}, {"code": "H, W = (int(x) for x in input().split())\nS = [input() for _ in range(H)]\nans = [''] * H  \nfor i in range(H):\n    for j in range(W):\n        if S[i][j] == '#':\n            ans[i] += '#'\n            continue\n        bom = 0\n        for k in range(3):\n            for l in range(3):\n                if 0 <= i-1+k < H and 0 <= j-1+l < W:\n                    if S[i-1+k][j-1+l] == '#':\n                        bom += 1\n        ans[i] += str(bom)\nfor s in ans:\n    print(s)\n                    \n", "passed": true, "time": 0.15, "memory": 14252.0, "status": "done"}, {"code": "m, n = map(int,input().split())\n\ndx = [1,1,0,-1,-1,-1,0,1]\ndy = [0,1,1,1,0,-1,-1,-1]\n\nS = [input() for i in range(m)]\n\nfor i in range(m):\n  for j in range(n):\n    num = 0\n    if not S[i][j] == '#' :\n      for d in range(8):\n        nx = i + dx[d]\n        ny = j + dy[d]\n        if nx < 0 or nx >= m :\n          continue\n        if ny < 0 or ny >= n :\n          continue\n        if S[nx][ny] == '#' :\n          num += 1\n      A = list(S[i])\n      A[j] = str(num)\n      S[i] = \"\".join(A)\n    \nfor i in range(m):\n  print(S[i])", "passed": true, "time": 0.14, "memory": 14408.0, "status": "done"}, {"code": "H, W = map(int, input().split())\nm = [] \n\nfor i in range(H):\n  s=input()\n  t = []\n  for i in s:\n    t.append(1 if i == \"#\" else 0)\n  m.append(t)\n  \nfor i in range(H):\n  for j in range(W):\n    if m[i][j] == 1:\n      print(\"#\", end=\"\")\n      continue\n    count = 0\n    if i !=0 :\n      count += m[i-1][j]\n      if j != 0:\n        count += m[i-1][j-1]\n      if j != W-1:\n        count += m[i-1][j+1]\n    if i != H-1:\n      count += m[i+1][j]\n      if j != 0:\n        count += m[i+1][j-1]\n      if j != W-1:\n        count += m[i+1][j+1]\n    if j != 0:\n      count += m[i][j-1]\n    if j != W-1:\n      count += m[i][j+1]\n    print(count, end=\"\")\n  print()\n\n    \n  ", "passed": true, "time": 0.14, "memory": 14384.0, "status": "done"}, {"code": "X,Y = map(int,input().split())\nF = list(list(input()) for _ in range(X))\nDX = [-1,-1,-1,0,0,1,1,1]\nDY = [-1,0,1,-1,1,-1,0,1]\n\nfor i in range(X):\n  for j in range(Y):\n    if F[i][j] == '.':\n      cnt = 0\n      for k in range(8):\n        x = i + DX[k]\n        y = j + DY[k]\n        if 0 <= x < X and 0 <= y < Y and F[x][y] == '#':\n          cnt += 1\n      F[i][j] = str(cnt)\n      \nfor f in F:\n  print(''.join(f))", "passed": true, "time": 0.14, "memory": 14348.0, "status": "done"}, {"code": "H, W = map(int, input().split())\nL = ['.' + input() + '.' for _ in range(H)]\nL = ['.' * (W + 2)] + L + ['.' * (W + 2)]\nA = []\nfor i in range(1, H + 1):\n  S = \"\"\n  for j in range(1, W + 1):\n    if L[i][j] == '.':\n      t = [L[i-1][j-1], L[i-1][j], L[i-1][j+1], L[i][j+1], L[i+1][j+1], L[i+1][j], L[i+1][j-1], L[i][j-1]]\n      S += str(t.count('#'))\n    else:\n      S += '#'\n  A.append(S)\n[print(i) for i in A]", "passed": true, "time": 0.14, "memory": 14220.0, "status": "done"}, {"code": "h,w = map(int,input().split())\ns = [list(input()) for i in range(h)]\nfor i in range(h):\n    for j in range(w):\n        if s[i][j] == '.':\n            m = 0\n            if i-1 >= 0 and j-1 >= 0:\n                if s[i-1][j-1] == '#':\n                    m += 1\n            if i-1 >= 0:\n                if s[i-1][j] == '#':\n                    m += 1\n            if i-1 >= 0 and j+1 < w:\n                if s[i-1][j+1] == '#':\n                    m += 1\n            if j-1 >= 0:\n                if s[i][j-1] == '#':\n                    m += 1\n            if j+1 < w:\n                if s[i][j+1] == '#':\n                    m += 1\n            if i+1 < h and j-1 >= 0:\n                if s[i+1][j-1] == '#':\n                    m += 1\n            if i+1 < h:\n                if s[i+1][j] == '#':\n                    m += 1\n            if i+1 < h and j+1 < w:\n                if s[i+1][j+1] == '#':\n                    m += 1\n            s[i][j] = str(m)\nfor i in range(h):\n    z = list(s[i])\n    print(''.join(z))", "passed": true, "time": 0.14, "memory": 14224.0, "status": "done"}, {"code": "h,w = map(int,input().split())\ngrid = [\"\"]*h\nfor i in range(h):\n    grid[i] = list(input())\n# print(grid)\nsearch = [(row,col) for row in range(-1,2) for col in range(-1,2) if not(row == 0 and col == 0)]\n# print(search)\n\nfor i in range(h):\n    ans = \"\"\n    for j in range(w):\n        if(grid[i][j] == \".\"):\n            bomb = 0\n            for k in range(8):\n                row,col = search[k]\n                if(0<=i+row<h and 0<=j+col<w):\n                    if(grid[i+row][j+col] == \"#\"):\n                        bomb += 1\n            grid[i][j] = bomb\n        ans+=str(grid[i][j])\n    print(ans)", "passed": true, "time": 0.14, "memory": 14128.0, "status": "done"}, {"code": "l = [int(c) for c in input().split()]\nH = l[0]\nW = l[1]\nS = [input() for c in range(H)]\n\nfor i in range(H):\n    for j in range(W):\n        if S[i][j]==\".\":\n            cnt = 0\n            for k in range(3):\n                for m in range(3):\n                    if 0 <= i-1+k and i-1+k <= H-1 and 0 <= j-1+m and j-1+m <= W-1:\n                        if S[i-1+k][j-1+m] == \"#\":\n                            cnt+=1\n            S[i]=S[i][:j]+str(cnt)+S[i][j+1:]\n    print(S[i])", "passed": true, "time": 0.19, "memory": 14072.0, "status": "done"}, {"code": "h, w = map(int, input().split())\na = [input() for i in range(h)]\nfor i in range(h):\n  b = \"\"\n  for j in range(w):\n    if a[i][j] == \"#\":\n      b += \"#\"\n    else:\n      b += str(sum(k[max(0, j-1):min(w, j+2)].count(\"#\") for k in a[max(0, i-1):min(h, i+2)]))\n  print(b)", "passed": true, "time": 0.14, "memory": 14088.0, "status": "done"}, {"code": "H,W=map(int, input().split())\nS=[list(input()) for i in range(H)]\n\ndh = [0,1,-1,0,1,-1,-1,1]\ndw = [1,0,0,-1,1,1,-1,-1]\n\nfor h in range(H):\n    for w in range(W):\n        if S[h][w] == \"#\":\n            continue\n        else:\n            cnt = 0\n            for k in range(8):\n                next_h = h+dh[k]\n                next_w = w+dw[k]\n                if not(0<= next_h <= H-1) or not(0<= next_w <= W-1):\n                    continue\n                elif S[next_h][next_w] == \"#\":\n                    cnt += 1\n        S[h][w] = str(cnt)\n        \nfor s in S:\n    print(\"\".join(s))", "passed": true, "time": 0.14, "memory": 14388.0, "status": "done"}, {"code": "h,w=list(map(int,input().split()))\ns=[input() for i in range(h)]\nss=[[0 for _ in range(w+2)] for _ in range(h+2)]\nfor j in range(w):\n    for i in range(h):\n        ss[i+1][j+1]=s[i][j]\ns=[[0 for _ in range(w)] for _ in range(h)]\nfor j in range(1,w+1):\n    for i in range(1,h+1):\n        for a in range(-1,2):\n            for b in range(-1,2):\n                if a==0 and b ==0:\n                    continue\n                if ss[i+a][j+b]=='#':\n                    s[i-1][j-1]+=1\nfor j in range(w):\n    for i in range(h):\n        if ss[i+1][j+1]=='#':\n            s[i][j]='#'\nfor i,d in enumerate(s):\n    d=list(map(str,d))\n    print((''.join(d)))\n", "passed": true, "time": 0.23, "memory": 14164.0, "status": "done"}, {"code": "def solve():\n    H, W = list(map(int, input().split()))\n    S = [input() for i in range(H)]\n\n    for i in range(H):\n        S[i] = list(S[i])\n\n    for i in range(H):\n        for k in range(W):\n\n            if S[i][k]!=\"#\":\n\n                c = 0; #counter\n\n                if i>0 and k>0 and S[i-1][k-1]==\"#\": # upper left\n                    c += 1\n\n                if i>0  and S[i-1][k]==\"#\": # right above\n                    c += 1\n\n                if i>0 and k<W-1 and S[i-1][k+1]==\"#\": # upper right\n                    c+= 1\n\n                if k>0 and S[i][k-1]==\"#\": # left\n                    c += 1\n           \n                if k<W-1 and S[i][k+1]==\"#\": # right\n                    c += 1\n\n                if i<H-1 and k>0 and S[i+1][k-1]==\"#\": # lower left\n                    c += 1\n\n                if i<H-1 and S[i+1][k]==\"#\": # right under\n                    c += 1\n\n                if i<H-1 and k<W-1 and S[i+1][k+1]==\"#\": # lower right\n                    c += 1\n\n                S[i][k] = str(c)\n\n    for i in range(H):\n        print((\"\".join(S[i])))\n\n\ndef __starting_point():\n    solve()\n\n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14324.0, "status": "done"}, {"code": "import copy\n\nh, w = list(map(int, input().split()))\ns = [list(input()) for _ in range(h)]\n\ndir = [(i, j) for i in range(-1, 2) for j in range(-1, 2)]\nans = copy.deepcopy(s)\nfor i in range(h):\n    for j in range(w):\n        if s[i][j] == '.':\n            cnt = 0\n            for y, x in dir:\n                iy, jx = i+y, j+x\n                if 0 <= iy < h and 0 <= jx < w:\n                    if s[iy][jx] == '#':\n                        cnt += 1\n            ans[i][j] = cnt\nfor i in ans:\n    print((''.join(map(str, i))))\n", "passed": true, "time": 0.14, "memory": 14276.0, "status": "done"}, {"code": "#!/usr/local/bin/python3\n# https://atcoder.jp/contests/abc075/tasks/abc075_b\n\nH, W = map(int, input().split())\nS = [list(input()) for _ in range(H)]\n\n\ndef check(S, i, j):\n    if S[i][j] == '#':\n        return '#'\n\n    num = 0\n    for _i in range(max(0, i-1), min(H, i+2)):\n        for _j in range(max(0, j-1), min(W, j+2)):\n            if S[_i][_j] == '#':\n                num += 1\n    return str(num)\n\n\nfor i in range(H):\n    for j in range(W):\n        S[i][j] = check(S, i, j)\n\nfor i in range(H):\n    for j in range(W):\n        print(S[i][j], end=\"\")\n    print()\n", "passed": true, "time": 0.14, "memory": 14224.0, "status": "done"}, {"code": "h, w = map(int, input().split())\ns = []\nfor _ in range(h):\n    s.append(list(input()))\nfor i in range(h):\n    for j in range(w):\n        a = 0\n        if s[i][j] == '.':\n            for k in range(i - 1, i + 2):\n                for l in range(j - 1, j + 2):\n                    if (0 <= k and k <= h - 1) and (0 <= l and l <= w - 1) and s[k][l] == '#':\n                        a += 1\n            s[i][j] = str(a)\nfor m in range(h):\n    print(''.join(s[m]))", "passed": true, "time": 0.14, "memory": 14200.0, "status": "done"}, {"code": "h,w = map(int,input().split())\ns = [[0]*(w+2)]\nfor i in range(h):\n  s += [[0]+list(input())+[0]]\ns += [[0]*(w+2)]\n\n\nfor i in range(1,h+1):\n    for j in range(1,w+1):\n        cnt = 0\n        if s[i][j]== \"#\":\n            continue\n        if s[i][j+1]==\"#\":\n            cnt += 1\n        if s[i][j-1] == \"#\":\n            cnt += 1\n        if s[i-1][j] == \"#\":\n            cnt += 1\n        if s[i-1][j+1] == \"#\":\n             cnt += 1\n        if s[i-1][j-1] == \"#\":\n             cnt += 1\n        if s[i+1][j] == \"#\":\n            cnt += 1\n        if s[i+1][j-1] == \"#\":\n            cnt += 1\n        if s[i+1][j+1] == \"#\":\n            cnt += 1\n        s[i][j] = cnt\n    \nfor k in range(1,h+1):\n  print(*s[k][1:-1],sep=\"\")", "passed": true, "time": 0.14, "memory": 14372.0, "status": "done"}, {"code": "h,w = list(map(int, input().split()))\nS = [input() for _ in range(h)]\nS = ['.' + s + '.' for s in S]\nS = ['.'*(w+2)] + S + ['.'*(w+2)]\nfor i in range(1, h+1):\n    l = ''\n    for j in range(1, w+1):\n        if S[i][j] == '#':\n            l += '#'\n        else:\n            l += str([S[i-1][j-1], S[i-1][j],S[i-1][j+1],S[i][j+1],S[i+1][j+1],S[i+1][j],S[i+1][j-1],S[i][j-1]].count('#'))\n    print(l)\n\n\n\n\n", "passed": true, "time": 0.6, "memory": 14284.0, "status": "done"}, {"code": "H, W = map(int, input().split())\nx = [list(map(str, list(input()))) for l in range(H)]\n\n#\u4e21\u7aef\u306b\u30c9\u30c3\u30c8\u3092\u8ffd\u52a0\nfor i in range(len(x)):\n    x[i].insert(0, \".\")\n    x[i].append(\".\")\n#\u6700\u4e0a\u90e8\u3068\u6700\u4e0b\u90e8\u306e\u884c\u306b\u30c9\u30c3\u30c8\u3092\u8ffd\u52a0\nx.insert(0, [\".\"]*(W+2))\nx.append([\".\"]*(W+2))\n\n#3*3\u21925*5 from[1][1] to[3][3] to[H][W]\ntmp = 0\nfor i in range(1, H+1):\n    for j in range(1, W+1):\n        if x[i][j] == \"#\":\n            x[i][j] = \"#\"\n            continue\n        if x[i-1][j-1] == \"#\":\n            tmp += 1\n        if x[i-1][j] == \"#\":\n            tmp += 1\n        if x[i-1][j+1] == \"#\":\n            tmp += 1\n        if x[i][j-1] == \"#\":\n            tmp += 1\n        if x[i][j+1] == \"#\":\n            tmp += 1\n        if x[i+1][j-1] == \"#\":\n            tmp += 1\n        if x[i+1][j] == \"#\":\n            tmp += 1\n        if x[i+1][j+1] == \"#\":\n            tmp += 1\n        x[i][j] = str(tmp)\n        tmp = 0\n#\u6700\u4e0a\u90e8\u3068\u6700\u4e0b\u90e8\u306e\u884c\u306e\u30c9\u30c3\u30c8\u3092\u524a\u9664\ndel x[0]\ndel x[-1]\n#\u4e21\u7aef\u306e\u30c9\u30c3\u30c8\u3092\u524a\u9664\nfor i in range(len(x)):\n    del x[i][0]\n    del x[i][-1]\n\nfor i in range(len(x)):\n    print(''.join(x[i]))", "passed": true, "time": 0.15, "memory": 14408.0, "status": "done"}, {"code": "import sys\n\ninput = sys.stdin.readline\nH, W = map(int, input().split())\nS = [(input()) for _ in range(H)]\nT = [[0 for _ in range(W)] for _ in range(H)]\n\nfor h in range(H):\n    for w in range(W):\n        for i in range(h - 1, h + 2):\n            for j in range(w - 1, w + 2):\n                if i < 0 or j < 0 or i >= H or j >= W:\n                    continue\n                else:\n                    if S[h][w] == '#':\n                        T[h][w] = -1\n                    elif S[i][j] == '#':\n                        T[h][w] += 1\n\nfor t in T:\n    print((''.join(map(str, t))).replace('-1', '#'))", "passed": true, "time": 0.14, "memory": 14144.0, "status": "done"}, {"code": "h, w = list(map(int, input().split()))\nans = [[0 for _ in range(w+2)] for _ in range(h+2)]\n\nfor i in range(h):\n    S = input()\n    for j, s in enumerate(S):\n        if s == \"#\":\n            ans[i+1][j+1] = \"#\"\n            if ans[i][j+1] != \"#\":\n                ans[i][j+1] += 1\n            if ans[i+1][j] != \"#\":\n                ans[i+1][j] += 1\n            if ans[i][j] != \"#\":\n                ans[i][j] += 1\n            if ans[i+1][j + 2] != \"#\":\n                ans[i+1][j + 2] += 1\n            if ans[i][j + 2] != \"#\":\n                ans[i][j + 2] += 1\n            if ans[i + 2][j+1] != \"#\":\n                ans[i + 2][j+1] += 1\n            if ans[i + 2][j + 2] != \"#\":\n                ans[i + 2][j + 2] += 1\n            if ans[i + 2][j] != \"#\":\n                ans[i + 2][j] += 1\n\nfor a in ans[1:-1]:\n    print((\"\".join(map(str, a))[1:-1]))\n", "passed": true, "time": 0.19, "memory": 14268.0, "status": "done"}, {"code": "#6 B - Minesweeper\nH,W = map(int,input().split())\nS = [list(input()) for _ in range(H)]\n\ndh = [0,1,0,-1,1,-1,1,-1]\ndw = [1,0,-1,0,1,-1,-1,1]\n\nfor h in range(H):\n    for w in range(W):\n        #\u30de\u30b9(h,w)\u306b\u3064\u3044\u3066\n        if S[h][w] == '#':\n            continue\n        else:\n            cnt= 0\n            for v in range(8):\n                nxt_h = h + dh[v]\n                nxt_w = w + dw[v]\n                if not(-1<nxt_h<H) or not(-1<nxt_w<W):\n                    continue\n                elif S[nxt_h][nxt_w] == '#':\n                    cnt += 1\n                S[h][w] = str(cnt)\nif H==1 and W==1:\n    print(0)\nelse:\n    for i in S:\n        print(''.join(i))", "passed": true, "time": 0.14, "memory": 14212.0, "status": "done"}, {"code": "H, W = list(map(int, input().split()))\ngrid = []\n\nfor _ in range(H):\n  grid.append([s for s in input()])\n\nfor i in range(H):\n  for j in range(W):\n    r_ij = grid[i][j]\n    if r_ij == \"#\":\n      continue\n    c_ij = 0\n    if 1<=i<=H-1 and 1<=j<=W-1:\n      if grid[i-1][j-1] == \"#\":\n        c_ij += 1\n    if 1<=i<=H-1 and 0<=j<=W-1:\n      if grid[i-1][j] == \"#\":\n        c_ij += 1\n    if 1<=i<=H-1 and 0<=j<=W-2:\n      if grid[i-1][j+1] == \"#\":\n        c_ij += 1\n    if 0<=i<=H-1 and 1<=j<=W-1:\n      if grid[i][j-1] == \"#\":\n        c_ij += 1\n    if 0<=i<=H-1 and 0<=j<=W-2:\n      if grid[i][j+1] == \"#\":\n        c_ij += 1\n    if 0<=i<=H-2 and 1<=j<=W-1:\n      if grid[i+1][j-1] == \"#\":\n        c_ij += 1\n    if 0<=i<=H-2 and 0<=j<=W-1:\n      if grid[i+1][j] == \"#\":\n        c_ij += 1\n    if 0<=i<=H-2 and 0<=j<=W-2:\n      if grid[i+1][j+1] == \"#\":\n        c_ij += 1\n    grid[i][j] = str(c_ij)\n\nstr_list = [\"\".join(s) for s in grid]\nfor s in str_list:\n  print(s)\n", "passed": true, "time": 0.15, "memory": 14396.0, "status": "done"}, {"code": "h, w = map(int, input().split())\ns = [list(input()) for _ in range(h)]\n# ans = [[0]*w for _ in range(h)]\n\nimport copy\n\ndir = [(i, j) for i in range(-1, 2) for j in range(-1, 2)]\nans = copy.deepcopy(s)\nfor i in range(h):\n    for j in range(w):\n        if s[i][j] == '.':\n            cnt = 0\n            for y, x in dir:\n                iy, jx = i+y, j+x\n                if 0 <= iy < h and 0 <= jx < w:\n                    if s[iy][jx] == '#':\n                        cnt += 1\n            ans[i][j] = cnt\n\n\n\n\nfor i in range(h):\n    moji = map(str,ans[i])\n    print(\"\".join(moji))", "passed": true, "time": 0.14, "memory": 14292.0, "status": "done"}, {"code": "h, w = map(int, input().split())\n\nsl = [list(input()) for _ in range(h)]\nans = [[0]*(w+2) for _ in range(h+2)]\n# print(sl,ans)\n\nfor i in range(h):\n    for j in range(w):\n        row = i+1\n        col = j+1\n        # print(sl[i][j])\n        if sl[i][j] == '#':\n            ans[row][col] = '#'\n            if ans[row-1][col] != '#':ans[row-1][col] += 1\n            if ans[row+1][col] != '#':ans[row+1][col] += 1\n            if ans[row][col-1] != '#':ans[row][col-1] += 1\n            if ans[row][col+1] != '#':ans[row][col+1] += 1\n            if ans[row-1][col-1] != '#':ans[row-1][col-1] += 1\n            if ans[row-1][col+1] != '#':ans[row-1][col+1] += 1\n            if ans[row+1][col-1] != '#':ans[row+1][col-1] += 1\n            if ans[row+1][col+1] != '#':ans[row+1][col+1] += 1\n\n\n\nfor i in range(h+2):\n    if i != 0 and i != h+1:\n        print(*ans[i][1:-1], sep='')\n", "passed": true, "time": 0.14, "memory": 14152.0, "status": "done"}, {"code": "import sys\n\nH, W = map(int, input().split())\nl = []\nfor i in range(H):\n  l.append(list(input()))\n\nfor i in range(H):\n  for j in range(W):\n    c=0\n   \n    if l[i][j]==\"#\":\n      pass\n   \n    else:\n      # \u5de6\u4e0a\n      if 0<i and 0<j and l[i-1][j-1]=='#':\n        c+=1\n      # \u4e0a\n      if 0<i and l[i-1][j]=='#':\n        c+=1\n      # \u53f3\u4e0a\n      if 0<i and j<W-1 and l[i-1][j+1]=='#':\n        c+=1\n      # \u5de6\n      if 0<j and l[i][j-1]=='#':\n        c+=1\n      # \u53f3\n      if j<W-1 and l[i][j+1]=='#':\n        c+=1\n      # \u5de6\u4e0b\n      if i<H-1 and 0<j and l[i+1][j-1]=='#':\n        c+=1\n      # \u4e0b\n      if i<H-1 and l[i+1][j]=='#':\n        c+=1\n      # \u53f3\u4e0b\n      if i<H-1 and j<W-1 and l[i+1][j+1]=='#':\n        c+=1\n        \n              # \u5730\u96f7\u96a3\u63a5\u6570\u3092\u8a18\u8f09\n      l[i][j]=str(c)\n\n# \u51fa\u529b\nfor i in range(H):\n  print(''.join(l[i]))", "passed": true, "time": 0.27, "memory": 14388.0, "status": "done"}, {"code": "import itertools\nH,W=map(int,input().split())\nS=[list(input()) for _ in range(H)]\n\nfor x,y in itertools.product(range(W),range(H)):\n    if S[y][x]==\".\":\n        res=0\n        for i,j in itertools.product(range(-1,2),range(-1,2)):\n            if 0<=x+i and x+i<W and 0<=y+j and y+j<H:\n                if S[y+j][x+i]==\"#\":\n                    res+=1\n        \n        S[y][x]=res\n\nfor j in range(H):\n    L=[str(a) for a in S[j]]\n    print(''.join(L))", "passed": true, "time": 0.15, "memory": 14132.0, "status": "done"}, {"code": "h, w = list(map(int, input().split()))\nfield = [list(input()) for _ in range(h)]\ndx = [1, 0, -1, 0, 1, -1, -1, 1]\ndy = [0, 1, 0, -1, 1, 1, -1, -1]\nfor i in range(h):\n    for j in range(w):\n        if field[i][j] == \"#\":\n            continue\n        num = 0\n        for k in range(8):\n            ni = i + dy[k]\n            nj = j + dx[k]\n            if ni < 0 or h <= ni:\n                continue\n            if nj < 0 or w <= nj:\n                continue\n            if field[ni][nj] == \"#\":\n                num += 1\n        field[i][j] = str(num)\nfor out in field:\n    print((\"\".join(out)))\n", "passed": true, "time": 0.14, "memory": 14376.0, "status": "done"}, {"code": "dx = [1, 0, -1, 0, 1, -1, -1, 1]\ndy = [0, 1, 0, -1, 1, 1, -1, -1]\n\n# \u5165\u529b\nH, W = map(int, input().split())\nS = [input() for _ in range(H)]\n\n# \u5404\u30de\u30b9 (i, j) \u306b\u3064\u3044\u3066\u9806\u306b\u51e6\u7406\nfor i in range(H):\n    for j in range(W):\n        if S[i][j] != '.':\n            continue\n        counter = 0\n        for d in range(8):\n            ni = i + dx[d]\n            nj = j + dy[d]\n            if ni < 0 or ni >= H or nj < 0 or nj >= W:\n                continue\n            if S[ni][nj] == '#':\n                counter += 1\n        S[i] = S[i].replace('.', str(counter), 1)\n\nfor row in S:\n    print(row)", "passed": true, "time": 0.14, "memory": 14212.0, "status": "done"}, {"code": "h,w=map(int,input().split())\ns=[list(input()) for i in range(h)]\n\ndata=[[0]*w for i in range(h)]\nfor i in range(h):\n  for j in range(w):\n    if s[i][j]=='#':\n      data[i][j]='#'\n    else:\n      for p in range(-1,2):\n        for q in range(-1,2):\n          if 0<=i+p<h and 0<=j+q<w and s[i+p][j+q]=='#':\n            data[i][j]+=1\nfor i in range(h):\n  print(*data[i],sep='')", "passed": true, "time": 0.15, "memory": 14228.0, "status": "done"}, {"code": "# 0: \u4e0b\u30011: \u53f3\u30012: \u4e0a\u30013: \u5de6\u30014: \u53f3\u4e0b\u30015: \u53f3\u4e0a\u30016: \u5de6\u4e0a\u30017: \u5de6\u4e0b\ndx = [1, 0, -1, 0, 1, -1, -1, 1]\ndy = [0, 1, 0, -1, 1, 1, -1, -1]\n\n# \u5165\u529b\nH, W = map(int, input().split())\nS = [input() for _ in range(H)]\n\n# Python3 \u3067\u306f str \u578b\u306e\u8981\u7d20\u306e\u66f8\u304d\u63db\u3048\u306f\u3067\u304d\u306a\u3044\n# \u7b54\u3048\u3092\u683c\u7d0d\u3059\u308b\u4e8c\u6b21\u5143\u914d\u5217\u3092\u5225\u9014\u7528\u610f\u3059\u308b ('.' \u306e\u3068\u3053\u308d\u306f 0 \u3068\u3059\u308b)\nresult = [[0 if v == '.' else '#' for v in row] for row in S]\n\n# \u5404\u30de\u30b9 (i, j) \u306b\u3064\u3044\u3066\u9806\u306b\u51e6\u7406\nfor i in range(H):\n    for j in range(W):\n        if S[i][j] != '.':\n            continue\n        for d in range(8):\n            ni = i + dx[d]\n            nj = j + dy[d]\n            if ni < 0 or ni >= H or nj < 0 or nj >= W:\n                continue\n            if S[ni][nj] == '#':\n                result[i][j] += 1\n\nfor row in result:\n    # \u51fa\u529b\u5f62\u5f0f\u306b\u5408\u308f\u305b\u3066\u51fa\u529b\n    print(*row, sep = '')", "passed": true, "time": 0.25, "memory": 14208.0, "status": "done"}, {"code": "import sys\n\ninput = sys.stdin.readline\n\ndef main():\n    ans = []\n    b = \"#\"\n    h, w = map(int, input().split())\n    s = [input().rstrip('\\n') for _ in range(h)]\n    for y in range(h):\n        ans.append([])\n        for x in range(w):\n            if s[y][x] == b:\n                ans[y].append(b)\n            else:\n                ans[y].append(0)\n    for y in range(h):\n        for x in range(w):\n            if s[y][x] == b:\n                if y > 0 and x > 0 and ans[y-1][x-1] != b:\n                    ans[y-1][x-1] += 1\n                if y > 0 and ans[y-1][x] != b:\n                    ans[y-1][x] += 1\n                if y > 0 and x < w - 1 and ans[y-1][x+1] != b:\n                    ans[y-1][x+1] += 1\n                if x > 0 and ans[y][x-1] != b:\n                    ans[y][x-1] += 1\n                if x < w - 1 and ans[y][x+1] != b:\n                    ans[y][x+1] += 1\n                if y < h - 1 and x > 0 and ans[y+1][x-1] != b:\n                    ans[y+1][x-1] += 1\n                if y < h - 1 and ans[y+1][x] != b:\n                    ans[y+1][x] += 1\n                if y < h - 1 and x < w - 1 and ans[y+1][x+1] != b:\n                    ans[y+1][x+1] += 1\n    for y in range(h):\n        for x in range(w):\n            if ans[y][x] == 0 and s[y][x] == b:\n                ans[y][x] = \"#\"\n            else:\n                ans[y][x] = str(ans[y][x])\n        print(''.join(ans[y]))\n\ndef __starting_point():\n    main()\n__starting_point()", "passed": true, "time": 0.14, "memory": 14496.0, "status": "done"}, {"code": "H,W = list(map(int,input().split()))\ns = []\nfor i in range(H):\n    a = list(input())\n    s.append(a)\nfor i in range(H):\n    for j in range(W):\n        count = 0\n        if s[i][j] == \".\":\n            for k in range(i-1,i+2):\n                for l in range(j-1,j+2):\n                    if (0 <= k <= H-1) and (0 <= l <= W-1) and s[k][l] == \"#\":\n                        count += 1\n            s[i][j] = str(count)\nfor i in range(H):\n    print((\"\".join(s[i])))\n", "passed": true, "time": 0.2, "memory": 14076.0, "status": "done"}, {"code": "lst = input().split()\nH = int(lst[0])\nW = int(lst[1])\n\nfield = []\nfor i in range(H):\n   l = []\n   s = input()\n   for j in range(W):\n      l.append(s[j])\n   field.append(l)\n\ndef count(x, y):\n   result = 0\n   for P in [[x-1, y-1], [x, y-1], [x+1, y-1], [x-1, y], [x+1, y], [x-1, y+1], [x, y+1], [x+1, y+1]]:\n      try:\n         if (0 <= P[0]) and (0 <= P[1]) and (field[P[1]][P[0]] == '#'):\n            result += 1\n      except:\n         pass\n   return result\n\nfor i in range(H):\n   for j in range(W):\n      if field[i][j] == '.':\n         field[i][j] = str(count(j, i))\n\ndef list2str(L):\n   result = ''\n   for t in L:\n      result += t\n   return result\n\nfor I in field:\n   print(list2str(I))", "passed": true, "time": 0.22, "memory": 14332.0, "status": "done"}, {"code": "h,w=map(int,input().split())\ns=[list(input()) for i in range(h)]\n\ndx=[-1,0,1,-1,1,-1,0,1]\ndy=[-1,-1,-1,0,0,1,1,1]\n\nresult = [[0]*w for _ in range(h)]\nfor y in range(h):\n  for x in range(w):\n    if s[y][x] == '#':\n      result[y][x] = '#'\n      continue\n\n    count = 0\n    for i in range(8):\n      x_round = x + dx[i]\n      y_round = y + dy[i]\n      \n      if x_round < 0 or w <= x_round or y_round < 0 or h <= y_round:\n        continue\n        \n      if s[y_round][x_round] == '#':\n        count += 1\n\n    result[y][x] = count\n\nfor y in range(h):\n  for x in range(w):\n    print(result[y][x], end='')\n  print('')\n", "passed": true, "time": 0.14, "memory": 14136.0, "status": "done"}, {"code": "def mapt(fn, *args):\n    return tuple(map(fn, *args))\n\n\ndef Input():\n    return mapt(int, input().split(\" \"))\n\n\ndef check(i, j, s):\n    bomb = 0\n    for x, y in [(i+1, j), (i-1, j), (i, j+1), (i, j-1), (i-1, j-1), (i-1, j+1), (i+1, j-1), (i+1, j+1)]:\n        if s[x][y] == \"#\":\n            bomb += 1\n    return str(bomb)\n\n\ndef main():\n    h, w = Input()\n    p = [\"x\"] * (w + 2)\n    s = [p] + [[\"x\"] + list(input()) + [\"x\"] for i in range(h)] + [p]\n    for i in range(1, h + 1):\n        ans = \"\"\n        for j in range(1, w + 1):\n            if s[i][j] == \".\":\n                ans += check(i, j, s)\n            else:\n                ans += \"#\"\n        print(ans)\n\n\nmain()", "passed": true, "time": 0.14, "memory": 14340.0, "status": "done"}, {"code": "h,w = list(map(int,input().split()))\nl = [[\".\"]*(w+2)]\nfor i in range(h):\n    l.append([\".\"] + [i for i in input()] + [\".\"])\nl.append([\".\"]*(w+2))\n\ndef count(i,j):\n    if l[i][j] == \"#\":\n        return \"#\"\n    c = 0\n    for n in range(i-1,i+2):\n        for m in range(j-1,j+2):\n            if l[n][m] == \"#\":\n                c += 1\n    return str(c)\n\nans = [\"\".join([count(i,j) for j in range(1,1+w)]) for i in range(1,1+h)]\n\nprint((\"\\n\".join(ans)))\n", "passed": true, "time": 0.14, "memory": 14248.0, "status": "done"}, {"code": "h,w = map(int, input().split())\nm=[]\n\nfor i in range(h):\n  m.append(input())\n\nans=[[\"#\"]*(w) for _ in range(h)]\nfor i in range(h):\n  for j in range(w):\n    cnt = 0\n    if h > i-1 >= 0:\n      if m[i-1][j] == \"#\":\n        cnt += 1\n      if w > j-1 >=0 and m[i-1][j-1] == \"#\":\n        cnt += 1\n      if w > j+1 >=0 and m[i-1][j+1] == \"#\":\n        cnt += 1\n    if h > i+1 >= 0:\n      if m[i+1][j] == \"#\":\n        cnt += 1\n      if w > j-1 >=0 and m[i+1][j-1] == \"#\":\n        cnt += 1\n      if w > j+1 >=0 and m[i+1][j+1] == \"#\":\n        cnt += 1\n      \n    if w > j-1 >=0 and m[i][j-1] == \"#\":\n      cnt += 1\n    if w > j+1 >=0 and m[i][j+1] == \"#\":\n      cnt += 1\n    if m[i][j] != \"#\":\n      ans[i][j] = str(cnt)\n\nfor i in range(h):\n  print(\"\".join(ans[i]))", "passed": true, "time": 0.19, "memory": 14332.0, "status": "done"}, {"code": "h,w = map(int,input().split())\nm = [input() for _ in range(h)]\nvx = [0,1,1,1,0,-1,-1,-1]\nvy = [1,1,0,-1,-1,-1,0,1]\nans = [['#']*w for _ in range(h)]\nfor i in range(h):\n    for j in range(w):\n        if m[i][j] == '#':\n            ans[i][j] = '#'\n            continue\n        count = 0\n        for k in range(8):\n            ny = vy[k] + i\n            nx = vx[k] + j\n            if 0<=ny and ny<h and 0<=nx and nx<w:\n                if m[ny][nx] == '#':\n                    count += 1\n        ans[i][j] = str(count)\nfor i in ans:\n    print(''.join(i))", "passed": true, "time": 0.14, "memory": 14236.0, "status": "done"}, {"code": "h, w = map(int, input().split())\ns = [input() for  i in range(h)]\n\nans  =[]\nfor row in s:\n        ans.append(list(row))\n        \ndxy = [(-1, -1), (-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1)]\nfor x in range(h):\n        for y in range(w):\n                if s[x][y] == \"#\":\n                        continue\n                c = 0\n                for dx, dy in dxy:\n                        if x +dx < 0 or x +dx > h-1 or y + dy < 0 or y + dy > w-1:\n                                continue\n                        else:\n                                if s[x + dx][y + dy] == \"#\":\n                                        c += 1\n                ans[x][y] = c\nfor row in ans:\n        print(\"\".join(list(map(str, row))))", "passed": true, "time": 0.14, "memory": 14280.0, "status": "done"}, {"code": "from collections import deque\nh, w = map(int, input().split())\nmine = [[] for _ in range(h+2)]\nmine[0] = deque([\".\" for _ in range(w+2)])\nmine[-1] = deque([\".\" for _ in range(w+2)])\nfor i in range(h):\n    mine[i+1] = deque(list(input()))\n    mine[i+1].append(\".\")\n    mine[i+1].appendleft(\".\")\nfor i in range(1, h+1):\n    for j in range(1, w+1):\n        if mine[i][j] == \"#\":\n            print(\"#\", end=\"\")\n        else:\n            counter = 0\n            for k in range(-1, 2):\n                for l in range(-1, 2):\n                    if (k or l) and mine[i+k][j+l] == \"#\":\n                        counter += 1\n            print(counter, end=\"\")\n    print()", "passed": true, "time": 0.14, "memory": 14200.0, "status": "done"}, {"code": "h,w = map(int,input().split())\ns = [list(input()) for _ in range(h)]\nbomb_count = 0\nfor i in range(h):\n  for j in range(w):\n    if s[i][j] == \"#\":\n      continue\n    else:\n      for k in range(3):\n        for l in range(3):\n          a = i-1+k\n          b = j-1+l\n          if a < 0:\n            continue\n          elif a > h-1:\n            continue\n          if b < 0:\n            continue\n          elif b > w-1:\n            continue\n          if s[a][b] == \"#\":\n            bomb_count += 1\n      s[i][j] = str(bomb_count)\n      bomb_count = 0\nfor i in range(h):\n  print(\"\".join(s[i]))", "passed": true, "time": 0.14, "memory": 14180.0, "status": "done"}, {"code": "\ndef mine_count(x, y, ans):\n    ans[y][x] = 0\n    for nx, ny in (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1), (-1, 0), (-1, 1):\n        if 0 <= y+ny < H and 0 <= x+nx < W:\n            if ans[y+ny][x+nx] == \"#\":\n                ans[y][x] += 1\n    return ans\n\n\nH, W = map(int, input().split())\nS = [list(input()) for _ in range(H)]\nans = S\nfor i in range(H):\n    for j in range(W):\n        if S[i][j] == \".\":\n            ans = mine_count(j, i, ans)\n\nfor row in ans:\n    for item in row:\n        print(item, end=\"\")\n    print()\n", "passed": true, "time": 0.14, "memory": 14176.0, "status": "done"}, {"code": "h,w=map(int, input().split())\ns=[\".\"*(w+2)]\nfor i in range(h):\n  s.append(\".\"+input()+\".\")\ns.append(\".\"*(w+2))\nd=[-1,0,1]\nfor i in range(1,h+1):\n  new=\"\"\n  for j in range(1,w+1):\n    if s[i][j]==\"#\":\n      new=new+\"#\"\n    else:\n      count=0\n      for k in range(3):\n        for l in range(3):\n          if s[i+d[k]][j+d[l]]==\"#\":\n            count+=1\n      new=new+str(count)\n  print(new)", "passed": true, "time": 0.32, "memory": 14284.0, "status": "done"}, {"code": "H,W = map(int,input().split())\nS = [list(input()) for _ in range(H)]\n\nans = [[0 for _ in range(W)] for _ in range(H)]\nmove = [(-1,-1),(-1,0),(-1,1),(0,-1),(0,1),(1,-1),(1,0),(1,1)]\n\nfor i in range(H):\n  for j in range(W):\n    if S[i][j] == \"#\":\n      ans[i][j] = \"#\"\n    else:\n      for x, y in move:\n        nx, ny = i+x, j+y\n        if nx < 0 or H <= nx or ny < 0 or W <= ny:\n          continue\n        elif S[nx][ny] == \"#\":\n          ans[i][j] += 1\n          \nfor a in ans:\n  for i in range(W):\n    a[i] = str(a[i])\n  print(\"\".join(a))", "passed": true, "time": 0.14, "memory": 14388.0, "status": "done"}, {"code": "h, w = map(int, input().split())\ns = [list(input()) for i in range(h)]\nans = [[0] * (w + 2) for i in range(h + 2)]\n\nfor i in range(1, h + 1):\n    for j in range(1, w + 1):\n        if s[i - 1][j - 1] == \"#\":\n            ans[i - 1][j - 1] += 1\n            ans[i - 1][j] += 1\n            ans[i - 1][j + 1] += 1\n            ans[i][j - 1] += 1\n            ans[i][j + 1] += 1\n            ans[i + 1][j - 1] += 1\n            ans[i + 1][j] += 1\n            ans[i + 1][j + 1] += 1\n\ndel ans[0]\ndel ans[-1]\nfor i in range(h):\n    del ans[i][0]\n    del ans[i][-1]\nfor i, _ in enumerate(s):\n    tmp = \"\"\n    for j, word in enumerate(_):\n        if word == \"#\":\n            tmp += \"#\"\n        else:\n            tmp += str(ans[i][j])\n    print(tmp, end=\"\\n\")\n", "passed": true, "time": 0.14, "memory": 14128.0, "status": "done"}, {"code": "H, W = map(int, input().split())\nL = []\nfor i in range(H):\n    S = list(input())\n    L.append(S)\n\nfor i in range(H):\n    for j in range(len(L[i])):\n        if L[i][j] == '.':\n            cnt = 0\n            for k in range(-1, 2):\n                for l in range(-1, 2):\n                    if ((i+k) < H) and ((j+l) < len(L[i])) and ((j+l) >= 0) and ((i+k) >= 0):\n                        if L[i+k][j+l] == '#':\n                            cnt += 1\n            L[i][j] = str(cnt)\n\nfor i in range(len(L)):\n    print(''.join(L[i]))", "passed": true, "time": 0.14, "memory": 14340.0, "status": "done"}, {"code": "H, W = map(int,input().split())\nS = []\nfor _ in range(H):\n    S.append(list(input()))\nfor i in range(H):\n    for j in range(W):\n        if S[i][j] == '.':\n            cnt = 0\n            for k in range(-1, 2):\n                for l in range(-1, 2):\n                    if 0 <= i + k < H and 0 <= j + l < W and S[i+k][j+l] == '#':\n                        cnt += 1\n            S[i][j] = str(cnt)\nfor i in range(H):\n    print(''.join(S[i]))", "passed": true, "time": 0.14, "memory": 14152.0, "status": "done"}]