13922 - Lots of Candies   

Description

There are N kids, with ids from 1 to N, standing in a queue.
Every kid in this queue has his own candy set, a multiset of candy types that he wants to eat.
Stiff Waist Beast wants to send off these kids, so he’s going to give some candies to them.

 

 

Formally, Stiff Waist Beast will put M candies on the table one by one, the ith candy he’s going to put is of type ci. Once the candies on the table contain the candy set of the kid at the front of the queue (i.e. The kid's candy set is a subset of the candies on the table), for every type of the candy in his candy set, he’ll pick one candy of that type from the table. Notice that he'll probably have repeated candy types in his  candy set, in this case, he'll get as many candies as the number of that candy type appears in his candy set. Every candy would stay on the table until one has taken it.

 

After he’d picked all of the candies he want, he’ll leave the queue. And the next kid would move to the front of the queue, start getting candies. i.e. These kids are waiting candies in a queue, no one would start getting candies until all of the kids in front of him has got their candy set.

 

Now, Pigeon, sidekick of Stiff Waist Beast, is recording the destination of every candy. He’d like to know who had picked the ith candy, or if it was left on the table eventually. Since he’s busy on recording all of the other stuff Stiff Waist Beast is doing, which is definitely important, he’s asking you for help. It’s up to you whether help him or not, but you’ll fail this lab if you don’t :(

Some details you may want to know:

  • If there are multiple candies of the same type on the table when the kid is picking that type of candies, the kid would choose the one that has been on the table for the longest time. i.e. The one with the smallest id.
  • For each candy, you should output the id of the kid who has taken it, or 0 if nobody has.

Constraints

  • ≤ N≤ 106
  • ≤ c≤ 109
  • szi106

Subtasks

 
  1. (2/6) ≤ ≤ 100≤ ≤ 100          
  2. (2/6) ≤ ≤ 1000≤ ≤ 10000 
  3. (2/6) No additional constraints                 

Input

The first line of input contains two positive integers NM, as described in the statement.
Next, there would be N candy set, each candy set is represented by two lines, the first line contains a single positive integer szi, denoted the size of the candy set of the ith kid. The second line contains szi integers, each denoted one of the candy type in this candy set.

Next, there would be M integers, c1 cM as the statement described.

Output

Output M lines, each contains a integer, represents the desination of the candy.

Sample Input  Download

Sample Output  Download

Tags




Discuss