# Розбір

The general observation for every group is that the $y$-coordinate does not matter since both coordinates do not depend on each other when performing the maneuvers (it can be seen from the formula of your new coordinate) and the only condition about reaching the Link-Cut system does not depend on $y$. Thus, the problem can be reduced to its $1$-dimensional case.

Group 1. $x_{1},y_{1},x_{2},y_{2}≥r$

In this group, there are only two cases to handle:

$s_{x}≥r$: in this case, no maneuvers are needed since you have already reached the Link-Cut system;

$s_{x}<r$: in this case, you can reach the needed $x$-coordinate using only one maneuver with the first and the second meteors. Here is why:

$x_{1},x_{2}≥r⟹2(x_{1}+x_{2}) ≥r$ (because the arithmetic mean of two numbers is at least as large as the minimal one of them);

$2(x_{1}+x_{2}) ≥r$ and $s_{x}<r⟹2(x_{1}+x_{2}) >s_{x}⟹2(x_{1}+x_{2}) −s_{x}>0$;

$2(x_{1}+x_{2}) −s_{x}>0⟹2(x_{1}+x_{2}) +2(x_{1}+x_{2}) −s_{x}>r+0>r$, and this is exactly what we need.

Thus, the answer in this group is either $0$, if your initial position is in the Link-Cut system, or $1$ otherwise.

Time and memory complexity: $O(n)$ or $O(1)$ (it is not necessary to read all the points, the first two of them are enough)

Group 2. $r,x_{i},y_{i}≤10_{5}$

Here is the observation that will be used in this and in the next groups: to reach the needed $x$-coordinate, the most optimal strategy is to alternate performing maneuvers using two leftmost meteors and two rightmost ones.

Also, there are two possible ways of using the above strategy: to begin from the left or from the right side.

Let's name the midpoint between two leftmost meteors as $a$, the midpoint between the rightmost one as $b$ and your initial position as $s$. Then:

If initially $a≤s≤b$ holds, then after the first maneuver $s$ will be either $≤a$ or $≥b$

After each maneuver, either $∣a−s∣$ or $∣b−s∣$ will increase by $b−a$, and the distance from $s$ to either $b$ or $a$ respectively will remain unchanged, depending on the side, relative to which the new maneuver is done.

Since $∣s−a∣$ and $∣s−b∣$ increases each by $b−a$ after every two maneuvers, and the side on which $s$ lays relative to $a$ and $b$ alternates after each maneuver, the needed coordinate will either be reached after a finite number of maneuvers if $a=b$, or will not be reached otherwise.

It can be seen that the number of maneuvers will be $O(r)$ in case of non-zero $b−a$. In this group, since $r≤10_{5}$, the possible solution is to simulate the process of performing maneuvers from both sides and to take the best answer out of two cases of the first maneuver.

Group 3. $r,x_{i},y_{i}≤10_{8}$

This group was added to make the fast implementations of the previous group and the quiet inaccurate implementations of the full solution get more points.

Group 4. no additional constraints

The solution for this group is based on the solution for the second one, but there is also the observation that helps to solve it a lot faster. If we write down our $x$-coordinate after each maneuver we perform and separate them by odd and even positions, two arithmetic series will be formed. That holds because the distances increase exactly by $b−a$ after every two operations, which can be considered as a step of arithmetic series. This way, the problem is being reduced to finding the index of the first arithmetic progression term that is $≥r$ (and taking the minimum such index out of two series).