#C10838. Count Similar Books

    ID: 40087 Type: Default 1000ms 256MiB

Count Similar Books

Count Similar Books

You are given a collection of n books. Each book has a unique identifier and is associated with one or more topics. Two books are considered similar if they share at least one common topic.

Your task is to compute the number of distinct pairs of books that are similar. A pair of books \((i,j)\) is considered the same as \((j,i)\), so each pair should be counted only once.

Example: If one book covers topics "history" and "math" and another covers "history" and "art", they form a similar pair because they both have the topic "history".

inputFormat

The first line of input contains a single integer \(n\) representing the number of books.

Each of the following \(n\) lines describes one book. Each line begins with an integer representing the book's ID, followed by an integer \(k\) which denotes the number of topics for that book. Then follow \(k\) strings, each representing a topic.

All input is provided via standard input (stdin).

outputFormat

Output a single integer representing the number of pairs of books that share at least one common topic. The result should be written to standard output (stdout).

## sample
4
1 2 history math
2 2 science math
3 1 art
4 2 history art
3

</p>