Suki and Biscuit's Shared Sniffing Spots
Suki, a black curly-coated dog with a grey beard and white paws, spent the morning in the park with her friend Biscuit. Every lamp post, bench and bush in the park has a numeric id, and each dog's collar logged the id of every spot it stopped to sniff. Both logs come out sorted in non-decreasing order, and a spot sniffed several times appears several times.
Suki wants to know which sniffs they had in common. Pair up equal ids between the two logs, each
entry used at most once: if spot x appears p times in Suki's log and q times in Biscuit's
log, it is a shared spot min(p, q) times. For example, a spot appearing 3 times in one log and 2
times in the other is shared twice.
Print all shared spots, with this multiplicity, in non-decreasing order.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 2·10^5): the lengths of Suki's and
Biscuit's logs.
The second line contains n integers a_1 ≤ a_2 ≤ … ≤ a_n (1 ≤ a_i ≤ 10^9): Suki's log.
The third line contains m integers b_1 ≤ b_2 ≤ … ≤ b_m (1 ≤ b_j ≤ 10^9): Biscuit's log.
Output
On the first line print k, the number of shared spots counted with multiplicity.
On the second line print the k shared ids in non-decreasing order, separated by spaces. If k is
0, the second line is empty.
Notes
In the first example, spot 2 appears 3 times in Suki's log and twice in Biscuit's, so it is shared twice. Spot 5 appears once in Suki's log and three times in Biscuit's, so it is shared once. Spot 7 appears once in each. Spots 1, 4 and 9 appear in only one log.
In the second example the dogs never sniffed the same spot, so the answer is 0.