~/algor $ cat problems/ikki-korsatkich-kesishma
Intersection of sorted arrays
Two integer arrays sorted in non-decreasing order are given: $a$ with $n$ elements and $b$ with $m$ elements. Find the numbers that occur in both arrays: if a number occurs $p$ times in $a$ and $q$ times in $b$, it appears in the answer $\min(p, q)$ times. Print the answer in non-decreasing order.
Input
The first line contains a positive integer $n$, the second line contains the $n$ integers of array $a$. The third line contains a positive integer $m$, the fourth line contains the $m$ integers of array $b$.
Output
The first line contains the number of common elements $k$. If $k \gt 0$, the second line contains $k$ integers separated by spaces.
Note
$1 \le n, m \le 10^{5}$
$-10^{9} \le a_{i}, b_{j} \le 10^{9}$
Examples
6 1 2 2 3 5 8 5 2 2 2 5 9
3 2 2 5
2 1 3 2 2 4
0