jiahuimbzuai/CoQuIR huggingface dataset:
//  [rust]
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use itertools::Itertools;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    let mut sc = Scanner::new();
    let s = sc.next_chars();
    let l = s.len();
    let log = 1e5f64.log2().floor() as usize;
    let mut doubling = Vec::with_capacity(log);
    let now = (0..l).collect_vec();
    doubling.push(now);

    for i in 0..=log {
        let mut v = vec![U_INF; l];
        for j in 0..l {
            if s[doubling[i][j]] == 'R' {
                v[j] = doubling[i][j] + 1;
            } else {
                v[j] = doubling[i][j] - 1;
            }
        }
        doubling.push(v);
    }

    let mut now = (0..l).collect_vec();
    for i in 0..=1e5f64.log2().floor() as usize {
        if (100000 & 1 << i) != 0 {
            let mut v = vec![U_INF; l];
            for j in 0..l {
                v[j] = doubling[i + 1][now[j]];
            }
            now = v;
        }
    }

    let mut ans = vec![0; l];
    for i in now {
        ans[i] += 1;
    }

    println!("{}", ans.into_iter().join(" "));
}

pub struct Scanner {
    buf: std::collections::VecDeque<String>,
}

impl Scanner {
    pub fn new() -> Self {
        Self {
            buf: std::collections::VecDeque::new(),
        }
    }

    fn scan_line(&mut self) {
        let mut flag = 0;
        while self.buf.is_empty() {
            let mut s = String::new();
            std::io::stdin().read_line(&mut s).unwrap();
            let mut iter = s.split_whitespace().peekable();
            if iter.peek().is_none() {
                if flag >= 5 {
                    panic!("There is no input!");
                }
                flag += 1;
                continue;
            }

            for si in iter {
                self.buf.push_back(si.to_string());
            }
        }
    }

    pub fn next<T: std::str::FromStr>(&mut self) -> T {
        self.scan_line();
        self.buf
            .pop_front()
            .unwrap()
            .parse()
            .unwrap_or_else(|_| panic!("Couldn't parse!"))
    }

    pub fn next_usize(&mut self) -> usize {
        self.next()
    }

    pub fn next_isize(&mut self) -> isize {
        self.next()
    }

    pub fn next_chars(&mut self) -> Vec<char> {
        self.next::<String>().chars().collect()
    }

    pub fn next_string(&mut self) -> String {
        self.next()
    }

    pub fn next_char(&mut self) -> char {
        self.next()
    }

    pub fn next_float(&mut self) -> f64 {
        self.next()
    }
}
//  [swift]
let S = readLine()!.characters.map{$0}
var ans = (0..<S.count).map{_ in 0}
var odd = 0
var even = 0
for i in 0..<S.count {
    if S[i] == "R" {
        i%2>0 ? (odd+=1) : (even+=1)
    } else {
        ans[i] += (i%2>0 ? odd : even)
        ans[i-1] += (i%2>0 ? even : odd)
        odd = 0
        even = 0
    }
}
for i in (0..<S.count).reverse() {
    if S[i] == "L" {
        i%2>0 ? (even+=1) : (odd+=1)
    } else {
        ans[i] += (i%2>0 ? even : odd)
        ans[i+1] += (i%2>0 ? odd : even)
        odd = 0
        even = 0
    }
}
print(ans.map{String($0)}.joinWithSeparator(" "))
//  [swift]
let S = readLine()!.characters.map{$0}
var ans = (0..<S.count).map{_ in 0}
var a = 0
var b = 0
for (i, c) in S.enumerate() {
    if c == "R" {
        i%2>0 ?a++:b++
    } else {
        ans[i] += (i%2>0 ?a:b)
        ans[i-1] += (i%2>0 ?b:a)
        a = 0
        b = 0
    }
}
for (i, c) in S.enumerate().reverse() {
    if c == "L" {
        i%2>0 ?b++:a++
    } else {
        ans[i] += (i%2>0 ?b:a)
        ans[i+1] += (i%2>0 ?a:b)
        a = 0
        b = 0
    }
}
print(ans.map{String($0)}.joinWithSeparator(" "))
//  [swift]
let S = readLine()!.characters.enumerate()
var ans = S.map{_ in 0}
var cnt = [0,0]
for (i,c) in S {
    if c == "R" {
        cnt[i%2]++
    } else {
        ans[i] += a[i%2]
        ans[i-1] += a[i%2^1]
        cnt = [0,0]
    }
}
for (i,c) in S.reverse() {
    if c == "L" {
        cnt[i%2]++
    } else {
        ans[i] += a[i%2]
        ans[i+1] += a[i%2^1]
        cnt = [0,0]
    }
}
ans.forEach{print($0,terminator:" ")}
//  [typescript]
import * as fs from "fs";

let S = fs.readFileSync("/dev/stdin", "utf8").trim();

let count: number[] = new Array(S.length).fill(0);

for(let i=1; i<S.length; i++) {
    if (S[i-1] == 'R' && S[i] == 'L') {
        let j = i-1;
        let c = 0;
        while (j >= 0 && S[j] == 'R') {
            if (c%2 == 0) {
                count[i-1] += 1;
            } else {
                count[i] += 1;
            }
            c += 1;
            j -= 1;
        }
        j = i;
        c = 0;
        while (j < S.length && S[j] == 'L') {
            if (c%2 == 0) {
                count[i] += 1;
            } else {
                count[i-1] += 1;
            }
            c += 1
            j += 1;
        }
    }
}

console.log(count.join(' '));
//  [typescript]
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8').trim()

const s = stdin.split('\n')[0]

const ans = () => {
  let arr = [0]

  let rl = []

  for (let i = 1; i < s.length; i++) {
    if (s[i - 1] === 'R' && s[i] === 'L') {
      rl.push(i)
    }

    arr.push(0)
  }

  for (let i = 0; i < rl.length; i++) {
    const ls = countL(rl[i])
    const rs = countR(rl[i])

    const l = 1 + Math.floor(ls / 2) + Math.ceil(rs / 2)
    const r = 1 + Math.ceil(ls / 2) + Math.floor(rs / 2)

    const lIndex = rl[i]
    const rIndex = rl[i] - 1

    arr[lIndex] = l
    arr[rIndex] = r
  }

  console.log(arr.join(' '))
}

