#include #include #include #include using namespace std; int main() { int n, m; scanf("%d %d", &n, &m); while (n > 0) { int res[n], top[m]; memset(top, 0, sizeof(top)); vector > ord; int id, mn, mx, mid; bool ok = true; for (int i = 0; i < n; i ++) { scanf("%d", &id); mn = 0; mx = m - 1; while (mn <= mx) { mid = (mn + mx) / 2; if (top[mid] > id) { mn = mid + 1; } else { mx = mid - 1; } } if (mn >= m) { ok = false; } else { res[i] = mn + 1; top[mn] = id; ord.push_back(pair(id, mn + 1)); } } if (ok) { sort(ord.begin(), ord.end()); printf("%d", res[0]); for (int i = 1; i < n; i ++) { printf(" %d", res[i]); } printf("\n"); printf("%d", ord[0].second); for (int i = 1; i < n; i ++) { printf(" %d", ord[i].second); } printf("\n"); } else { printf("Transportation failed\n"); } scanf("%d %d", &n, &m); } return 0; }