FACEFRND - Friends of Friends

Bob uses a social networking site almost all the time. He was wondering what are Friends of Friends in that social networking site? If “X” is his friend, and “Y” is X’s friend but “Y” is not his friend, then “Y” is called his friend of friend. You have to find how many friends of friends Bob has. (Each user in that social networking site has a unique 4-digit ID number)

Input

First line contains a integer “N” (1 ≤ N ≤ 100) the number of friends in Bob's Profile. Then follow N lines.

First Integer in each line is the ID number of Bob's friend, then an integer “M” (1 ≤ M ≤ 100) is the number of people in his friend list. Then follow M integers in that line, denoting the ID number of friends in his friend list (excluding Bob). 

Output

Output a single integer denoting Bob's number of friends of friends.

Example

Input:
3
2334 5 1256 4323 7687 3244 5678
1256 2 2334 7687
4323 5 2334 5678 6547 9766 9543

Output:
6

Added by:Ankit Kumar Vats
Date:2011-10-20
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All
Resource:Own Problem

hide comments
2017-02-09 09:49:39
Comment often mislead, first try to understand the question on your own, and then look at comment.Friends There can be Be ID like 0000 , 0001 , 0002 , 0323 , 0123 , 0023 , 0067, 0001 , 0002. Because the question said id is is unique 4-digit ID number. And this is the thing many people are missing, i can say that there is no ID between 1-100 or anything like that , all there is 4 digit unique id , like 0001 , 0002 .

Thanks To @chinmoy17_c all 4 digits in the ID need not necessarily be non-zero...


Think Simple and original , do not see how others do it , think on your own , and devise your own method.


Last edit: 2017-02-09 10:14:37
2016-12-28 13:04:04
Simple one done without map :-)
2016-12-27 19:58:58
Thanks @sidthe1 there is indeed an id between 1 and 30
2016-12-21 19:26:52
Nice Problem and lots to learn.
Can be done using vectors in 0.00s
2016-12-13 14:22:44
there is an ID between 0 and 99 :(
2016-11-22 16:42:39
Got AC :-) after using a array.
2016-11-11 16:14:29
no need of sorting !! my 51st ... AC in first go :)
2016-10-26 12:43:53 E Naveen Kumar
AC in a GO....!!!

Last edit: 2016-10-26 12:44:50
2016-09-02 20:58:10
AC in one go :) ezy one
2016-08-04 16:25:11 giriprasad kemburu
Ac in one go...:):):)
Easy with collections(Treeset) java.
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.