A multi-stage festival has several entry stations, and each station independently scans and records the wristband ID of every attendee who passes through it during the day; within a single station's log, IDs never repeat. Festival organizers want to open an exclusive after-party to every attendee whose wristband was scanned at every single station — meaning that ID must appear in all of the stations' logs.
Given the logs from all stations, list every wristband ID that appears in all of them, sorted in ascending order.
Line 1: a single integer M — the number of stations.
Each of the next M lines describes one station's log: an integer k (the number of IDs scanned at that station) followed by k space-separated distinct positive integers — the wristband IDs scanned at that station (not necessarily given in sorted order).
A single line with every wristband ID that appears in all M stations' logs, in ascending order, space-separated. If no such ID exists, print an empty line.
k over all stations is at most 2000Example 1
Input
3 5 3 1 2 4 5 4 1 2 3 4 4 3 4 5 6
Expected
3 4
Explanation
Station 1 scanned {3,1,2,4,5}, station 2 scanned {1,2,3,4}, station 3 scanned {3,4,5,6}. ID 3 is present in all three logs, and so is ID 4; no other ID (1, 2, 5, or 6) is present in every log. Sorted ascending, the answer is "3 4".
Example 2
Input
2 3 1 2 3 3 4 5 6
Expected
(empty)Explanation
Station 1 scanned {1,2,3} and station 2 scanned {4,5,6} — the two logs share no IDs at all, so the after-party list is empty.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →