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
2015-11-16 20:36:48 ROHIT Kumar
easy one ....my 100th completed with this :P
2015-11-02 20:15:31
some id is not of 4 digits
2015-11-01 06:04:09
some id are not of four digits...:-|
2015-10-03 11:01:47
easy one...... use array simply. my 50th........
2015-09-30 15:17:10
WATCH OUT!
the problem is simple, but has pranks that are not easy to see, follow more test cases:
2
2334 1 2022
2022 1 2334
Out: 0
2
2334 1 7687
4323 1 7687
Out: 1

2
1013 3 7687 4440 1520
4044 2 7687 4440
Out: 3

2
1013 3 7687 7687 7687
4044 3 7687 7687 7687
Out: 1

There is no problem with the input data , just make sure your program validates these test cases ; they helped me ! And remember : count the friends of my friends ( without repeating them and not counting my friends )
2015-09-18 15:24:53 Rahul yadav
simply use array ..AC in one go
2015-09-12 05:54:37 sakshi
How this problem can be solved using just two line?..how is their an id which is not of four digits?
2015-09-03 23:47:43 topke
Something is wrong with this input. I've allocated 10006 array size and still it gives me out of bounds error.
2015-08-29 15:09:10 sneh sajal
juss array n sorting :)
2015-08-24 18:28:43
Can be done through arrays also... :) good question
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.