luogu#P5123. [USACO18DEC] Cowpatibility G

[USACO18DEC] Cowpatibility G

Background

On 2025/4/9, two groups of hack testdata were added (@Starrykiller).

Problem Description

Research shows that one factor matters more than anything else in whether two cows can get along as friends—whether they like the same ice cream flavor.

Farmer John has NN cows (2N5×1042 \le N \le 5 \times 10^4). Each cow lists her five favorite ice cream flavors. To make the list more concise, each possible flavor is represented by a positive integer ID\texttt{ID} not exceeding 10610^6. If two cows' lists share at least one common ice cream flavor, then they can get along.

Please compute the number of pairs of cows that cannot get along.

Input Format

The first line contains NN. The next NN lines each contain 55 integers (all distinct), representing one cow’s favorite ice cream flavors.

Output Format

Output the number of pairs of cows that cannot get along.

4
1 2 3 4 5
1 2 3 10 8
10 9 8 7 6
50 60 70 80 90
4

Hint

Here, cow 44 cannot get along with any of cows 11, 22, or 33, and cow 11 and cow 33 also cannot get along.

Translated by ChatGPT 5