#117Easy
Intersection of two arrays
Time: 1 s · Memory: 256 MB
- Maps and sets
Statement
You are given two arrays and . Find all distinct numbers present in both, in increasing order.
Input format
The first line contains , the second the array . The third line contains , the fourth the array . , .
Output format
The first line contains the number of common values . The second line contains those numbers in increasing order (empty if ).
Examples
Input
5 1 2 3 2 5 4 2 5 7 2
Output
2 2 5
Input
2 1 2 2 3 4
Output
0
Note
Turn both arrays into sets and take the intersection (Python — a & b). Repetitions count once: in the first example occurs twice in both arrays but once in the answer — 2 5.
For comparing every element with all others ( operations) is too slow — a set or a dictionary does it in one pass.
