Under construction

Still being built. Things may change

Stage Lighting

Time limit2sMemory limit512 MB

Summary
For each start i, find the smallest r such that some subset of projectors i to r, with pairwise disjoint connector sets, has total power at least Z.
Level

Hard8 of 10

Topics
Sliding window, Bit manipulation, Dynamic programming
Solved
No attempts yet

Problem

nn projectors are installed along a stage, numbered from 1 to nn from left to right. Projector ii has power pip_i. The stage counts as lit if the total power of the switched-on projectors is at least ZZ.

Each working projector must be connected to a set of connectors. There are kk different connectors in total. Projector ii has kik_i outputs and must be connected to connectors ai,1,ai,2,…,ai,kia_{i,1}, a_{i,2}, \dots, a_{i,k_i}. At any moment, at most one projector can be connected to a given connector.

For each ii from 1 to nn, find the minimum rir_i such that, among projectors numbered from ii to rir_i inclusive, you can choose a subset of projectors to run at the same time so that the stage is lit.

Input

The first line contains three integers nn, kk, and ZZ (1≤n≤1051 \le n \le 10^5, 1≤k≤81 \le k \le 8, 1≤Z≤1091 \le Z \le 10^9). The second line contains nn integers p1,…,pnp_1, \dots, p_n (1≤pi≤1091 \le p_i \le 10^9). The next nn lines describe the connectors. Line ii contains kik_i (1≤ki≤k1 \le k_i \le k) followed by kik_i distinct integers ai,1,…,ai,kia_{i,1}, \dots, a_{i,k_i} (1≤ai,j≤k1 \le a_{i,j} \le k).

Output

Print nn lines. On line ii, print rir_i if it exists, and −1-1 otherwise.

Examples1

  1. Example 1

    Input
    6 3 6
    3 1 3 5 6 4
    1 2
    1 3
    1 1
    1 2
    3 1 2 3
    2 1 3
    
    Expected output
    3
    4
    4
    5
    5
    -1