The Lost Cow
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 has to be at some location on this path. If we think of the path as a number line, then Farmer John is currently at position and Bessie is currently at position (unknown to Farmer John). If Farmer John only knew where Bessie was located, he could walk directly to her, traveling a distance of . Unfortunately, it is dark outside and Farmer John can't see anything. The only way he can find Bessie is to walk back and forth until he eventually reaches her position.
Trying to figure out the best strategy for walking back and forth in his search, Farmer John consults the computer science research literature and is somewhat amused to find that this exact problem has not only been studied by computer scientists in the past, but that it is actually called the "Lost Cow Problem" (this is actually true!).
The recommended solution for Farmer John to find Bessie is to move to position , then reverse direction and move to position , then to position , and so on, in a "zig zag" pattern, each step moving twice as far from his initial starting position as before. As he has read during his study of algorithms for solving the lost cow problem, this approach guarantees that he will at worst travel times the direct distance between himself and Bessie before he finds her (this is also true, and the factor of is actually the smallest such worst case guarantee any strategy can achieve).
Farmer John is curious to verify this result. Given and , compute the total distance he will travel according to the zig-zag search strategy above until he finds Bessie.
Input
Two distinct integers and . Both are in the range .
Output
Print the distance Farmer John will travel to reach Bessie.