Conspiracy

No attempts yetTime limit3sMemory limit128 MB

Problem

Hostile Bitotia has attacked Byteotia and occupied a large part of its territory. King Byteasar of Byteotia wants to organize a resistance movement in the occupied area, so he begins by choosing the people who will form its core. These chosen people must be split into two groups:

  • the conspirators, who will operate directly in the occupied territory, and
  • the support group, who will operate inside free Byteotia.

The split has to satisfy all of the following rules:

  • Every two people in the support group know each other, so the group can cooperate efficiently.
  • No two conspirators know each other.
  • Neither group is empty: there is at least one conspirator and at least one member of the support group.

Byteasar wants to know how many ways there are to split the chosen people into these two groups, and above all whether any valid split exists at all. Help him find this number.

Input

The first line contains one integer nn (2n50002 \le n \le 5000), the number of people involved. The people are numbered from 11 to nn.

Each of the next nn lines describes the acquaintances of one person. The ii-th of these lines begins with an integer kik_i (0kin10 \le k_i \le n-1), the number of people that person ii knows, followed by kik_i integers ai,1,ai,2,,ai,kia_{i,1}, a_{i,2}, \dots, a_{i,k_i} given in increasing order (1ai,jn1 \le a_{i,j} \le n, ai,jia_{i,j} \ne i), the numbers of those acquaintances.

Acquaintance is mutual: if person xx appears among person ii's acquaintances, then person ii appears among person xx's acquaintances.

Output

Print one integer: the number of ways to split the chosen people into the conspirators and the support group so that all the rules above hold. If no valid split exists, print 00.

Hint

In the example above there are three valid splits. The group of conspirators can be persons 11 and 44, persons 22 and 44, or person 44 alone.