7990: ABC255 —— C - ±1 Operation 1
[Creator : ]
Description
You are given an integer X. The following action on this integer is called an operation.
Consider performing zero or more operations to make X a good number. Find the minimum number of operations required to do so.
-
Choose and do one of the following.
- Add 1 to X.
- Subtract 1 from X.
Consider performing zero or more operations to make X a good number. Find the minimum number of operations required to do so.
Input
Input is given from Standard Input in the following format:
$X\ A\ D\ N$
$X\ A\ D\ N$
Output
Print the answer as an integer.
Constraints
All values in input are integers.
$−10^{18}≤X,A≤10^{18}$
$−10^6≤D≤10^6$
$1≤N≤10^{12}$
$−10^{18}≤X,A≤10^{18}$
$−10^6≤D≤10^6$
$1≤N≤10^{12}$
Sample 1 Input
6 2 3 3
Sample 1 Output
1
Since A=2,D=3,N=3, we have S=(2,5,8).
You can subtract 1 from X once to make X=6 a good number.
It is impossible to make X good in zero operations.
You can subtract 1 from X once to make X=6 a good number.
It is impossible to make X good in zero operations.
Sample 2 Input
0 0 0 1
Sample 2 Output
0
We might have D=0. Additionally, no operation might be required.
Sample 3 Input
998244353 -10 -20 30
Sample 3 Output
998244363
-555555555555555555 -1000000000000000000 1000000 1000000000000
444445