405297: GYM101875 F Number Preference

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

F. Number Preferencetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Laërdos is organizing a party and invited all his N mathematician friends. He decided to decorate his party with positive integers, ranging from 1 to 1018. He's now struggling to choose the integers that he's going to use because his friends are very picky about numbers.

He talked to all his friends beforehand, and they all told him their preferences. Each one of them described their preference by either:

  1. Listing the integers that they like, meaning that they hate all other integers; or
  2. Listing the integers that they hate, meaning that they like all other integers.

He wants to know how many integers he can use that will please all his friends.

Input

The first line of the input contains a single integer N (1 ≤ N ≤ 105) indicating the number of friends that were invited to the party.

Each of the following N lines describes the preferences of each friend. The i-th line contains the preferences of the i-th friend and has the following format:

t s l1 ... ls

t is 1 if the friend listed the integers that he or she likes and 2 otherwise. s (1 ≤ s ≤ 105) indicates the number of integers that were listed. It is followed by s integers l1... ls (1 ≤ lj ≤ 1018), indicating the integers that the friend listed.

The total number of integers listed by all friends is not greater than 2 × 105.

Output

Output a single integer, the number of integers that all Laërdos' friends like.

ExamplesInput
3
1 3 1 2 3
2 1 1
1 3 1 2 4
Output
1
Input
5
1 3 1 2 3
1 3 1 2 4
1 3 1 2 5
1 3 1 2 7
2 1 8
Output
2
Input
2
1 2 10 11
2 2 10 11
Output
0

Source/Category

加入题单

算法标签: