Criptomonede

Time limit: 0.8s Memory limit: 64MB Input: Output:

Gomory and Hu have started investing in cryptocurrencies. On their investment plan there are nn of the most popular cryptocurrencies known to them.

Every day, Gomory, being very passionate about investments, wants to invest 11 GH in several cryptocurrencies. Since Hu is his much more careful and responsible friend, he allows Gomory to choose only a subset of these investments.

At the end of their investment plan, which lasts kk days, the two calculate their profit. Since they are very smart, they figured out how the cryptocurrency market works and how they can compute their profit. Thus, they realized that the final profit is the product of the GH units invested in each cryptocurrency.

Because they have such an exciting life, they will try all possible ways of investing, and at the very end they will count the money obtained from the entire process. The two ask for your help and ask you to compute how rich they will be.

Task

Formally, you are given nn and kk sequences of the form: mim_i, pip_i, ai,1a_{i, 1}, ai,2a_{i, 2}, \ldots, ai,mia_{i, m_i} (1ik)(1 \le i \le k).

Starting from a zero array of length nn, for each ii, a subsequence SiS_i of exact size pip_i is chosen from the array aia_i, and the elements at the positions in SiS_i are incremented by 11 in the array of length nn. After performing the kk operations, the product of the elements of the array is computed.

You are asked to output the sum of the products of the elements of the array modulo 109+710^9 + 7, over all possible ways of choosing the subsequences during the kk operations.

Input Data

On the first line, the numbers nn and kk are read, in this order, with the meaning from the statement.

On the next kk lines, the parameters for the kk days are given, in the following order: mim_i, pip_i, ai,1a_{i, 1}, ai,2a_{i, 2}, \ldots, ai,mia_{i, m_i}.

Output Data

You must output a single number representing the sum of the products of the elements of the final array modulo 109+710^9+7, considering all possible ways of choosing the subsequences during the kk operations.

Constraints

  • 1n141 \le n \le 14
  • 1k201 \le k \le 20
  • 1pimin1 \le p_i \le m_i \le n
  • 1ai,1<ai,2<<ai,min1 \le a_{i, 1} < a_{i, 2} < \ldots < a_{i, m_i} \le n
# Points Restrictions
1 10 n5n \le 5, k5k \le 5
2 15 pi=1p_i = 1
3 30 n11n \le 11
4 45 No additional constraints

Example

stdin

3 2
3 2 1 2 3
2 2 2 3

stdout

4

Explanation

In the given example, there are three possible final configurations:

  1. We choose on the first day (1,2)(1 , 2), and on the second day (2,3)(2, 3). The final array will be [1,2,1][1,2,1], and the product of the elements is 22.
  2. We choose on the first day (1,3)(1 , 3), and on the second day (2,3)(2, 3). The final array will be [1,1,2][1,1,2], and the product of the elements is 22.
  3. We choose on the first day (2,3)(2 , 3), and on the second day (2,3)(2, 3). The final array will be [0,2,2][0,2,2], and the product of the elements is 00.

Thus, the answer is 2+2+0=42 + 2 + 0 = 4.

Log in or sign up to be able to send submissions!