Bipartite Blanket#9724

Bipartite Blanket

1 second
128 megabytes
Very hard

In a bipartite graph, the nodes are divided into two disjoint sets and such that every edge connects a node from to a node from . A matching is a set of edges where no two edges share a common node. We say that a matching blankets a set of nodes if every node in is an endpoint of at least one edge in .

Each node in the bipartite graph is assigned a weight — a positive integer. The weight of a set of nodes is defined as the sum of the weights of its individual nodes.

Given an integer threshold , determine the number of distinct node sets such that the total weight of is at least and is blanketed by at least one matching .

Input

The first line contains two integers and (1 \le n, m \le 20) — the number of nodes in sets and , respectively. Let the nodes of be denoted as a_1, a_2, \ldots, a_n and the nodes of as b_1, b_2, \ldots, b_m.

The next lines each contain characters describing the edges of the graph. The -th character of the -th line is "" if there is an edge between a_i and b_j, and "" otherwise.

The following line contains integers v_1, v_2, \ldots, v_n (1 \le v_k \le 10^7) — the weights of the nodes a_1, a_2, \ldots, a_n.

The next line contains integers w_1, w_2, \ldots, w_m (1 \le w_k \le 10^7) — the weights of the nodes b_1, b_2, \ldots, b_m.

The final line contains a single integer (1 \le t \le 4 \cdot 10^8) — the weight threshold.

Output

Print the number of node sets whose total weight is at least and that are blanketed by at least one matching .

Examples

In the example, the subset \{a_1, a_2, b_2, b_3\} is blanketed by the matching \{(a_1, b_2), (a_2, b_3)\} and has a weight of .

The subsets \{a_3, b_2, b_3\} and \{a_2, a_3, b_2, b_3\} are both blanketed by the matching \{(a_2, b_3), (a_3, b_2)\}, with weights of and , respectively.

All other subsets either have a total weight less than or are not blanketed by any matching.

For instance, the subset \{a_2, a_3, b_1, b_3\} has a total weight of but is not blanketed by any matching, so it is not included in the count.

Example 2

Loading
Loading

Example 1

Loading
Loading