Common between us

2.3

3 votes
Very-Easy
Problem

Janardhan bhaiya has intense crush on N girls :p but he is bored as he develops feelings for new girl on each day. So he wants to find perfect girl before searching perfect girl he wants to know the common characteristics between all of his N crushes.

You are given N rows first element of ith row ( ai ) represents number of characteristics ith crush possess. Next ai integers represents the characteristics id.

You have to print the characteristics id which are present in all of the crushes in ascending order.

Note: characteristics id in row may or may not be distinct.

Input:
First line of input is N.
Next each N lines will contain first integer ai and followed by ai space separated integers each representing characteristics id.
Output:
Print the common characteristics id in all of the rows in ascending order if non of the id's are common then print -1.
Constraints:
1 <= N <= 103
1 <= characterstic id <= 103
1 <= sum of all ai <= 106

Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?