#P1466F. Euclid's nightmare

    ID: 5717 Type: RemoteJudge 2000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>bitmasksdfs and similardsugraphsgreedymathsortings*2100

Euclid's nightmare

No submission language available for this problem.

Description

You may know that Euclid was a mathematician. Well, as it turns out, Morpheus knew it too. So when he wanted to play a mean trick on Euclid, he sent him an appropriate nightmare.

In his bad dream Euclid has a set SS of nn mm-dimensional vectors over the Z2\mathbb{Z}_2 field and can perform vector addition on them. In other words he has vectors with mm coordinates, each one equal either 00 or 11. Vector addition is defined as follows: let u+v=wu+v = w, then wi=(ui+vi)mod2w_i = (u_i + v_i) \bmod 2.

Euclid can sum any subset of SS and archive another mm-dimensional vector over Z2\mathbb{Z}_2. In particular, he can sum together an empty subset; in such a case, the resulting vector has all coordinates equal 00.

Let TT be the set of all the vectors that can be written as a sum of some vectors from SS. Now Euclid wonders the size of TT and whether he can use only a subset SS' of SS to obtain all the vectors from TT. As it is usually the case in such scenarios, he will not wake up until he figures this out. So far, things are looking rather grim for the philosopher. But there is hope, as he noticed that all vectors in SS have at most 22 coordinates equal 11.

Help Euclid and calculate T|T|, the number of mm-dimensional vectors over Z2\mathbb{Z}_2 that can be written as a sum of some vectors from SS. As it can be quite large, calculate it modulo 109+710^9+7. You should also find SS', the smallest such subset of SS, that all vectors in TT can be written as a sum of vectors from SS'. In case there are multiple such sets with a minimal number of elements, output the lexicographically smallest one with respect to the order in which their elements are given in the input.

Consider sets AA and BB such that A=B|A| = |B|. Let a1,a2,aAa_1, a_2, \dots a_{|A|} and b1,b2,bBb_1, b_2, \dots b_{|B|} be increasing arrays of indices elements of AA and BB correspondingly. AA is lexicographically smaller than BB iff there exists such ii that aj=bja_j = b_j for all j<ij < i and ai<bia_i < b_i.

In the first line of input, there are two integers nn, mm (1n,m51051 \leq n, m \leq 5 \cdot 10^5) denoting the number of vectors in SS and the number of dimensions.

Next nn lines contain the description of the vectors in SS. In each of them there is an integer kk (1k21 \leq k \leq 2) and then follow kk distinct integers x1,xkx_1, \dots x_k (1xim1 \leq x_i \leq m). This encodes an mm-dimensional vector having 11s on coordinates x1,xkx_1, \dots x_k and 00s on the rest of them.

Among the nn vectors, no two are the same.

In the first line, output two integers: remainder modulo 109+710^9+7 of T|T| and S|S'|. In the second line, output S|S'| numbers, indices of the elements of SS' in ascending order. The elements of SS are numbered from 11 in the order they are given in the input.

Input

In the first line of input, there are two integers nn, mm (1n,m51051 \leq n, m \leq 5 \cdot 10^5) denoting the number of vectors in SS and the number of dimensions.

Next nn lines contain the description of the vectors in SS. In each of them there is an integer kk (1k21 \leq k \leq 2) and then follow kk distinct integers x1,xkx_1, \dots x_k (1xim1 \leq x_i \leq m). This encodes an mm-dimensional vector having 11s on coordinates x1,xkx_1, \dots x_k and 00s on the rest of them.

Among the nn vectors, no two are the same.

Output

In the first line, output two integers: remainder modulo 109+710^9+7 of T|T| and S|S'|. In the second line, output S|S'| numbers, indices of the elements of SS' in ascending order. The elements of SS are numbered from 11 in the order they are given in the input.

Samples

Sample Input 1

3 2
1 1
1 2
2 2 1

Sample Output 1

4 2
1 2

Sample Input 2

2 3
2 1 3
2 1 2

Sample Output 2

4 2
1 2

Sample Input 3

3 5
2 1 2
1 3
1 4

Sample Output 3

8 3
1 2 3

Note

In the first example we are given three vectors:

  • 1010
  • 0101
  • 1111

It turns out that we can represent all vectors from our 22-dimensional space using these vectors:

  • 0000 is a sum of the empty subset of above vectors;
  • 01=11+1001 = 11 + 10, is a sum of the first and third vector;
  • 10=1010 = 10, is just the first vector;
  • 11=10+0111 = 10 + 01, is a sum of the first and the second vector.

Hence, T={00,01,10,11}T = \{00, 01, 10, 11\}. We can choose any two of the three vectors from SS and still be able to obtain all the vectors in TT. In such a case, we choose the two vectors which appear first in the input. Since we cannot obtain all vectors in TT using only a single vector from SS, S=2|S'| = 2 and S={10,01}S' = \{10, 01\} (indices 11 and 22), as set {1,2}\{1, 2 \} is lexicographically the smallest. We can represent all vectors from TT, using only vectors from SS', as shown below:

  • 0000 is a sum of the empty subset;
  • 01=0101 = 01 is just the second vector;
  • 10=1010 = 10 is just the first vector;
  • 11=10+0111 = 10 + 01 is a sum of the first and the second vector.