description: Alice has an empty grid with n rows and m columns. Some of the cells are marked, and no marked cells are adjacent to the edge of the grid. (Two squares are adjacent if they share a side.) 
  
  Alice wants to fill each cell with a number such that the following statements are true: 
  
    * every unmarked cell contains either the number 1 or 4; 
    * every marked cell contains the sum of the numbers in all unmarked cells adjacent to it (if a marked cell is not adjacent to any unmarked cell, this sum is 0); 
    * every marked cell contains a multiple of 5. 
  
  Alice couldn't figure it out, so she asks Bob to help her. Help Bob find any such grid, or state that no such grid exists.
  
  Input
  
  The first line of input contains two integers n and m (1 ≤ n, m ≤ 500) — the number of rows and the number of columns in the grid, respectively.
  
  Then n lines follow, each containing m characters. Each of these characters is either '.' or 'X' — an unmarked and a marked cell, respectively. No marked cells are adjacent to the edge of the grid.
  
  Output
  
  Output "'NO" if no suitable grid exists. Otherwise, output "'YES"'. Then output n lines of m space-separated integers — the integers in the grid.
  
  Examples
  
  Input
  
  
  5 5
  .....
  .XXX.
  .X.X.
  .XXX.
  .....
  
  
  Output
  
  
  YES
  4 1 4 4 1
  4 5 5 5 1
  4 5 1 5 4
  1 5 5 5 4
  1 4 4 1 4
  
  
  Input
  
  
  5 5
  .....
  .XXX.
  .XXX.
  .XXX.
  .....
  
  
  Output
  
  
  NO
  
  
  Input
  
  
  3 2
  ..
  ..
  ..
  
  
  Output
  
  
  YES
  4 1
  4 1
  1 4
  
  
  Input
  
  
  9 9
  .........
  .XXXXX.X.
  .X...X...
  .X.XXXXX.
  .X.X.X.X.
  .X.XXX.X.
  .X.....X.
  .XXXXXXX.
  .........
  
  
  Output
  
  
  YES
  4 4 4 1 4 1 4 1 4
  1 5 5 5 5 5 4 10 1
  4 5 1 4 1 5 4 4 4
  4 5 1 5 5 0 5 5 1
  4 5 1 5 4 5 1 5 4
  4 5 1 5 5 5 4 5 1
  1 5 4 4 1 1 4 5 1
  4 5 5 5 5 5 5 5 4
  1 1 1 1 4 4 1 1 4
  
  Note
  
  It can be shown that no such grid exists for the second test.
solution: import java.util.*;
  import java.io.*;
  
  public class F {
  
      static PrintWriter pw;
  
      int[][] dir = {{0, -1}, {-1, 0}, {0, 1}, {1, 0}};
  
      void solve(int n, int m, char[][] g) {
          // tr(n, m, g);
          // List[] adj = initializeGraph(n * m);
          List<List<Integer>> adj = initializeGraph(n * m);
          // tr(adj);
          for (int i = 0; i < n; i++) {
              for (int j = 0; j < m; j++) {
                  if (g[i][j] == 'X') {
                      List<Integer> q = new ArrayList<>();
                      for (int[] e : dir) {
                          int x = i + e[0];
                          int y = j + e[1];
                          if (x < 0 || x >= n || y < 0 || y >= m) continue;
                          if (g[x][y] == '.') {
                              q.add(x * m + y);
                          }
                      }
                      // tr(q.size());
                      if (q.size() % 2 == 1) {
                          pr("NO");
                          return;
                      }
                      for (int k = 0; k < q.size(); k += 2) {
                          int x = q.get(k), y = q.get(k + 1);
                          // adj[x].add(y);
                          // adj[y].add(x);
                          adj.get(x).add(y);
                          adj.get(y).add(x);
                          // tr(adj);
                      }
                  }
              }
          }
          // tr(adj);
          List<Integer> que = new ArrayList<>();
          int[][] res = new int[n][m];
          for (int i = 0; i < n; i++) {
              for (int j = 0; j < m; j++) {
                  if (res[i][j] > 0 || g[i][j] == 'X') continue;
                  res[i][j] = 1;
                  que.add(i * m + j);
                  while (que.size() > 0) {
                      int cur = que.get(0);
                      que.remove(0);
                      for (Object o : adj.get(cur)) {
                          int v = (int) o;
                          // tr(v);
                          if (res[v / m][v % m] == 0) {
                              res[v / m][v % m] = res[cur / m][cur % m] ^ 5;
                              que.add(v);
                          }
                      }
                  }
              }
          }
          pr("YES");
          for (int i = 0; i < n; i++) {
              for (int j = 0; j < m; j++) {
                  if (g[i][j] == 'X') {
                      for (int[] e : dir) {
                          int x = i + e[0];
                          int y = j + e[1];
                          if (x < 0 || x >= n || y < 0 || y >= m) continue;
                          if (g[x][y] == '.') {
                              res[i][j] += res[x][y];
                          }
                      }
                  }
                  if (j == m - 1) {
                      pr(res[i][j]);
                  } else {
                      pw.print(res[i][j] + " ");
                  }
              }
          }
      }
  
  //    List[] initializeGraph(int n) {
  //        List[] g = new ArrayList[n];
  //        Arrays.fill(g, new ArrayList<Integer>());
  //        return g;
  //    }
  
      List<List<Integer>> initializeGraph(int n) {
          List<List<Integer>> g = new ArrayList<>();
          for (int i = 0; i < n; i++) {
              g.add(new ArrayList<>());
          }
          return g;
      }
  
      private void run() {
          // read_write_file(); // comment this before submission
          FastScanner fs = new FastScanner();
          int t = 1;
          while (t-- > 0) {
              int n = fs.nextInt();
              int m = fs.nextInt();
              char[][] g = new char[n][m];
              for (int i = 0; i < n; i++) g[i] = fs.next().toCharArray();
              solve(n, m, g);
          }
      }
  
      private final String INPUT = "input.txt";
      private final String OUTPUT = "output.txt";
  
      void read_write_file() {
          FileInputStream instream = null;
          PrintStream outstream = null;
          try {
              instream = new FileInputStream(INPUT);
              outstream = new PrintStream(new FileOutputStream(OUTPUT));
              System.setIn(instream);
              System.setOut(outstream);
          } catch (Exception e) {
          }
      }
  
      public static void main(String[] args) {
          pw = new PrintWriter(System.out);
          new F().run();
          pw.close();
      }
  
      void pr(int num) {
          pw.println(num);
      }
  
      void pr(long num) {
          pw.println(num);
      }
  
      void pr(double num) {
          pw.println(num);
      }
  
      void pr(String s) {
          pw.println(s);
      }
  
      void pr(char c) {
          pw.println(c);
      }
  
      class FastScanner {
          BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
          StringTokenizer st = new StringTokenizer("");
  
          String next() {
              while (!st.hasMoreTokens())
                  try {
                      st = new StringTokenizer(br.readLine());
                  } catch (IOException e) {
                      e.printStackTrace();
                  }
              return st.nextToken();
          }
  
          int nextInt() {
              return Integer.parseInt(next());
          }
  
          int[] readArray(int n) {
              int[] a = new int[n];
              for (int i = 0; i < n; i++)
                  a[i] = nextInt();
              return a;
          }
  
          Integer[] readIntegerArray(int n) {
              Integer[] a = new Integer[n];
              for (int i = 0; i < n; i++)
                  a[i] = nextInt();
              return a;
          }
  
          long nextLong() {
              return Long.parseLong(next());
          }
  
          double nextDouble() {
              return Double.parseDouble(next());
          }
      }
  
      void tr(Object... o) {
          pw.println(Arrays.deepToString(o));
      }
  }