Study Group


Submit solution


Points: 1
Time limit: 1.0s
Memory limit: 256M

Authors:
Problem type
Allowed languages
C, C++, Java, Python

After cramming assignments in the last week of semester, its now swotvac period, and you have to lock in! You have formed a study group with your friends, but no one has started studying yet. To set an example, you start studying on day 1. Every day after that, each person will begin studying only if at least one of their close friends began studying the day before. If none of their friends has started studying, they won't feel motivated to and will continue doomscrolling. How many of the study group has started studying by 7 days, at the end of the swotvac period?

Note: none of your friends are parasocial. Close friendships are always mutual.

Input

The first line consists of an integer n\ (1 \leq n \leq 10^4), the number of people in the study group (including yourself).

The following 2n lines come in groups of two for each person. The first line contains the person's name N, and some integer a_i, the number of close friends that person has (between 0 and \min(10, n-1)). N is between 1 and 100 characters long (inclusive), with only upper and lowercase English letters. The next line contains a_i space-separated names N, which are the friends of this person. This 2-line pattern is repeated n times, once for each person.

People can't be close friends with themselves, and all close friendships are symmetric. The first inputted person corresponds to yourself, who starts studying on day 1. Each person will have a unique name.

Output

Output how many in the study group have started studying after 7 days (including yourself). You (the first person inputted) will start studying in day 1, and everyone else will start studying one day after any of their close friends are studying.

Example

Input 1
5
Alex 2
Bob David
Bob 2
Alex Charles
Charles 2
Bob Ethan
David 1
Alex
Ethan 1
Charles
Output 1
5

We can see that everyone would start studying before 7 days.

  • Day 1: Alex (you) starts
  • Day 2: Bob and David start
  • Day 3: Charles starts
  • Day 4: Ethan starts
Input 2
9
Alex 1
Bob
Bob 2
Charles Alex
Charles 2
Ethan Bob
Ethan 2
James Charles
James 3
Ethan David Dylan
David 2
James Ben
Ben 3
Dylan David Bill
Dylan 2
James Ben
Bill 1
Ben
Output 2
8

Everyone except for Bill will start studying before the end of day 7.

  • Day 1: Alex (you) starts
  • Day 2: Bob starts
  • Day 3: Charles starts
  • Day 4: Ethan starts
  • Day 5: James starts
  • Day 6: David and Dylan start
  • Day 7: Ben starts

Comments

There are no comments at the moment.