You have square tiles, each painted with a color codified with a number. You will have to use the tiles to cover a floor of dimensions , with just one restriction: there cannot be two or more (horizontal or vertical) adjacent tiles of the same color. Can you find a solution?
Input consists of several cases, each with and , followed by numbers, all between 1 and . Assume .
For each case, if there is no solution, print a line with
“NO”. Otherwise, print a line with “YES”,
followed by
lines with
numbers each. If there is more than one solution, you can print any one.
Follow strictly the format of the sample output.
Input
2 3 6 1 1 4 4 6 2 3 6 1 1 4 4 6 2 3 6 6 6 6 2 2 4 4 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 1 11 1 2 3 4 5 6 7 8 9 10 11
Output
YES 1 4 6 6 1 4 YES 6 4 1 4 1 6 NO YES 4 3 2 1 3 1 4 3 1 2 3 1 2 4 2 4 YES 5 11 4 6 3 7 2 8 10 9 1