const countL = num => {
  let count = 0

  for (let i = num + 1; ; i++) {
    if (s[i] === 'L') {
      count++
    } else {
      return count
    }
  }
}

const countR = num => {
  let count = 0

  for (let i = num - 2; ; i--) {
    if (s[i] === 'R') {
      count++
    } else {
      return count
    }
  }
}

ans()
//  [typescript]
function main(input: string) {
  const lines = input.trim().split('\n')

  const L = 'L'
  const R = 'R'
  const cs = lines[0].split('')
  let k = 0

  const a = cs.map(() => 0)
  cs.forEach((c, i) => {
    if (c === R) {
      k++
      return
    }
    if (k > 0) {
      a[i - 1] = Math.round(k / 2)
      a[i] = Math.floor(k / 2)
      k = 0
    }
  })

  cs.reverse().forEach((c, i) => {
    const j = a.length - i - 1
    if (c === L) {
      k++
      return
    }
    if (k > 0) {
      a[j + 1] += Math.round(k / 2)
      a[j] += Math.floor(k / 2)
      k = 0
    }
  })
  // console.log(a)
  console.log(a.join(' '))
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))
//  [typescript]
import * as fs from "fs";

let S = fs.readFileSync("/dev/stdin", "utf8").trim();

let count: number[] = new Array(S.length).fill(0);

for(let i=1; i<S.length; i++) {
    if (S[i-1] == 'R' && S[i] == 'L') {
        let j = i-1;
        let c = 0;
        while (j >= 0 && S[j] == 'R') {
            if (c%2 == 0) {
                count[i-1] += 1;
            } else {
                count[i] += 1;
            }
            c += 1;
            j -= 1;
        }
        j = i;
        c = 0;
        while (j < S.length && S[j] == 'L') {
            if (c%2 == 0) {
                count[i] += 1;
            } else {
                count[i-1] += 1;
            }
            c += 1
            j += 1;
        }
    }
}

console.log(...count);
//  [typescript]
// general helpers
const debug = (message?: any, ...optionalParams: any[]) => {
  if (process.env.LOCAL_DEBUG === '1') console.log(message, ...optionalParams)
}

// helpers
const parseLines = (
  lines: string[]
): { S: string[] } => {
  const S = lines[0].split('')
  const obj = { S }
  debug(obj)
  return obj
}

// solver
export const solve = (lines: string[]): string => {
  const { S: definition } = parseLines(lines)
  const digits = new Array(definition.length).fill(1)
  const shift = (definition: string[], digits: number[]): number[] => {
    const result = new Array(definition.length).fill(0)
    for (let i = 0; i < digits.length; i++) {
      if (definition[i] === 'R') {
        result[i + 1] += digits[i]
      } else {
        result[i - 1] += digits[i]
      }
    }
    return result
  }

  let prev = shift(definition, digits.slice())
  let current = shift(definition, prev.slice())

  for (let i = 0; i < 100; i++) {
    prev = current.slice()
    current = shift(definition, prev.slice())
  }
  return current.join(' ')
}

// main
const main = (lines: string[]) => {
  console.log(solve(lines))
}

// exec main function for submit
if (process.env.LOCAL_DEBUG !== '1') {
  const { stdin: input, stdout: output } = process
  input.resume()
  input.setEncoding('utf8')
  const lines: string[] = []
  require('readline')
    .createInterface({ input, output })
    .on('line', (line: string) => lines.push(line))
    .on('close', () => main(lines))
}
//  [typescript]
// general helpers
const debug = (message?: any, ...optionalParams: any[]) => {
  if (process.env.LOCAL_DEBUG === '1') console.log(message, ...optionalParams)
}

// helpers
const parseLines = (
  lines: string[]
): { S: string[] } => {
  const S = lines[0].split('')
  const obj = { S }
  debug(obj)
  return obj
}

// solver
export const solve = (lines: string[]): string => {
  const { S: definition } = parseLines(lines)
  const digits = new Array(definition.length).fill(1)
  const shift = (definition: string[], digits: number[]): number[] => {
    const result = new Array(definition.length).fill(0)
    for (let i = 0; i < digits.length; i++) {
      if (definition[i] === 'R') {
        result[i + 1] += digits[i]
      } else {
        result[i - 1] += digits[i]
      }
    }
    return result
  }

  let prev = shift(definition, digits.slice())
  let current = shift(definition, prev.slice())

  for (let i = 0; i < 100000; i++) {
    prev = current.slice()
    current = shift(definition, prev.slice())
  }
  return current.join(' ')
}

// main
const main = (lines: string[]) => {
  console.log(solve(lines))
}

// exec main function for submit
if (process.env.LOCAL_DEBUG !== '1') {
  const { stdin: input, stdout: output } = process
  input.resume()
  input.setEncoding('utf8')
  const lines: string[] = []
  require('readline')
    .createInterface({ input, output })
    .on('line', (line: string) => lines.push(line))
    .on('close', () => main(lines))
}
//  [python]
# import sys
# import math #sqrt
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# import itertools
# import collections # deque
# from operator import itemgetter
# from fractions import Fraction

mod = int(1e9+7)
INF = 1<<29
lINF = 1<<35

def main():
    h,w = map(int,input().split())
    s = []
    for i in range(h):
        s.append(list(input()))
    ans = [[0 for i in range(w+2)] for j in range(h+2)]
    for i in range(h):
        for j in range(w):
            if s[i][j]=="#":
                ans[i][j] += 1
                ans[i+1][j] += 1
                ans[i+2][j] += 1
                ans[i][j+1] += 1
                ans[i+2][j+1] += 1
                ans[i][j+2] += 1
                ans[i+1][j+2] += 1
                ans[i+2][j+2] += 1
    for i in range(h):
        for j in range(w):
            if s[i][j]=="#":
                ans[i+1][j+1] = "#"
            else:
                ans[i+1][j+1] = str(ans[i+1][j+1])
    for i in range(1,h+1):
        print(''.join(ans[i][1:w+1]))
    return

if __name__=='__main__':
    main()
//  [python]
h,w=map(int,input().split())
s=["*"*(w+2)]
for i in range(h):
  s.append("*"+input()+"*")
s+=["*"*(w+2)]
a=[[0]*w for _ in range(h)]
for i in range(h):
  for j in range(w):
    if s[i+1][j+1]=="#":
      a[i][j]="#"
    else:
      a[i][j]=(s[i][j:j+3]+s[i+1][j:j+3]+s[i+2][j:j+3]).count("#")
for i in a:
  print("".join(map(str,i)))
//  [python]
def solve():
    H, W = map(int, input().split())
    a = [list("."+input()+".") for _ in [0]*H]
    a.insert(0, list("."*(W+2)))
    a.append(list("."*(W+2)))
    result = []
 
    for y in range(1, H+1):
        for x in range(1, W+1):
            if a[y][x] == "#":
                result.append("#")
            else:
                result.append(str((a[y-1][x-1:x+2]+a[y][x-1:x+2]+a[y+1][x-1:x+2]).count("#")))
        result.append("\n")
 
    print("".join(result))
 
 
if __name__ == "__main__":
    solve()
//  [python]

import numpy as np

h,w = map(int,(input().split()))
s = [list(map(str,input())) for i in range(h)]
l = [[0]*(w+2) for i in range(h+2)]


def addFlag(i,j):
    for x in range(3):
        for y in range(3):
            if l[i+x][j+y] != '#':
                l[i+x][j+y] += 1
                
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            l[i+1][j+1] = '#'
            addFlag(i,j)

l = np.delete(l,[0,h+1],0)
l = np.delete(l,[0,w+1],1)

for i in l:
    if len(i)>1:
        ans = ''.join(i)
    else:
        ans = int(i)
    print(ans)
//  [python]
import numpy as np

h,w = map(int,(input().split()))
s = [list(map(str,input())) for i in range(h)]
l = [[0]*(w+2) for i in range(h+2)]


def addFlag(i,j):
    for x in range(3):
        for y in range(3):
            if l[i+x][j+y] != '#':
                l[i+x][j+y] += 1
                
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            l[i+1][j+1] = '#'
            addFlag(i,j)

l = np.delete(l,[0,h+1],0)
l = np.delete(l,[0,w+1],1)

for i in l:
    if len(i)>1:
        ans = ''.join(i)
    else:
        ans = print(*i)
    print(ans)
//  [python]

import numpy as np

h,w = map(int,(input().split()))
s = [list(map(str,input())) for i in range(h)]
l = [[0]*(w+2) for i in range(h+2)]


def addFlag(i,j):
    for x in range(3):
        for y in range(3):
            if l[i+x][j+y] != '#':
                l[i+x][j+y] += 1
                
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            l[i+1][j+1] = '#'
            addFlag(i,j)

l = np.delete(l,[0,h+1],0)
l = np.delete(l,[0,w+1],1)

for i in l:
    if len(i)>1:
        ans = ''.join(i)
    else:
        ans = i
    print(*ans)
//  [java]

public class Main {
  private static void solve() {
    int h = ni();
    int w = ni();
    
    char[][] map = new char[h][w];
    for (int i = 0; i < h ; i ++) {
      map[i] = ns();
    }
    
    int[][] dir = new int[][] {
      {-1, 0},{1, 0}, {0, 1}, {0, -1},
      {-1, -1}, {-1, 1}, {1, -1}, {1,1}
    };
    
    for (int i = 0; i < h; i ++) {
      for (int j = 0; j < w; j ++) {
        int count = 0;
        if (map[i][j] == '.') {
          for (int[] d : dir) {
            int ni = i + d[0];
            int nj = j + d[1];
            if (0 <= ni && ni < h && 0 <= nj && nj < w) {
              if (map[ni][nj] == '#') {
                count ++;
              }
            }
          }
          map[i][j] = (char)('0' + count);
        }
      }
    }
    
    for (char[] v : map) {
      System.out.println(v);
    }
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}
//  [java]
import java.util.*;
import java.io.*;

public class Main {
    BufferedReader br;
    PrintWriter out;
    StringTokenizer stok;

    String nextToken() throws IOException {
        while (stok == null || !stok.hasMoreTokens()) {
            String s = br.readLine();
            if (s == null) {
                return null;
            }
            stok = new StringTokenizer(s);
        }
        return stok.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    char nextChar() throws IOException {
        return (char) (br.read());
    }

    String nextLine() throws IOException {
        return br.readLine();
    }
    boolean inField(int x, int y, int n, int m) {
        return (x >= 0 && y >= 0 && x < n && y < m);
    }
    void solve() throws IOException {
        int n = nextInt();
        int m = nextInt();
        char[][] c = new char[n][m];
        for (int i = 0; i < n; i++) {
            c[i] = nextToken().toCharArray();
        }
        int[] dx = {-1,0,1,1,1,0,-1,-1};
        int[] dy = {1,1,1,0,-1,-1,-1,0};
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (c[i][j] == '#') continue;
                int ans = 0;
                for (int k = 0; k < 8; k++) {
                    int ni = i + dx[k];
                    int nj = j + dy[k];
                    if (inField(ni,nj,n,m) && c[ni][nj] =='#'){
                        ans++;
                    }
                }
                c[i][j] = (char)('0' + ans);
            }
        }

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                out.print(c[i][j]);
            }
            out.println();
        }
    }

    void run() throws IOException {
        // br = new BufferedReader(new FileReader("dragons.in"));
        //out = new PrintWriter("dragons.out");
        // br = new BufferedReader(new FileReader("input.txt"));
        // out = new PrintWriter("output.txt");
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        br.close();
        out.close();
    }

    public static void main(String[] args) throws IOException {
        // Locale.setDefault(Locale.US);
        new Main().run();
    }
}
//  [java]
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        char[][] S = new char[H][W];
        for(int i=0; i<H; i++){
            S[i] = sc.next().toCharArray();
        }
        //String S = sc.next();

        for(int i=0; i<H; i++){
            for(int j=0; j<W; j++){
                if(S[i][j]=='#'){
                    continue;
                }
                int count=0;
                if(i>0){
                    if(S[i-1][j]=='#'){
                        count++;
                    } 
                    if(j>0 && S[i-1][j-1]=='#'){
                        count++;
                    }
                    if(j<W-1 && S[i-1][j+1]=='#'){
                        count++;
                    }
                }

                if(j>0 && S[i][j-1]=='#'){
                    count++;
                }
                if(j<W-1 && S[i][j+1]=='#'){
                    count++;
                }

                if(i<H-1){
                    if(S[i+1][j]=='#'){
                        count++;
                    } 
                    if(j>0 && S[i+1][j-1]=='#'){
                        count++;
                    }
                    if(j<W-1 && S[i+1][j+1]=='#'){
                        count++;
                    }
                }
                
                System.out.print(count);
            }
            System.out.println();
        }
        
        
        
        
        
                
            

        }
        
        

        
        
        }
//  [java]
import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();//マス目の設定
        int W = sc.nextInt();
        String[][] map;
      	int[][] result;
      	map=new String [H][W];
      	result=new int[H][W];
       	
      
      	for(int i=0;i<H;i++) {//データの打ち込み
          for(int j=0;j<W;j++){
			map[i][j]=sc.next();
          }
		}
     	for(int i=0;i<H;i++) {//データの打ち込み
          for(int j=0;j<W;j++){
			result[i][j]=-1;
          }
		}
      
      	for(int i=0;i<H;i++) {//変換
          for(int j=0;j<W;j++){
           	if(map[i][j]=="."){
              result[i][j]=0;
              
              if(map[i][j+1]=="#"){
				result[i][j]+=1;
              }
              if(map[i][j-1]=="#"){
				result[i][j]+=1;
              }
              if(map[i+1][j]=="#"){
				result[i][j]+=1;
              }
              if(map[i-1][j]=="#"){
				result[i][j]+=1;
              }
              if(map[i+1][j+1]=="#"){
				result[i][j]+=1;
              }
              if(map[i-1][j+1]=="#"){
				result[i][j]+=1;
              }
              if(map[i+1][j-1]=="#"){
				result[i][j]+=1;
              }
              if(map[i-1][j-1]=="#"){
				result[i][j]+=1;
              }
              
           	}
          }
		}
      
      
      for(int i=0;i<H;i++) {//データの書き出し
        for(int j=0;j<W-1;j++){
          if(result[i][j]==-1){
			System.out.print(map[i][j]);
          }else{
          	System.out.print(result[i][j]);
          }
        }
        
		if(result[i][W]==-1){
		  System.out.println(map[i][W]);
        }else{
          System.out.println(result[i][W]);
        } 
      }
      
    }
}
//  [java]
import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();//マス目の設定
        int W = sc.nextInt();
        String[][] map;
      	int[][] result;
      	map=new String [H][W];
      	result=new int[H][W];
       	
      
      	for(int i=0;i<H;i++) {//データの打ち込み
          for(int j=0;j<W;j++){
			map[i][j]=sc.next();
          }
		}
     	for(int i=0;i<H;i++) {//データの打ち込み
          for(int j=0;j<W;j++){
			result[i][j]=-1;
          }
		}
      
      	for(int i=0;i<H;i++) {//変換
          for(int j=0;j<W;j++){
           	if(map[i][j]=="."){
              result[H][W]=0;
              
              if(map[i][j+1]=="#"){
				result[i][j]+=1;
              }
              if(map[i][j-1]=="#"){
				result[i][j]+=1;
              }
              if(map[i+1][j]=="#"){
				result[i][j]+=1;
              }
              if(map[i-1][j]=="#"){
				result[i][j]+=1;
              }
              if(map[i+1][j+1]=="#"){
				result[i][j]+=1;
              }
              if(map[i-1][j+1]=="#"){
				result[i][j]+=1;
              }
              if(map[i+1][j-1]=="#"){
				result[i][j]+=1;
              }
              if(map[i-1][j-1]=="#"){
				result[i][j]+=1;
              }
              
           	}
          }
		}
      
      
      for(int i=0;i<H;i++) {//データの書き出し
        for(int j=0;j<W-1;j++){
          if(result[i][j]==-1){
			System.out.print(map[i][j]);
          }else{
          	System.out.print(result[i][j]);
          }
        }
        
		if(result[i][W]==-1){
		  System.out.println(map[i][W]);
        }else{
          System.out.println(result[i][W]);
        } 
      }
      
    }
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;


bool is_sharp(vector<string> &s, int h, int w, int H, int W) {
  return 0 <= h && h < H && 0 <= w && w < W && s.at(h).at(w) == '#';
}

int count_sharp(vector<string>& s, int h, int w, int H, int W) {

  vector<vector<int> > coordinates = {
    {h - 1, w - 1},
    {h - 1, w    },
    {h - 1, w + 1},
    {h    , w + 1},
    {h + 1, w + 1},
    {h + 1, w    },
    {h + 1, w - 1},
    {h    , w - 1}
  };

  int count = 0;
  for (int i = 0; i < coordinates.size(); i++) {
    int h_i = coordinates.at(i).at(0);
    int w_i = coordinates.at(i).at(1);
    if (is_sharp(s, h_i, w_i, H, W)) {
      count++;
    }
  }

  return count;
}

void answer1() {
  cin.tie(0);
	ios_base::sync_with_stdio(false);
  int H, W;
  cin >> H >> W;
  vector<string> s(H);
  for (auto& s_i: s) {
    cin >> s_i;
  }
  for (int h = 0; h < H; h++) {
    for (int w = 0; w < W; w++) {
      if (! is_sharp(s, h, w, H, W)) {
        int count = count_sharp(s, h, w, H, W);
        //char c_count = (char)('0' + count);
        //s.at(h).at(w) = c_count;
        cout << count;
      } else {
        cout << '#';
      }
    }
    cout << endl;
  }
}

void answer2() {
  cin.tie(0);
	ios_base::sync_with_stdio(false);
  int H, W;
  cin >> H >> W;

  char s[52][52] = {};
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      cin >> s[i][j];
    }
  }

  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      if (s[i][j] == '#') {
        cout << '#';
      } else {
        int count = 0;
        for (int h = i - 1; h <= i + 1; h++) {
          for (int w = j - 1; w <= j + 1; w++) {
            if (s[h][w] == '#') {
              // s[i][j] == '#'であることはないのでforループに含んでいる
              count++;
            }
          }
        }
        cout << (char)('0' + count);
      }
    }
    cout << endl;
  }

}

int main() {
  //answer1();
  answer2();
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;
#define double long double
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define vout(v) for(int i=0;i<(int)v.size()-1;i++){cout<<v[i]<<" ";}cout<<v[v.size()-1]<<"\n";
#define debg(a) cerr<<#a<<" "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> V;
const long long MOD=1000000007;
const long long INF = 1e18;
vector <ll> dp;

void plus1(ll H, ll W, ll h, ll w, std::vector<std::string>& S){
    if (h<0 || w<0 || h>=H || w>=W) {return;}
    if (S[h][w]=='.') {
        S[h][w] = '1';
    } else if (S[h][w]!='#'){
        S[h][w] +=1;
    }
}

void solve(long long H, long long W, std::vector<std::string> S){
    for (ll i = 0; i < H; i++) {
        for (ll j = 0; j < W; j++) {
            if(S[i][j]=='.') { S[i][j]='0';}
            if(S[i][j]=='#') {
                plus1(H, W, i+1, j, S);
                plus1(H, W, i+1, j+1, S);
                plus1(H, W, i, j+1, S);
                plus1(H, W, i-1, j+1, S);
                plus1(H, W, i-1, j, S);
                plus1(H, W, i-1, j-1, S);
                plus1(H, W, i, j-1, S);
                plus1(H, W, i+1, j-1, S);
            }
        }
    }
    for (ll i = 0; i < H; i++) {
        cout << S[i] << "\n";
    }
}

int main(){
    long long H;
    scanf("%lld",&H);
    long long W;
    scanf("%lld",&W);
    std::vector<std::string> S(H);
    for(int i = 0 ; i < H ; i++){
        std::cin >> S[i];
    }
    solve(H, W, std::move(S));
    return 0;
}
//  [cpp]
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
	string s[52] = {}, yojo[52];
	int a, b, cnt = 0, yan;
	cin >> a >> b;
	for (int i = 1; i <= a; i++) {
		yojo[i] = "b";
		cin >> s[i];
		yojo[i] += s[i];
		yojo[i] += "b";
	}
	for (int i = 1; i <= a; i++) {
		for (int j = 1; j <= b; j++) {
			if (yojo[i][j] == '#') {
				cout << yojo[i][j];
			}
			else {
				if (yojo[i - 1][j - 1] == '#') {
					cnt++;
				}
				if (yojo[i - 1][j] == '#') {
					cnt++;
				}
				if (yojo[i - 1][j + 1] == '#') {
					cnt++;
				}
				if (yojo[i][j - 1] == '#') {
					cnt++;
				}
				if (yojo[i][j + 1] == '#') {
					cnt++;
				}
				if (yojo[i + 1][j - 1] == '#') {
					cnt++;
				}
				if (yojo[i + 1][j + 1] == '#') {
					cnt++;
				}
				if (yojo[i + 1][j] == '#') {
					cnt++;
				}
				cout << cnt;
			}
			cnt = 0;
		}
		cout << endl;
	}
	return 0;
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;

int main(){
    int m, n;
    cin >> m >> n;
    char arr[m][n];
    for(int i=0; i<m; i++){
        for(int j=0; j<n; j++){
            cin >> arr[i][j];
        }
    }
    int val{0};
    for(int i=0; i<m; i++){
        for(int j=0; j<n; j++){
            val = 0;
            if(arr[i][j] == '.'){
                if(j>0){
                if(arr[i][j-1]=='#'){
                        val++;
                }
                }
                if(j<(m-1)){
                if(arr[i][j+1]=='#'){
                        val++;
                }
                }
                if(i>0){
                    if(arr[i-1][j]=='#'){
                        val++;
                    }
                    if(j>0){
                        if(arr[i-1][j-1]=='#'){
                        val++;
                        }
                        
                        
                    }
                    if(j<(n-1)){
                        if(arr[i-1][j+1]=='#'){
                        val++;
                        }
                        
                    }
                }
                if(i<(m-1)){
                    if(arr[i+1][j]=='#'){
                        val++;
                    }
                    if(j>0){
                        if(arr[i+1][j-1]=='#'){
                        val++;
                        }
                        
                    }
                    if(j<(n-1)){
                        if(arr[i+1][j+1]=='#'){
                        val++;
                        }
                    }
                }
                val+=48;
                arr[i][j] = val;
            }
        }
    }
    for(int i=0; i<m; i++){
        for(int j=0; j<n; j++){
            cout << arr[i][j];
        }
        cout << endl;
    }
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;

int main(){
    int m, n;
    cin >> m >> n;
    char arr[m][n];
    for(int i=0; i<m; i++){
        for(int j=0; j<n; j++){
            cin >> arr[i][j];
        }
    }
    int val{0};
    for(int i=0; i<m; i++){
        for(int j=0; j<n; j++){
            val = 0;
            if(arr[i][j] == '.'){
                if(i>0){
                    if(arr[i-1][j]=='#'){
                        val++;
                    }
                    if(j>0){
                        if(arr[i-1][j-1]=='#'){
                        val++;
                        }
                        if(arr[i][j-1]=='#'){
                        val++;
                        }
                        
                    }
                    if(j<(n-1)){
                        if(arr[i-1][j+1]=='#'){
                        val++;
                        }
                        if(arr[i][j+1]=='#'){
                        val++;
                        }
                    }
                }
                if(i<(m-1)){
                    if(arr[i+1][j]=='#'){
                        val++;
                    }
                    if(j>0){
                        if(arr[i+1][j-1]=='#'){
                        val++;
                        }
                        
                    }
                    if(j<(n-1)){
                        if(arr[i+1][j+1]=='#'){
                        val++;
                        }
                    }
                }
                val+=48;
                arr[i][j] = val;
            }
        }
    }
    for(int i=0; i<m; i++){
        for(int j=0; j<n; j++){
            cout << arr[i][j];
        }
        cout << endl;
    }
}
//  [c]
#include <stdio.h>

int main(void) {
	int H, W;
	scanf("%d%d", &H, &W);
	char S[H][W];
	for (int i = 0; i < H; i++) {
		scanf("%s", S[i]);
	}

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (S[i][j] == '#') {
				putchar('#');
			} else {
				int n = 0;
				for (int dy = -1; dy <= 1; dy++) {
					int y = i + dy;
					for (int dx = -1; dx <= 1; dx++) {
						int x = j + dx;
						if (y < 0 || y >= H || x < 0 || x >= W) {
							continue;
						}
						if (S[y][x] == '#') {
							n++;
						}
					}
				}
				putchar('0' + n);
			}
		}
		putchar('\n');
	}
	return 0;
}
//  [c]
#include<stdio.h>
int main(void)
{
  int h,w;
  char s[100][100];
  int result[100][100];

  scanf("%d %d\n",&h,&w);
  for(int i=0;i<h;i++){
    scanf("%s",s[i]);
  }

  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      result[i][j]=0;
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(s[i][j]=='#'){
        result[i][j-1]++;
        result[i][j+1]++;
        result[i-1][j-1]++;
        result[i-1][j]++;
        result[i-1][j+1]++;
        result[i+1][j-1]++;
        result[i+1][j]++;
        result[i+1][j+1]++;
      }
    }
  }

  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(s[i][j]=='#'){
        printf("#");
      }else{
        printf("%d",result[i][j]);
      }
    }
    puts(" ");
  }
  return 0;
}
//  [c]
#include <stdio.h>

int main()
{
	int i, H, W;
	char S[52][52] = {};
	scanf("%d %d", &H, &W);
	for (i = 1; i <= H; i++) scanf("%s", &(S[i][1]));
	
	int j, k, l, count[52][52] = {};
	for (i = 1; i <= H; i++) {
		for (j = 1; j <= W; j++) {
			if (S[i][j] == '#') {
				for (k = -1; k <= 1; k++) {
					for (l = -1; l <= 1; l++) {
						if (S[i+k][j+l] == '.') count[i+k][j+l]++;
					}
				}
			}
		}
	}
	
	for (i = 1; i <= H; i++) {
		for (j = 1; j <= W; j++) {
			if (S[i][j] == '.') printf("%d", count[i][j]);
			else printf("#");
		}
		printf("\n");
	}
	fflush(stdout);
	return 0;
}
//  [c]
#include <stdio.h>
int main () {
  int h, w, i, j, k, l, temp;
  char s[50][50];
  char t[50][50];
  scanf ("%d%d", &h, &w);
  for (i = 0; i < h; ++i) {
    scanf ("%s", s[i]);
  }
  for (i = 0; i < h; ++i) {
    for (j = 0; j < w; ++j) {
      if (s[i][j] == '#') {
        t[i][j] = s[i][j];
      } else {
        temp = 0;
        for (k = i-1; k < i+2; ++k) {
          if (k == -1 || k == h) {
            continue;
          } else {
            for (l = j-1; l < j+2; ++l) {
              if (l == -1 || l == w) {
                continue;
              } else {
                if (s[k][l] == '#') {
                  temp += 1;
                }
              }
            }
          }
        }
        t[i][j] = '0' + temp;
      }
    }
  }
  for (i = 0; i < h; ++i) {
    t[i][w] = '\0';
    printf ("%s\n", t[i]);
  }
  return 0;
}
//  [c]
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;


int main(){
    int H, W;
    int count;

    cin >> H;
    cin >> W;

    char S[H][W];

    rep(i, H)
    {
        cin >> S[i];
    }

    rep(i, H)
    {
        rep(j, W){
            if (S[i][j] == '.'){
                count = 0;
                for (int k = -1; k < 2; k++)
                {
                    if((i + k > 0) && (i + k < H - 1)){
                        for (int l = -1; l < 2; l++)
                        {
                            if((j + l > 0) && (j + l < W - 1)){
                                if((k == 0) && (l == 0)){
                                }else{
                                    if(S[i + k][j + l] == '#') count++;
                                }
                            }
                        }
                    }
                }

                cout << count;
            }else{
                cout << '#';
            }
        }
        cout << endl;
    }

    return 0;
}
//  [c]
#include <bits/stdc++.h>

using namespace std;

int NumMine(vector<string> &data,int i,int j){
    int num = 0;
    if (i>0){
        if(j>0){
            if(data[i-1].at(j-1)=='#'){
                num++;
            }
        }
        if(data[i-1].at(j)=='#'){
            num++;
        }
        if(j<(data[i-1].length()-1)){
            if(data[i-1].at(j+1)=='#'){
                num++;
            }
        }
    }
    if(j>0){
        if(data[i].at(j-1)=='#'){
            num++;
        }
    }
    if(j<(data[i].length()-1)){
        if(data[i].at(j+1)=='#'){
            num++;
        }
    }

    if (i<(data.size()-1)){
        if(j>0){
            if(data[i+1].at(j-1)=='#'){
                num++;
            }
        }
        if(data[i+1].at(j)=='#'){
            num++;
        }
        if(j<(data[i+1].length()-1)){
            if(data[i+1].at(j+1)=='#'){
                num++;
            }
        }
    }
    return num;
}

