400467: GYM100187 G Image Processing

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

G. Image Processingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

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.

Input

The 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.

Output

If 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.

ExamplesInput
2 3 3


011
000
110


111
100
111
Output
2 4 5
2 1 0
4 7 2
4 2
Input
2 3 3


011
000
110


100
101
001
Output
IMPOSSIBLE

加入题单

算法标签: