P9390 Marigold

Description

There is a 12-digit decimal number $X$. You only know that the number formed by its last 6 digits is $Y$. You are also given an integer $Z$. Among all possible $X$, you need to find the minimum value of $\lvert X - Z \rvert$. Note that $X$, $Y$, and $Z$ have no leading zeros (that is, the most significant digit is not $0$). Also, $X$ must have exactly 12 digits and $Y$ must have exactly 6 digits.

Input Format

The first line contains two integers $Y, Z$.

Output Format

The first line contains one integer, the minimum value of $\lvert X - Z \rvert$.

Explanation/Hint

**Sample #1 Explanation** Let $X = 123455987654$. The minimum value of $\lvert X - Z \rvert$ can be $135802$. --- **Sample #2 Explanation** Let $X = 100000428571$. The minimum value of $\lvert X - Z \rvert$ can be $99999714286$. --- **Constraints** For all testdata: $100000 \leq Y \leq 999999$, $0 \leq Z \leq 10^{12}$. | Subtask ID | $Z \leq$ | Special Constraint | Score | | :----------------: | :--------: | :----------------: | :---: | | $\text{Subtask 1}$ | $0$ | $Y = 142857$ | $25$ | | $\text{Subtask 2}$ | $0$ | None | $25$ | | $\text{Subtask 3}$ | $999999$ | None | $25$ | | $\text{Subtask 4}$ | $10^{12}$ | None | $25$ | --- ![](https://cdn.luogu.com.cn/upload/image_hosting/ibn2l6eb.png) Translated by ChatGPT 5