You are given an integer . You can perform the following three types of operations:
Decrease by .
Increase by .
If is divisible by , divide by .
Determine the minimum number of operations needed to transform the number into .
The input consists of a single integer (1 \le n \le 10^{18}).
Output a single integer representing the minimum number of operations required to make the number equal to .
Example 1
Example 2
Example 5
In the first example, you can divide by once to reach .
In the second example, you can decrease by twice, and then divide by .
Solutions that correctly handle the constraints 1 \le n \le 10^5 will earn of the total points.