Downtown

0

0 votes
Medium
Problem

Downtown is the most recent hit of Balvin and Annita, the problemsetter was hearing this amazing song when he wrote this statement.

The countries have preferences about the musicians and the musicians have preferences about the countries, this is due to the people from a country likes the music of the composers in a distinct way, and the musicians likes to go to some countries in some order of preference.

MusicForHire bussines group are so worried about this situation, they have a group of musicians and they send a musician to a country only if the country accept and the musician ask for it.

  • A country can reject an accepted musician.

  • A rejected musician can't ask again to country where is reject.

The musician-country deal works in the following way, the available musician with highest ranking ask for to a country, followed by the second-highest ranked available musician, and so.

A musician is considered available if is not accepted until that moment by a country.

MusicForHire wants to maximize their benefits due to if the group send a top 2 musician preference of a country to that country, the country will pay the half part of the contract, if the group send a top 3 preference of a country to that country, the country will pay the third part of the contract, that works in the musician-company way too, if a musician go to some country while more dislike the country more money will receive, so they ask you to help with this task such a way the bussines group have the maximum possible benefit.

Obviously, a musician must have a country asigned.

Input

You will receive an integer C and M ( 1MC1000 ) in the first line, separated by a space, the number of countries and the musicians, respectively.

The next C lines, contains M integers, the ids of musician favourites of the country in descendant order of preference, separated by a space.

The next M lines contains an integer R ( 1RM ) representing her/him rating followed by C integers separated by a space, the countries favourites in descendant order of preference, no one musician have the same rating of other musician.

Output

You should print M integers separated by a space, representing the country where the musician Mi should be go.

Time Limit: 1.5
Memory Limit: 256
Source Limit:
Editor Image

?