Latin Squares
A Latin square is an N×N grid filled with numbers from 1 to N, where each number appears exactly once in each row and each column. Here is an example of a 3×3 Latin square:
You are given a rectangular matrix of dimensions W×H (W ≠ H, 2 ≤ W, H ≤ 8). This matrix is filled with numbers ranging from 1 to max(W, H) across its rows and columns. Your task is to transform this matrix into a Latin square with a side length of max(W, H), or determine if this transformation is impossible. The original content of the matrix must remain unchanged.
Input
The first line of input contains the integers W and H. The next H lines each contain W numbers, separated by spaces.
Output
If it is impossible to transform the rectangle into a Latin square, output "Impossible" (without quotes). Otherwise, first output the side length of the Latin square, followed by the Latin square itself in subsequent lines. Ensure that numbers in each row are separated by a single space. If multiple solutions exist, you may output any one of them.