The Lost Cow#10521

The Lost Cow

1 second
128 megabytes
Easy

Farmer John has lost his prize cow, Bessie, and he needs to find her!

Fortunately, there is only one long path running across the farm, and Farmer John knows that Bessie must be somewhere along this path. If we think of the path as a number line, then Farmer John is currently at position , while Bessie is at position (which is unknown to Farmer John). If Farmer John knew Bessie's location, he could walk directly to her, traveling a distance of |x - y|. Unfortunately, it is dark outside, and Farmer John cannot see anything. The only way he can find Bessie is to walk back and forth until he eventually reaches her position.

Trying to determine the best strategy for searching, Farmer John consults the computer science literature and is somewhat amused to discover that this exact problem has not only been studied by computer scientists, but is actually known as the "Lost Cow Problem" (this is actually true!).

The recommended strategy for finding Bessie is to first move to position x+1, then reverse direction and move to position x - 2, then to position x + 4, and so on, following a "zig-zag" pattern in which each new turning point is twice as far from the initial position as the previous one. As Farmer John learned while studying algorithms for the Lost Cow Problem, this strategy guarantees that he will travel at most times the direct distance |x - y| before finding Bessie. Moreover, is the smallest possible worst-case guarantee among all possible strategies.

Farmer John would like to verify this result. Given and , compute the total distance he will travel using the zig-zag search strategy described above until he finds Bessie.

Input

Two distinct integers and . Both are in the range .

Output

Print the total distance Farmer John will travel before reaching Bessie.

Examples

Example 1

Loading
Loading