#C10254. Maximum Unique Genres

    ID: 39439 Type: Default 1000ms 256MiB

Maximum Unique Genres

Maximum Unique Genres

You are given n packs, each containing a set of genres represented by positive integers. Your task is to determine the maximum number of unique genres that can be obtained by selecting any subset of these packs.

In other words, if you choose a subset of the available packs, you can obtain genres equal to the union of the genres in the selected packs. Formally, if the selected packs are represented by sets \(S_1, S_2, \dots, S_k\), then the answer is \(|S_1 \cup S_2 \cup \dots \cup S_k|\). If no packs are selected (or there are no packs at all), the answer is 0.

The input is provided through standard input, and the result should be written to standard output.

inputFormat

The input begins with a single integer n (\(0 \leq n \leq 10^5\)) — the number of packs. This is followed by n lines. Each of these lines contains a space-separated list of integers representing the genres in that pack. If n = 0, no further lines follow.

Example:

3
1 2
2 3
3 4

outputFormat

Output a single integer representing the maximum number of unique genres that can be obtained by selecting any subset of the packs.

Example:

4
## sample
3
1 2
2 3
3 4
4

</p>