atcoder#ABC255C. [ABC255C] ±1 Operation 1

[ABC255C] ±1 Operation 1

Score : 300300 points

Problem Statement

You are given an integer XX. The following action on this integer is called an operation.

  • Choose and do one of the following.- Add 11 to XX.
    • Subtract 11 from XX.

The terms in the arithmetic progression SS with NN terms whose initial term is AA and whose common difference is DD are called good numbers. Consider performing zero or more operations to make XX a good number. Find the minimum number of operations required to do so.

Constraints

  • All values in input are integers.
  • 1018X,A1018-10^{18} \le X,A \le 10^{18}
  • 106D106-10^6 \le D \le 10^6
  • 1N10121 \le N \le 10^{12}

Input

Input is given from Standard Input in the following format:

XX AA DD NN

Output

Print the answer as an integer.

6 2 3 3
1

Since A=2,D=3,N=3A=2,D=3,N=3, we have S=(2,5,8)S=(2,5,8). You can subtract 11 from XX once to make X=6X=6 a good number. It is impossible to make XX good in zero operations.

0 0 0 1
0

We might have D=0D=0. Additionally, no operation might be required.

998244353 -10 -20 30
998244363
-555555555555555555 -1000000000000000000 1000000 1000000000000
444445