The sixth friend

0.6 Consider a world where a pandemic has imposed a new rule: No party
can have more than six assistants. Given the lists of friends of each
person in a group, we will call someone the sixth friend if he is not in
the top five of at least another person. Being egocentric is not an
option to avoid being the sixth friend, and therefore not being able to
attend any party!

0.4

[image]

Can you compute the number of sixth friends in a group of people?

Input

Input consists of several cases. Each case begins with the number of
people n, followed by n lines, one per person. Every line i contains the
name p_(i) of the i-th person, his number of friends f_(i), and the
names of his f_(i) friends in order, from more to less favorite.

You can assume 1 ≤ n ≤ 10⁴, that all names are different and consist of
between 1 and 10 letters, and 0 ≤ f_(i) ≤ 30. The list of friends of
each person p_(i) only includes names in {p₁, …, p_(n)}, but can contain
repeated names, including p_(i) one or more times.

For instance, among the five best friends of Joey in the sample in fact
there are only Chandler, Phoebe and Rachel. Janice is the only sixth
friend of the first case.

Output

For every case, print the number of sixth friends.

Problem information

Author: Joan Alemany

Generation: 2026-01-25T11:30:58.006Z

© Jutge.org, 2006–2026.
https://jutge.org
