//84104971101048411497 - Can you guess what does this mean?
using namespace std;
#include <bits/stdc++.h>
#define mapii map<int, int>
#define debug(a) cout << #a << ": " << a << endl
#define fdto(i, r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define forit(it, type, var) for(type::iterator it = var.begin(); it != var.end(); it++)
#define fordit(rit, type, var) for(type::reverse_iterator rit = var.rbegin(); rit != var.rend(); rit++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ll long long
#define maxN 15
#define maxK 35
struct box {
int id, n;
int d[maxN];
inline bool operator < (const box &b) const {
fto(i, 1, n)
if (d[i] >= b.d[i]) return false;
return true;
}
};
int k, n, f[maxK], trace[maxK];
box a[maxK];
vector<int> ans;
int main () {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
while (scanf("%d%d", &k, &n) != EOF) {
fto(i, 1, k)
fto(j, 1, n) scanf("%d", &a[i].d[j]);
fto(i, 1, k) {
a[i].id = i;
a[i].n = n;
sort(a[i].d+1, a[i].d+n+1);
}
// std::stable_sort algorithm
stable_sort(a+1, a+k+1);
// Printing out all boxes
fto(i, 1, k) {
printf("%d\n", a[i].id);
fto(j, 1, n) printf("%d ", a[i].d[j]);
printf("\n");
}
fto(i, 1, k) {
f[i] = 1;
trace[i] = 0;
fto(j, 1, i-1) {
if (a[j] < a[i] && f[i] < f[j]+1) {
f[i] = f[j]+1;
trace[i] = j;
}
}
}
printf("%d\n", *max_element(f+1, f+k+1));
int pos = max_element(f+1, f+k+1)-f;
ans.clear();
int u = pos;
while (trace[u] != 0) {
u = trace[u];
ans.pb(a[u].id);
}
fordit(rit, vector<int>, ans) printf("%d ", *rit);
printf("%d\n", a[pos].id);
}
return 0;
}
Ly84NDEwNDk3MTEwMTA0ODQxMTQ5NyAtIENhbiB5b3UgZ3Vlc3Mgd2hhdCBkb2VzIHRoaXM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10sIHRyYWNlW21heEtdOwpib3ggYVttYXhLXTsKdmVjdG9yPGludD4gYW5zOwogCmludCBtYWluICgpIHsKICAgICNpZm5kZWYgT05MSU5FX0pVREdFCiAgICAgICAgZnJlb3BlbigiaW5wdXQudHh0IiwgInIiLCBzdGRpbik7CiAgICAgICAgLy9mcmVvcGVuKCJvdXRwdXQudHh0IiwgInciLCBzdGRvdXQpOwogICAgI2VuZGlmIC8vIE9OTElORV9KVURHRQogCiAgICB3aGlsZSAoc2NhbmYoIiVkJWQiLCAmaywgJm4pICE9IEVPRikgewogICAgICAgIGZ0byhpLCAxLCBrKQogICAgICAgICAgICBmdG8oaiwgMSwgbikgc2NhbmYoIiVkIiwgJmFbaV0uZFtqXSk7CiAgICAgICAgZnRvKGksIDEsIGspIHsKICAgICAgICAgICAgYVtpXS5pZCA9IGk7CiAgICAgICAgICAgIGFbaV0ubiA9IG47CiAgICAgICAgICAgIHNvcnQoYVtpXS5kKzEsIGFbaV0uZCtuKzEpOwogICAgICAgIH0KCQkvLyBzdGQ6OnN0YWJsZV9zb3J0IGFsZ29yaXRobQogICAgICAgIHN0YWJsZV9zb3J0KGErMSwgYStrKzEpOwogICAgICAgIC8vIFByaW50aW5nIG91dCBhbGwgYm94ZXMKICAgICAgICBmdG8oaSwgMSwgaykgewogICAgICAgICAgICBwcmludGYoIiVkXG4iLCBhW2ldLmlkKTsKICAgICAgICAgICAgZnRvKGosIDEsIG4pIHByaW50ZigiJWQgIiwgYVtpXS5kW2pdKTsKICAgICAgICAgICAgcHJpbnRmKCJcbiIpOwogICAgICAgIH0KICAgICAgICBmdG8oaSwgMSwgaykgewogICAgICAgICAgICBmW2ldID0gMTsKICAgICAgICAgICAgdHJhY2VbaV0gPSAwOwogICAgICAgICAgICBmdG8oaiwgMSwgaS0xKSB7CiAgICAgICAgICAgICAgICBpZiAoYVtqXSA8IGFbaV0gJiYgZltpXSA8IGZbal0rMSkgewogICAgICAgICAgICAgICAgICAgIGZbaV0gPSBmW2pdKzE7CiAgICAgICAgICAgICAgICAgICAgdHJhY2VbaV0gPSBqOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHByaW50ZigiJWRcbiIsICptYXhfZWxlbWVudChmKzEsIGYraysxKSk7CiAgICAgICAgaW50IHBvcyA9IG1heF9lbGVtZW50KGYrMSwgZitrKzEpLWY7CiAKICAgICAgICBhbnMuY2xlYXIoKTsKICAgICAgICBpbnQgdSA9IHBvczsKICAgICAgICB3aGlsZSAodHJhY2VbdV0gIT0gMCkgewogICAgICAgICAgICB1ID0gdHJhY2VbdV07CiAgICAgICAgICAgIGFucy5wYihhW3VdLmlkKTsKICAgICAgICB9CiAgICAgICAgZm9yZGl0KHJpdCwgdmVjdG9yPGludD4sIGFucykgcHJpbnRmKCIlZCAiLCAqcml0KTsKICAgICAgICBwcmludGYoIiVkXG4iLCBhW3Bvc10uaWQpOwogICAgfQogCiAgICByZXR1cm4gMDsKfQ==