+1-1x2

AtCoder
IDabc188_f
Time2000ms
Memory256MB
Difficulty
Takahashi has written an integer $X$ on a blackboard. He can do the following three kinds of operations any number of times in any order: * increase the value written on the blackboard by $1$; * decrease the value written on the blackboard by $1$; * multiply the value written on the blackboard by $2$. Find the minimum number of operations required to have $Y$ written on the blackboard. ## Constraints * $1 \le X \le 10^{18}$ * $1 \le Y \le 10^{18}$ * $X$ and $Y$ are integers. ## Input Input is given from Standard Input in the following format: $X$ $Y$ [samples]
Samples
Input #1
3 9
Output #1
3

Initially, $3$ is written on the blackboard. The following three operations can make it $9$:

*   increase the value by $1$, which results in $4$;
*   multiply the value by $2$, which results in $8$;
*   increase the value by $1$, which results in $9$.
Input #2
7 11
Output #2
3

The following procedure can make the value on the blackboard $11$:

*   decrease the value by $1$, which results in $6$;
*   multiply the value by $2$, which results in $12$;
*   decrease the value by $1$, which results in $11$.
Input #3
1000000000000000000 1000000000000000000
Output #3
0

If the value initially written on the blackboard equals $Y$, print $0$.
API Response (JSON)
{
  "problem": {
    "name": "+1-1x2",
    "description": {
      "content": "Takahashi has written an integer $X$ on a blackboard. He can do the following three kinds of operations any number of times in any order: *   increase the value written on the blackboard by $1$; *   ",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc188_f"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Takahashi has written an integer $X$ on a blackboard. He can do the following three kinds of operations any number of times in any order:\n\n*   increase the value written on the blackboard by $1$;\n*   ...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments