#t151. 扫雷

扫雷

Minesweeper

Problem Description

Xiaoyang is playing the classic game "Minesweeper" and wants to generate a Minesweeper map himself.

Xiaoyang wants a map of nn rows and mm columns, with n×mn \times m cells in total. The rows are numbered 1,2,…,n1, 2, \dots, n and the columns 1,2,…,m1, 2, \dots, m. Some cells are mines; the others are not.

Xiaoyang designates qq cells as mines, and all other cells are non-mines. He wants you to compute, for each non-mine cell, how many mine cells it is adjacent to.

Two cells are adjacent if and only if they share at least one vertex (that is, for a cell not on the map's edge, the 88 surrounding cells are all adjacent to it).

Input Format

The input contains q+1q + 1 lines. The first line contains three positive integers nn, mm, and qq: the number of rows, the number of columns, and the number of mines. The following qq lines each contain two integers: the row and column of the ii-th mine. The given mines are guaranteed to be distinct.

Output Format

Output nn lines, each with mm characters separated by spaces. For cell (i,j)(i, j), output:

  1. * if it is a mine;
  2. otherwise the number of adjacent mines (a digit from 0 to 8).

Sample Input

3 4 4
1 1
1 3
2 4
3 2

Sample Output

* 2 * 2
2 3 3 *
1 * 2 1

Sample Explanation

From the input, the map is 33 rows and 44 columns with 44 mines at (1,1)(1,1), (1,3)(1,3), (2,4)(2,4), and (3,2)(3,2). In the output * marks a mine; the other digits mark how many mines each non-mine cell is adjacent to. For example, cell (2,2)(2,2) (non-mine) is adjacent to three mines (1,1)(1,1), (1,3)(1,3), and (3,2)(3,2), so it outputs 33; cell (1,2)(1,2) is adjacent to two mines (1,1)(1,1) and (1,3)(1,3), so it outputs 22. The rest follow the same rule, giving the sample output.

Constraints

  • 3≤n,m≤5003 \le n, m \le 500
  • 1≤q≤n⋅m1 \le q \le n \cdot m
  • The given mines are inside the map and distinct; rows and columns are 11-indexed.