//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::sort algorithm
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;
}
Ly84NDEwNDk3MTEwMTA0ODQxMTQ5NyAtIENhbiB5b3UgZ3Vlc3Mgd2hhdCBkb2VzIHRoaXMgbWVhb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ttYXhLXTsKYm94IGFbbWF4S107CnZlY3RvcjxpbnQ+IGFuczsKCmludCBtYWluICgpIHsKICAgICNpZm5kZWYgT05MSU5FX0pVREdFCiAgICAgICAgZnJlb3BlbigiaW5wdXQudHh0IiwgInIiLCBzdGRpbik7CiAgICAgICAgLy9mcmVvcGVuKCJvdXRwdXQudHh0IiwgInciLCBzdGRvdXQpOwogICAgI2VuZGlmIC8vIE9OTElORV9KVURHRQoKICAgIHdoaWxlIChzY2FuZigiJWQlZCIsICZrLCAmbikgIT0gRU9GKSB7CiAgICAgICAgZnRvKGksIDEsIGspCiAgICAgICAgICAgIGZ0byhqLCAxLCBuKSBzY2FuZigiJWQiLCAmYVtpXS5kW2pdKTsKICAgICAgICBmdG8oaSwgMSwgaykgewogICAgICAgICAgICBhW2ldLmlkID0gaTsKICAgICAgICAgICAgYVtpXS5uID0gbjsKICAgICAgICAgICAgc29ydChhW2ldLmQrMSwgYVtpXS5kK24rMSk7CiAgICAgICAgfQoJCS8vIHN0ZDo6c29ydCBhbGdvcml0aG0KICAgICAgICBzb3J0KGErMSwgYStrKzEpOwogICAgICAgIC8vIFByaW50aW5nIG91dCBhbGwgYm94ZXMKICAgICAgICBmdG8oaSwgMSwgaykgewogICAgICAgICAgICBwcmludGYoIiVkXG4iLCBhW2ldLmlkKTsKICAgICAgICAgICAgZnRvKGosIDEsIG4pIHByaW50ZigiJWQgIiwgYVtpXS5kW2pdKTsKICAgICAgICAgICAgcHJpbnRmKCJcbiIpOwogICAgICAgIH0KICAgICAgICBmdG8oaSwgMSwgaykgewogICAgICAgICAgICBmW2ldID0gMTsKICAgICAgICAgICAgdHJhY2VbaV0gPSAwOwogICAgICAgICAgICBmdG8oaiwgMSwgaS0xKSB7CiAgICAgICAgICAgICAgICBpZiAoYVtqXSA8IGFbaV0gJiYgZltpXSA8IGZbal0rMSkgewogICAgICAgICAgICAgICAgICAgIGZbaV0gPSBmW2pdKzE7CiAgICAgICAgICAgICAgICAgICAgdHJhY2VbaV0gPSBqOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHByaW50ZigiJWRcbiIsICptYXhfZWxlbWVudChmKzEsIGYraysxKSk7CiAgICAgICAgaW50IHBvcyA9IG1heF9lbGVtZW50KGYrMSwgZitrKzEpLWY7CgogICAgICAgIGFucy5jbGVhcigpOwogICAgICAgIGludCB1ID0gcG9zOwogICAgICAgIHdoaWxlICh0cmFjZVt1XSAhPSAwKSB7CiAgICAgICAgICAgIHUgPSB0cmFjZVt1XTsKICAgICAgICAgICAgYW5zLnBiKGFbdV0uaWQpOwogICAgICAgIH0KICAgICAgICBmb3JkaXQocml0LCB2ZWN0b3I8aW50PiwgYW5zKSBwcmludGYoIiVkICIsICpyaXQpOwogICAgICAgIHByaW50ZigiJWRcbiIsIGFbcG9zXS5pZCk7CiAgICB9CgogICAgcmV0dXJuIDA7Cn0K