int main(){
    int H, W;
    cin >> H >> W;

    vector<string> data(H);

    for (int i = 0; i < H;i++){
        cin >> data[i];
    }

    for (int i = 0; i < H;i++){
        for (int j = 0; j < W;j++){
            if(data[i].at(j)!='.'){
                continue;
            }else{
                data[i][j] = '0'+NumMine(data, i, j);
            }
        }
    }

    for (int i = 0; i < H;i++){
        cout << data[i] << endl;
    }
}
//  [javascript]
'use strict'
function Main(input){
  input = input.trim().split('\n');
  const hw = input.shift().split(' ').map((str)=> Number(str));
  const H  = hw[0], W = hw[1];  
  const data = input.map(ls => ls.split(''));
  
  const hy = [-1, -1, -1, 0, 0, 1, 1, 1];
  const wx = [-1, 0, 1, -1, 1, -1, 0, 1];
  
  for(let i = 0; i < H; i++){
    for(let j = 0; j < W; j++){
      
      if(data[i][j] === '#') continue;
      
      let count = 0;
      for(let k = 0; k < 8; k++){
        const y = i + hy[k] , x = j + wx[k]; 
        if(y < 0 || H <= y) continue;
        if(x < 0 || W <= x) continue;
        
        if(data[y][x] === '#') {
          count += 1;
        }
      }
      data[i][j] = count;
    }
  }
  const result = data.map(ls => ls.join('')).join('\n');
  console.log(result);
}

//固定
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
'use strict'

