time limit per test: 0.25 sec. memory limit per test: 65536 KB
input: standard output: standard
Consider a monochrome computer monitor with N x M pixels resolution. It can display K symbols. Symbol is a non-empty set of black pixels on the screen. You are to write a program, that computes minimal possible amount of pixels, that are enough to recognize a symbol.
Input
First line of input contains integers N, M, K (1 <= N, M <= 10, 2 <= K <= 6). K blocks follow, separated by empty lines. Each block consists of N rows of M characters. It's a symbols representation on the N x M screen. `1' denotes black pixel, `0' denotes white pixel. You may assume that symbols are unique.
Output
Print on the first line of output the minimal possible amount of pixels that enough to recognize symbol. I.e. you have to find set of pixels that has different color in each pair of symbols. If there are several sets with equal amount of pixels, output any of them. Then print N lines M characters each. `1' denotes that corresponding pixel is in your set. `0' denotes that corresponding pixel is not in your set.
Sample test(s)
Input
2 4 3 0000 0001
1000 0001
1111 1001
Output
2 1000 1000
Note
In this example output set consists of two most left pixels. They are both white in first symbol; black and white in second symbol; both black in third symbol. So, it's possible to recognize each symbol using this set of pixels.