Intersection in First-Array Order
Find the distinct values present in both arrays.
Input
The first line contains n and m. The next two lines contain arrays A and B.
Array and query counts are between $1$ and $10^5$. Integer values are between $-10^9$ and $10^9$. Deleting a missing multiset value has no effect.
Output
Scan A from left to right and print each value that also occurs in B once, at its first occurrence.
Example
Input
7 5
3 1 3 2 5 4 2
2 3 6 4 2
Output
3 2 4
Comments