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

hide comments
atulav: 2017-12-31 12:01:58

map rocks !!!

sid00733: 2017-12-24 23:02:51

AC in one go

mpride44: 2017-12-22 19:38:26

thanx to STL...!!!
AC in one go..

sayasaiteja: 2017-12-15 08:48:36

ac in one go

mani_kota_18: 2017-12-14 19:41:14

AC in one go!!

Last edit: 2017-12-15 13:47:39
hitesh87: 2017-12-14 14:52:01

Only using visited array.

anurag31: 2017-10-27 19:42:20

these ID's can be 0001, 0002, 0045..etc

arjun8115: 2017-09-09 11:50:09

easiest one using set

ayushgupta1997: 2017-08-13 08:37:28

finally my 100th :) and 400th :) in total used 2 sets----trying to do it in other way :p

ameyanator: 2017-08-10 21:05:35

Just remember that a 4 digit id can also be 0001. Cost me 1 wa -_-

Ohh and my 50th!!! :D

Last edit: 2017-08-10 21:06:59

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