AGARTHA IS REAL#12268

AGARTHA IS REAL

You met a strange lady, she made you nervous, she took you in and gave you breakfast, and she said:

You're given integers n,x,y and , you can use the following two operations:

M-operations: Multiply by either or .

S-operations: Subtract from .

Output the minimum total cost to make equal to or output if it's impossible to make reach .

Input

The input consists of integers n,x,y and (0 \le |n| \le 2 \cdot 10^9 , 1 \le x,y,z \le 2 \cdot 10^9).

Output

The output consists of a single integer, the minimum total cost to make equal to .

Examples

Example 1

Loading
Loading

Example 2

Loading
Loading

Note

In the first test. To achieve a cost of we do:

  • Subtract from for a cost of , now n=1.

  • Multiply by for a cost of , now n=2.

  • Multiply by for a cost of , now n=4.

  • Subtract from for a cost of , now n=0.

The total cost is 1+1+2+1=5, it can be shown that there's no way to get a total cost lower than , so is the answer.

In the second test. No matter what operations we make we can't make equal to , so the answer is .

Scoring

  1. Subtask ( points) : (|n|,x,y,z \le 5)

  2. Subtask ( points) : (|n|,x,y,z \le 1000)

  3. Subtask ( points) : (|n|,x,y,z \le 10^6)

  4. Subtask ( points) : (z \le 10^6)

  5. Subtask ( points) : x = y

  6. Subtask ( points) : no additional constraints.