The Strongest Build Solution Codeforces Educational Round 144

The Strongest Build Solution Codeforces Educational Round 144

Ivan is playing yet another roguelike computer game. He controls a single hero in the game. The hero has nn equipment slots. There is a list of cici items for the ii-th slot, the jj-th of them increases the hero strength by ai,jai,j. The items for each slot are pairwise distinct and are listed in the increasing order of their strength increase. So, ai,1<ai,2<<ai,ciai,1<ai,2<⋯<ai,ci.

For each slot Ivan chooses exactly one item. Let the chosen item for the ii-th slot be the bibi-th item in the corresponding list. The sequence of choices [b1,b2,,bn][b1,b2,…,bn] is called a build.

The strength of a build is the sum of the strength increases of the items in it. Some builds are banned from the game. There is a list of mm pairwise distinct banned builds. It’s guaranteed that there’s at least one build that’s not banned.

What is the build with the maximum strength that is not banned from the game? If there are multiple builds with maximum strength, print any of them.

Input

The first line contains a single integer nn (1n101≤n≤10) — the number of equipment slots.

The ii-th of the next nn lines contains the description of the items for the ii-th slot. First, one integer cici (1ci21051≤ci≤2⋅105) — the number of items for the ii-th slot. Then cici integers ai,1,ai,2,,ai,ciai,1,ai,2,…,ai,ci (1ai,1<ai,2<<ai,ci1081≤ai,1<ai,2<⋯<ai,ci≤108).

The sum of cici doesn’t exceed 21052⋅105.

The next line contains a single integer mm (0m1050≤m≤105) — the number of banned builds.

Each of the next mm lines contains a description of a banned build — a sequence of kk integers b1,b2,,bkb1,b2,…,bk (1bici1≤bi≤ci).

The builds are pairwise distinct, and there’s at least one build that’s not banned.

Output

Print the build with the maximum strength that is not banned from the game. If there are multiple builds with maximum strength, print any of them.

Examples
input

Copy
3
3 1 2 3
2 1 5
3 2 4 6
2
3 2 3
3 2 2
output

Copy
2 2 3 
input

Copy
3
3 1 2 3
2 1 5
3 2 4 6
2
3 2 3
2 2 3
output

Copy
1 2 3
input

Copy
3
3 1 2 3
2 1 5
3 2 4 6
2
3 2 3
2 2 3
output

Copy
3 2 2
input

Copy
4
1 10
1 4
1 7
1 3
0
output

Copy
1 1 1 1

Leave a Comment