Kind of a Blur

No attempts yetTime limit1sMemory limit128 MB

Problem

Image blurring occurs when the object being captured is out of the camera's focus. Recovering the original image given only its blurred version is one of the most interesting topics in image processing; this process is called deblurring, and it is your task in this problem.

In this problem all images are grey-scale (no colours). An image is represented as a two-dimensional matrix of real numbers, where each cell holds the brightness of the corresponding pixel. Although not mathematically exact, a blurred image can be described by replacing each pixel with the average of all pixels whose Manhattan distance† from it is at most a fixed value $D$ (the pixel itself included). Here is how the blur of a $3 \times 3$ image with blurring distance $D = 1$ is computed:

$$ \text{blur}\begin{pmatrix}\begin{bmatrix} 2 & 30 & 17 \ 25 & 7 & 13 \ 14 & 0 & 35 \end{bmatrix}\end{pmatrix} = \begin{bmatrix} \frac{2+30+25}{3} & \frac{2+30+17+7}{4} & \frac{30+17+13}{3} \ \frac{2+25+7+14}{4} & \frac{30+25+7+13+0}{5} & \frac{17+7+13+35}{4} \ \frac{25+14+0}{3} & \frac{7+14+0+35}{4} & \frac{13+0+35}{3} \end{bmatrix} = \begin{bmatrix} 19 & 14 & 20 \ 12 & 15 & 18 \ 13 & 14 & 16 \end{bmatrix} $$

Given a blurred image, reconstruct the original image assuming it was blurred exactly as described above.

† The Manhattan distance (also called the taxicab distance) between two points is the sum of the absolute differences of their coordinates. That is, the Manhattan distance between pixels $(r_1, c_1)$ and $(r_2, c_2)$ is $|r_1 - r_2| + |c_1 - c_2|$.

Input

The input consists of several test cases. Each case is given on $H + 1$ lines. The first line contains three non-negative integers $W$, $H$, and $D$: the width and height of the blurred image and the blurring distance, respectively, where $1 \le W, H \le 10$ and $D \le \min(W/2, H/2)$. The following $H$ lines give the brightness of each pixel of the blurred image. Each line contains $W$ non-negative real numbers given to two decimal places, and every value is less than $100$.

Zero or more lines consisting entirely of whitespace may appear between cases. The last line of the input contains three zeros.

Output

For each test case, print the deblurred image as a matrix of real numbers of the same size ($H$ lines, each with $W$ values). Round each entry to two decimal places and right-justify it in a field of width $8$. Separate the outputs of two consecutive test cases by a single empty line, and do not print an empty line after the last test case. It is guaranteed that every test case has exactly one unique solution.