P1571 Envious Medusa
Description
Although Miss Medusa has arrived in Beijing and received the Science and Technology Innovation Award, she is still not satisfied. The reason is that she found many people also received the Science and Technology Innovation Award, and some of them even received another award — the Special Contribution Award. The more people receive both awards, the more envious Miss Medusa becomes. So she decides to count who received both awards to know how envious she is.
Input Format
The first line contains two integers $n, m$, meaning there are $n$ people who received the Science and Technology Innovation Award and $m$ people who received the Special Contribution Award.
The second line contains $n$ positive integers, the IDs of the people who received the Science and Technology Innovation Award.
The third line contains $m$ positive integers, the IDs of the people who received the Special Contribution Award.
Output Format
Output one line: the IDs of the people who received both awards, in the same order as in the Science and Technology Innovation Award winners list.
Explanation/Hint
For $60\%$ of the testdata, $0 \leq n, m \leq 1000$, and each award recipient’s ID is $\lt 2 \times 10^9$.
For $100\%$ of the testdata, $0 \leq n, m \leq 10^5$, and each award recipient’s ID is $\lt 2 \times 10^9$.
It is guaranteed that all numbers on the second line are pairwise distinct, and all numbers on the third line are pairwise distinct.
Translated by ChatGPT 5