#include <algorithm>
#include <iostream>
using namespace std;
const int N = 2000;
const int M = 2000;
const int INF = 0x3f3f3f3f;
int aa[M], qq[N][N], ii[N];
long long pp[N][N];
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL);
int n, m; cin >> n >> m;
for (int i = 0; i < n; i++) {
int s_ = 0;
for (int j = 0; j < m; j++)
cin >> aa[j], s_ += aa[j];
for (int s = s_, h = 0, j = 0; j < m; j++) {
int a = aa[j] * n, q = aa[j] * n;
for (long long p = (long long) j * q; s <= a; a -= s, s = s_)
pp[i][h] = p += s, qq[i][h] = q, h++;
s -= a;
}
}
for (int z = 0; z < n; z++)
ii[z] = z;
for (int r = 0; r < 50000; r++)
for (int z = 0; z + 1 < n; z++)
if ((__int128) pp[ii[z]][z] * qq[ii[z + 1]][z] > (__int128) pp[ii[z + 1]][z] * qq[ii[z]][z])
swap(ii[z], ii[z + 1]);
for (int z = 0; z + 1 < n; z++)
cout << pp[ii[z]][z] << ' ' << qq[ii[z]][z] << '\n';
for (int z = 0; z < n; z++)
cout << ii[z] + 1 << ' ';
cout << '\n';
return 0;
}