Problem Statement
There are positive integers N,M, and an NtimesM positive integer matrix Ai,j. For two (strictly) increasing positive integer sequences X=(X1,ldots,XN) and Y=(Y1,ldots,YM), we define the penalty D(X,Y) as max1leqileqN,1leqjleqM∣XiYj−Ai,j∣.
Find two (strictly) increasing positive integer sequences X and Y such that D(X,Y) is the smallest possible.
Constraints
- 1leqN,Mleq5
- 1leqAi,jleq109 (1leqileqN, 1leqjleqM)
- All values in the input are integers.
Input is given from Standard Input in the following format:
N M
A1,1 ldots A1,M
vdots
AN,1 ldots AN,M
Output
Output your answer in the following format:
Dmin
X1 ldots XN
Y1 ldots YM
Here, Dmin is the smallest possible penalty and the following conditions should be satisfied:
- D(X,Y) should be equal to Dmin.
- Xi<Xi+1 (1leqileqN−1).
- Yj<Yj+1 (1leqjleqM−1).
- 1leqXileq2cdot109 (1leqileqN).
- 1leqYjleq2cdot109 (1leqjleqM).
One can show that there is an optimal solution satisfying the last two conditions.
Sample Output 1
Sample Output 2
Sample Output 3