Score : 1000 points
Problem Statement
There are positive integers N,M, and an N×M positive integer matrix Ai,j. For two (strictly) increasing positive integer sequences X=(X1,…,XN) and Y=(Y1,…,YM), we define the penalty D(X,Y) as max1≤i≤N,1≤j≤M∣XiYj−Ai,j∣.
Find two (strictly) increasing positive integer sequences X and Y such that D(X,Y) is the smallest possible.
Constraints
- 1≤N,M≤5
- 1≤Ai,j≤109 (1≤i≤N, 1≤j≤M)
- All values in the input are integers.
Input is given from Standard Input in the following format:
N M
A1,1 … A1,M
⋮
AN,1 … AN,M
Output
Output your answer in the following format:
Dmin
X1 … XN
Y1 … 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 (1≤i≤N−1).
- Yj<Yj+1 (1≤j≤M−1).
- 1≤Xi≤2⋅109 (1≤i≤N).
- 1≤Yj≤2⋅109 (1≤j≤M).
One can show that there is an optimal solution satisfying the last two conditions.