#include //#include #include #include #include #include using namespace std; //ifstream cin ("x.in"); ofstream cout ("x.out"); const int nmax = 100; const int inf = 1 << 30; int l[nmax + 1], r[nmax + 1]; bool viz[nmax + 1]; vector< int > g[nmax + 1]; string s[nmax + 1]; bool pair_up (int nod) { if (viz[ nod ]) { return 0; } viz[ nod ] = 1; for (int i = 0; i < (int)g[ nod ].size(); ++ i) { if (l[ g[ nod ][ i ] ] == 0) { r[ nod ] = g[ nod ][ i ]; l[ g[ nod ][ i ] ] = nod; return 1; } } for (int i = 0; i < (int)g[ nod ].size(); ++ i) { if (pair_up(l[ g[ nod ][ i ] ])) { r[ nod ] = g[ nod ][ i ]; l[ g[ nod ][ i ] ] = nod; return 1; } } return 0; } int main() { cin.sync_with_stdio(false); int n, k; cin >> n >> k; for (int i = 1; i <= n; ++ i) { cin >> s[ i ]; int a, b, c; a = b = c = inf; for (int j = 1; j <= k; ++ j) { cin >> c; if (a < b && b < c) { g[ i ].push_back( j ); } a = b; b = c; } } bool ok = 1; int ans = 0; while (ok) { memset(viz, 0, sizeof(viz)); ok = 0; for (int i = 1; i <= n; ++ i) { if (viz[ i ] == 0 && pair_up(i)) { ++ ans; ok = 1; } } } //cout << ans << "\n"; for (int i = 1; i <= k; ++ i) { if (r[ l[ i ] ] != i) { cout << "none"; } else { cout << s[ l[ i ] ]; -- ans; } cout << "\n"; } assert(ans == 0); return 0; }