Hide

Problem F
Separated Points

You are given distinct integer points on the line: $N$ points are items and $M$ points are sensors. For a pair of items $i$ and $j$ at locations $x_i$ and $x_j$, respectively, the distance between these items is $|x_i - x_j|$. We say this pair is sensed if there is at least one sensor between them, that is if there is at least one sensor at a location $z_k$ with $\min (x_i,x_j) < z_k < \max (x_i, x_j)$.

For every integer $D$, determine how many sensed pairs of items have distance exactly $D$ between them.

\includegraphics[width=0.6\textwidth ]{separatedpoints.pdf}
Figure 1: Illustration of the first sample case. The black points are items and the white points are sensors. The dashed lines correspond to a sensed pair of points.

Input

The first line of input contains two integers $N$ ($1 \leq N \leq 400\, 000$) and $M$ ($1 \leq M \leq 400\, 000$). The second line contains $N$ integers $x_1, \ldots , x_N$ ($0 \leq x_i \leq 10^6$) indicating the locations of the items. The final line contains $M$ integers $z_1, \ldots , z_M$ ($0 \leq z_i \leq 10^6$) indicating the locations of the sensors. All $N+M$ locations will be distinct.

Output

For every integer $D$ such that there is at least one pair of sensed items at distance $D$ from each other, output a single line containing $D$ followed by the number of such pairs. These lines should be presented in ascending order of $D$.

If no pair of items is sensed, simply output none on a single line.

Sample Input 1 Sample Output 1
4 2
10 2 6 1
8 3
4 2
5 1
8 1
9 1
Sample Input 2 Sample Output 2
2 1
7 3
2
none

Please log in to submit a solution to this problem

Log in