#P9390. Minimum Difference in 12-Digit Number Reconstruction
Minimum Difference in 12-Digit Number Reconstruction
Minimum Difference in 12-Digit Number Reconstruction
Given a 12-digit decimal number \(X\) whose last six digits form the number \(Y\). You are also given an integer \(Z\). Your task is to find the minimum value of \( |X - Z| \) among all 12-digit numbers \(X\) that end with \(Y\).
Note:
- \(X\), \(Y\), and \(Z\) have no leading zeros (i.e., the most significant digit is non-zero).
- \(X\) has exactly 12 digits and \(Y\) has exactly 6 digits.
Mathematically, any valid (X) can be represented as:
[ X = k \times 10^6 + Y, \quad \text{where } k \in [10^5, 999999]. ]
Your task is to output the minimum absolute difference \( |X-Z| \) over all possible valid \(X\).
inputFormat
The input consists of two space-separated integers: (Y) and (Z). (Y) is a six-digit number (with no leading zeros) and (Z) is an integer (also without leading zeros).
outputFormat
Output a single integer representing the minimum absolute difference ( |X-Z| ) where (X) is a valid 12-digit number ending with (Y).
sample
123456 100000123456
0