400467: GYM100187 G Image Processing
Description
At the time free of games Andrey processes images. Most of all he likes to process grayscale images. Each pixel on a grayscale image has a brightness which is the integer from 0 to 109, inclusively. The closer the brightness to zero, the darker is this pixel; zero brightness corresponds to the black color and 109 — to the white. Andrey calls such pictures colored.
When processing colored picture, Andrey chooses an integer t from 0 to 109, inclusively, and creates a new image consisting of only two colors: black and while (he denotes them as 0 and 1, correspondingly). He calls such images monochrome.
The principle of creating monochrome images is very simple: Andrey looks at each pixel of the initial colored image and, if the brightness of this pixel is strictly less that t, this pixel will be black on the monochrome image, otherwise it will be white.
You are given k monochrome images. You are to determine if they all could be the result of processing the same colored image, and if they could, which exactly colored image and values t1, ..., tk could be used.
InputThe first line contains three positive integers k, n and m (1 ≤ k·n·m ≤ 200000) — the amount of images and their sizes.
Then k blocks describing monochrome images follow. Each block starts from the empty line, followed by the description of the image: n lines of m characters each. These characters can be either «0», which denotes the black color, or «1», which corresponds to the white color.
OutputIf there is no such colored image that all k given monochrome images can be the result of its processing, output «IMPOSSIBLE».
Otherwise, in the first n lines output the matrix n × m, each element of which is the integer from 0 to 109 and equals to the brightness of the corresponding pixel of the colored image. Numbers should be separated by spaces.
After the matrix in the next line output k numbers t1, ..., tk (0 ≤ ti ≤ 109) used to obtain the corresponding monochrome images.
If there are several possible solutions, output any of them.
ExamplesInput2 3 3Output
011
000
110
111
100
111
2 4 5Input
2 1 0
4 7 2
4 2
2 3 3Output
011
000
110
100
101
001
IMPOSSIBLE