#include <bits/stdc++.h>   using namespace std;   const int maxn = 310;   int g[maxn][maxn];   int best[maxn];   int a[maxn];   int ans[maxn];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         int v;         scanf( %d , &v);         g[i][v] = j;       }     }     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       best[i] = 1000;     }     for (int i = 1; i <= n; i++) {       int cura = -1;       int curb = -1;       for (int j = 1; j <= n; j++)         if (a[j] <= i) {           cura = a[j];           break;         }       for (int j = 1; j <= n; j++)         if (cura != a[j] && a[j] <= i) {           curb = a[j];           break;         }       for (int j = 1; j <= n; j++) {         int cur = cura;         if (cura == j) cur = curb;         if (cur == -1) continue;         if (g[j][cur] < best[j]) {           best[j] = g[j][cur];           ans[j] = i;         }       }     }     for (int i = 1; i <= n; i++) {       printf( %d , ans[i]);       if (i != n)         printf(   );       else         printf(  n );     }     return 0;   }   