100 atcoder#ABC114B. [ABC114B] 754
[ABC114B] 754
Score : points
Problem Statement
There is a string consisting of digits 1
, 2
, , 9
.
Lunlun, the Dachshund, will take out three consecutive digits from , treat them as a single integer and bring it to her master. (She cannot rearrange the digits.)
The master's favorite number is . The closer to this number, the better. What is the minimum possible (absolute) difference between and ?
Constraints
- is a string of length between and (inclusive).
- Each character in is
1
,2
, , or9
.
Input
Input is given from Standard Input in the following format:
Output
Print the minimum possible difference between and .
1234567876
34
Taking out the seventh to ninth characters results in , and the difference between this and is . The difference cannot be made smaller, no matter where is taken from.
Note that the digits cannot be rearranged. For example, taking out 567
and rearranging it to 765
is not allowed.
We cannot take out three digits that are not consecutive from , either. For example, taking out the seventh digit 7
, the ninth digit 7
and the tenth digit 6
to obtain 776
is not allowed.
35753
0
If 753
itself can be taken out, the answer is .
1111111111
642
No matter where is taken from, , with the difference .