Bipartite Blanket

Count vertex subsets of a weighted bipartite graph whose total weight is at least t and that some matching covers completely.

Hard8Dynamic programmingBit manipulationCombinatoricsGraphNo attempts yetTime limit3sMemory limit512 MB

Problem

In a bipartite graph the vertices are split into two disjoint sets AA and BB, and every edge joins one vertex of AA with one vertex of BB. A matching MM is a set of edges in which no two edges share a vertex. A matching MM blankets a set of vertices VV when every vertex of VV is an endpoint of some edge of MM.

You are given a bipartite graph in which every vertex carries a positive integer weight. The weight of a set of vertices is the sum of the weights of its vertices.

You are also given an integer threshold tt. Count the sets of vertices VV whose weight is at least tt and which are blanketed by at least one matching. Here VV is a subset of ABA \cup B, and two different subsets count separately.

Input

The first line contains the number of vertices nn in AA and the number of vertices mm in BB, separated by a space (1n,m201 \le n, m \le 20). The vertices of AA are a1,a2,,ana_1, a_2, \dots, a_n and the vertices of BB are b1,b2,,bmb_1, b_2, \dots, b_m.

Each of the next nn lines contains mm characters that describe the edges. The jj-th character of the ii-th line is 1 if there is an edge between aia_i and bjb_j, and 0 otherwise.

The next line contains nn integers v1,v2,,vnv_1, v_2, \dots, v_n (1vk100000001 \le v_k \le 10\,000\,000), where vkv_k is the weight of aka_k. The line after that contains mm integers w1,w2,,wmw_1, w_2, \dots, w_m (1wk100000001 \le w_k \le 10\,000\,000), where wkw_k is the weight of bkb_k.

The last line contains the integer tt (1t4000000001 \le t \le 400\,000\,000).

Output

Print on one line the number of vertex sets whose weight is at least tt and that are blanketed by some matching.

Hint

In the first example the subset {a1,a2,b2,b3}\{a_1, a_2, b_2, b_3\} is blanketed by the matching {(a1,b2),(a2,b3)}\{(a_1, b_2), (a_2, b_3)\} and has weight 21. The subsets {a3,b2,b3}\{a_3, b_2, b_3\} and {a2,a3,b2,b3}\{a_2, a_3, b_2, b_3\} are both blanketed by the matching {(a2,b3),(a3,b2)}\{(a_2, b_3), (a_3, b_2)\} and have weights 21 and 23. Every other subset either weighs less than 21 or is blanketed by no matching. For instance {a2,a3,b1,b3}\{a_2, a_3, b_1, b_3\} has weight 26, but no matching blankets it, so it is not counted.