function main(s) {

  s = s.split('\n');
  const H = Number(s[0].split(' ')[0]);
  const W = Number(s[0].split(' ')[1]);
  const table = s.slice(1, -1).map(line => line.split(''));

  for (let h = 0; h < H; h++) {
    for (let w = 0; w < W; w++) {
      if (table[h][w] === '#') continue;

      let count = 0;

      // 上の行
      if (h >= 1) {
        
        // 左上
        if (w >= 1) {
          if (table[h - 1][w - 1] === '#') count += 1;
        }

        // 真上
        if (table[h - 1][w] === '#') count += 1;

        // 右上
        if (w < W - 1) {
          if (table[h - 1][w + 1] === '#') count += 1;
        }
      }

      // 該当行
      // 左
      if (w >= 1) {
        if (table[h][w - 1] === '#') count += 1;
      }

      // 右
      if (w < W - 1) {
        if (table[h][w + 1] === '#') count += 1;
      }

      // 下の行
      if (h < H - 1) {

        // 左下
        if (w >= 1) {
          if (table[h + 1][w - 1] === '#') count += 1;
        }

        // 真下
        if (table[h + 1][w] === '#') count += 1;

        // 右下
        if (w < W - 1) {
          if (table[h + 1][w + 1] === '#') count += 1;
        }
      }

      table[h][w] = count;
    }
  }

  const ans = table.map(line => line.join('')).join('\n');
  console.log(ans);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
function getLineByParam( param ){
  var ret;
  for ( var i=0; i<param[0].length; i++ ) {
    if ( "\n" == param[0].charAt( i ) ) {
      ret = param[0].slice( 0, i );
      param[0] = param[0].slice( ret.length+1 );
      return ret;
    }
  }
  ret = param[0];
  param[0]="";
  return ret;
}

function countBomb( S, i, j ){
  if ( '#' === S[i][j] ) return '#';
  var cnt = 0;
  if ( 0 < i ) {
    if ( 0 < j && '#' === S[i-1][j-1] ) cnt++;
    if ( '#' === S[i-1][j] ) cnt++;
    if ( S[i].length - 1 > j && '#' === S[i-1][j+1] ) cnt++;
  }
  if ( 0 < j && '#' === S[i][j-1] ) cnt++;
  if ( S[i].length - 1 > j && '#' === S[i][j+1] ) cnt++;
  if ( S.length - 1 > i ) {
    if ( 0 < j && '#' === S[i+1][j-1] ) cnt++;
    if ( '#' === S[i+1][j] ) cnt++;
    if ( S[i].length - 1 > j && '#' === S[i+1][j+1] ) cnt++;
  }
  return cnt;
}

function Main(input) {
  input = [input];
  var tmp = getLineByParam(input).split(" ");
  var H = parseInt( tmp[0] );
  var W = parseInt( tmp[1] );
  var S = [];
  for ( var i=0; i<H; i++ ) {
    S[i] = [];
    tmp = getLineByParam(input).split("");
    for ( var j=0; j<W; j++ ) {
      S[i][j] = tmp[j];
    }
  }

  for ( var i=0; i<H; i++ ) {
    for ( var j=0; j<W; j++ ) {
      S[i][j] = countBomb( S, i, j );
    }
    console.log( S[i].join("") );
  }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
function*stdinIter(){const t=require("fs").readFileSync("/dev/stdin","utf-8").trim().split(/\n|\s/);yield*t}function readMany(t,e){const i=e||this.iter||(this.iter=stdinIter()),n=[];for(let e=0;e<t;e+=1)n.push(i.next().value);return n};

(() => {
    const [ h, w ] = readMany(2).map(it => parseInt(it))
    const s = []
    const map = []

    for (let i = 0; i < h; i += 1) {
        const tmp = readMany(1)[0].split('')
        s.push(tmp)
        map.push([])
    }

    const get = (arr, i, j) => {
        const tmp = arr[i]
        if (tmp) {
            return tmp[j]
        } else {
            return void 0
        }
    }

    for (let i = 0; i < h; i += 1) {
        for (let j = 0; j < w; j += 1) {
            if (s[i][j] == '#') {
                map[i][j] = '#'
                continue
            }

            let boms = 0
            if (get(s, i - 1, j) == '#') boms += 1
            if (get(s, i - 1, j + 1) == '#') boms += 1
            if (get(s, i - 1, j - 1) == '#') boms += 1
            if (get(s, i, j) == '#') boms += 1
            if (get(s, i, j + 1) == '#') boms += 1
            if (get(s, i, j - 1) == '#') boms += 1
            if (get(s, i + 1, j) == '#') boms += 1
            if (get(s, i + 1, j + 1) == '#') boms += 1
            if (get(s, i + 1, j - 1) == '#') boms += 1

            map[i][j] = boms
        }
    }

    console.log(map)
})()
//  [javascript]
"use strict"

function Main(input) {
  input = input.trim().split('\n');
  const H = input[0].trim().split(' ').map(Number)[0];
  const W = input[0].trim().split(' ').map(Number)[1];
  const S = input.slice(1, W+1).map(val => val.trim().split(''));

  for(let h=0; h<H; h++){
    for(let w=0; w<W; w++){
      let tmp = S[h][w];
      if(tmp === '#'){
        if (h > 0) {
          if(w > 0) S[h-1][w-1] = S[h-1][w-1] === '.' ? 1 : S[h-1][w-1] === '#' ? '#' : S[h-1][w-1] + 1;
          S[h-1][w]   = S[h-1][w] === '.' ? 1 : S[h-1][w] === '#' ? '#' : S[h-1][w] + 1;
          if(w < W - 1) S[h-1][w+1] = S[h-1][w+1] === '.' ? 1 : S[h-1][w+1] === '#' ? '#' : S[h-1][w+1] + 1;
        }

        if (w > 0) {
          S[h][w-1]   = S[h][w-1] === '.' ? 1 : S[h][w-1] === '#' ? '#' : S[h][w-1] + 1;
        }

        if (w < W - 1) {
          S[h][w+1]   = S[h][w+1] === '.' ? 1 : S[h][w+1] === '#' ? '#' : S[h][w+1] + 1;
        }

        if (h < H - 1) {
          if(w > 0) S[h+1][w-1] = S[h+1][w-1] === '.' ? 1 : S[h+1][w-1] === '#' ? '#' : S[h+1][w-1] + 1;
          S[h+1][w]   = S[h+1][w] === '.' ? 1 : S[h+1][w] === '#' ? '#' : S[h+1][w] + 1;
          if(w < W - 1) S[h+1][w+1] = S[h+1][w+1] === '.' ? 1 : S[h+1][w+1] === '#' ? '#' : S[h+1][w+1] + 1;
        }
      }
    };
  };

  console.log(S.join('\n').replace(/,/g, '').replace(/\./g, '0'));
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [go]
package main

import (
	"bufio"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	iv, _ := strconv.Atoi(readStr())
	return iv
}

func readStr() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	h, w := readInt(), readInt()
	s := make([]string, h)
	for i := range s {
		s[i] = readStr()
	}

	var wr = bufio.NewWriter(os.Stdout)
	mvx := []int{-1, 0, 1, -1, 1, -1, 0, 1}
	mvy := []int{1, 1, 1, 0, 0, -1, -1, -1}
	for i := range s {
		for j := range s[i] {
			if s[i][j] == '#' {
				wr.WriteString("#")
				continue
			}

			cnt := 0
			for k := 0; k < 8; k++ {
				if x, y := j+mvx[k], i+mvy[k]; x >= 0 && x < w && y >= 0 && y < h && s[y][x] == '#' {
					cnt++
				}
			}
			wr.WriteString(strconv.Itoa(cnt))
		}
		wr.WriteString("\n")
	}
	wr.Flush()
}
//  [go]
package main

import (
	"fmt"
	"os"
	"bufio"
)

type Directions int
const (
	up = iota
	upRight
	right
	downRight
	down
	downLeft
	left
	upLeft
)

type Area rune
const (
	Bomb = '#'
	Space = '.'
)

func main() {
	var H,W int
	input := bufio.NewScanner(os.Stdin)

	fmt.Scan(&H)
	area := make([]string,H)
	sampleArea:= make([]string,H) 

	fmt.Scan(&W)

	for i := 0;i < H;i++ {
		input.Scan()
		sampleArea[i] = input.Text()
	}
	
	for y,str := range sampleArea {
		runeArray := make([]rune,W)
		for x,char := range str {
			if Bomb == char {
				runeArray[x] = Bomb
				continue
			}
			runeArray[x] = rune(countBomb(sampleArea,W,H,x,y) + '0')
		}
		area[y] = string(runeArray)
	}
	
	for _,str := range area {
		fmt.Println(str)
	}
}

func countBomb(area []string,xMax int,yMax int,x int,y int) int {
	var count int
	for dir := up;dir <= upLeft;dir++ {
		if look(Directions(dir),area,x,y) {
			count++
		}
	}
	return count
}

func look(direction Directions,area []string,x int,y int) bool{
	switch direction {
	case up:
		if 0 == y || Space == area[y - 1][x]{
			return false 
		}
	case upRight:
		if len(area[y]) - 1 == x || 0 == y || Space ==  area[y - 1][x + 1] {
			return false
		}
	case right:
		if len(area[y]) - 1 == x || Space == area[y][x + 1] {
			return false
		}
	case downRight:
		if len(area[y]) - 1  == x || len(area) - 1 == y || Space == area[y + 1][x + 1] {
			return false
		}
	case down:
		if len(area) - 1 == y || Space == area[y + 1][x]{
			return false
		}
	case downLeft:
		if len(area) - 1 == y || 0 == x || Space == area[y + 1][x - 1] {
			return false
		}
	case left:
		if 0 == x || Space == area[y][x - 1] {
			return false
		}
	case upLeft:
		if 0 == x || 0 == y || Space == area[y - 1][x - 1] {
			return false
		}
	}
	return true
}
//  [go]
package main

import (
  "fmt"
  "strconv"
)

func main() {
  var h, w int
  fmt.Scan(&h, &w)

  grid := make([]string, h)
  for i := 0; i < h; i++ {
    fmt.Scan(&grid[i])
  }
  var cnt [50][50]int
  for i := 0; i < h; i++ {
    for j := 0; j < w; j++ {
      if grid[i][j] == '.' {continue}
      for dy := -1; dy < 2; dy++ {
        for dx := -1; dx < 2; dx++ {
          y, x := i + dy, j + dx
          if y < 0 || x < 0 {continue}
          cnt[y][x]++
        }
      }
    }
  }
  for i := 0; i < h; i++ {
    for j := 0; j < w; j++ {
      if grid[i][j] == '#' {
        fmt.Print("#")
      } else {
        fmt.Print(strconv.Itoa(cnt[i][j]))
      }
    }
    fmt.Print("\n")
  }
}