Two IP Cameras
Contest: Kotlin Heroes: Episode 4
Difficulty rating: 2300
Tags: *special, math, number theory

You have two IP cameras of the same model. Each camera can take photos starting from some moment of time with a fixed period. You can freely choose the starting moment but you can choose the period only as one of $$$k$$$ values $$$p_1, p_2, \dots, p_k$$$ which are chosen by the camera's manufacturer.

You have $$$n$$$ moments of interest $$$x_1, x_2, \dots, x_n$$$. You'd like to configure both cameras in such a way that at least one camera will take a photo in each of these moments. Configuring the camera means setting the moment when it takes the first photo and the gap between two consecutive photos (which should be one of the values $$$p_1, p_2, \dots, p_k$$$). It's not a problem for you that cameras can take photos at other moments of time — you only care about moments of interest.

Input format:
The first line contains two integers $$$k$$$ and $$$n$$$ ($$$1 \le k \le 10^5$$$; $$$2 \le n \le 10^5$$$) — the number of periods to choose and the number of moments of interest.

The second line contains $$$k$$$ integers $$$p_1, p_2, \dots, p_k$$$ ($$$1 \le p_1 < p_2 < \dots < p_k \le 10^6$$$) — the periods to choose in the ascending order.

The third line contains $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$1 \le x_1 < x_2 < \dots < x_n \le 10^6$$$) — the moments of interest in the ascending order.

Output format:
Print YES (case insensitive) in the first line if there is a way to configure cameras.

In the second line, print two integers $$$s_1$$$ and $$$cp_1$$$ ($$$1 \le s_1 \le 10^6$$$; $$$1 \le cp_1 \le 10^6$$$; $$$cp_1 \in \{p_1, \dots, p_k\}$$$) — the starting moment and the period for the first camera. The period should be one of the given periods.

In the third line, print two integers $$$s_2$$$ and $$$cp_2$$$ ($$$1 \le s_2 \le 10^6$$$; $$$1 \le cp_2 \le 10^6$$$; $$$cp_2 \in \{p_1, \dots, p_k\}$$$) — the starting moment and the period for the second camera. The period should be one of the given periods.

If there is no way to configure cameras, print NO (case insensitive). If there are multiple ways, you may print any of them.

Constraints:
Time limit: 3.0 s
Memory limit: 256.0 MB

Example input:
3 5
3 5 7
1 4 5 7 12

Example output:
YES
1 3
5 7

Example input:
3 2
1 2 3
1 10

Example output:
YES
1 1
10 1

Editorial:
Since there are only two cameras, in each triple of interesting moments there exists a pair of them which are photographed by the same camera. For example, let's take three moments $$$x_1$$$, $$$x_2$$$ and $$$x_3$$$, and check three cases:
• $$$x_1$$$ and $$$x_2$$$ are photographed by the same camera;
• $$$x_1$$$ and $$$x_3$$$ are photographed by the same camera;
• $$$x_2$$$ and $$$x_3$$$ are photographed by the same camera.
Suppose moments $$$a$$$ and $$$b$$$ are photographed by the same camera. Then its period must be a divisor of $$$b - a$$$. Let's check all values in $$$[p_1, p_2, \dots, p_k]$$$ and try each divisor of $$$b - a$$$ as the period for the first camera (and $$$a$$$ as the starting moment for it). Numbers not exceeding $$$10^6$$$ have up to $$$240$$$ divisors, so if we are able to check each divisor in time $$$O(n + k)$$$, then we'll obtain a working solution.
To check the given period and starting moment for the first camera, find all interesting moments that aren't photographed by it (let these moments, listed in ascending order, be $$$[z_1, z_2, \dots, z_m]$$$). The starting moment for the second camera should be $$$z_1$$$, and its period should be a divisor of $$$z_2 - z_1$$$, $$$z_3 - z_2$$$, ..., $$$z_m - z_{m - 1}$$$. We can find the greatest common divisor of these pairwise differences (denote it as $$$g$$$), and check every possible period to find the one which divides $$$g$$$. If we find a divisor of $$$g$$$ in $$$[p_1, \dots, p_k]$$$, then it should be the period for the second camera, and the problem is solved.