Marbles in Three Baskets

Time limit1sMemory limit128 MB

Problem

Each of three baskets contains a certain number of marbles. In one move you choose one basket as the source and another basket as the destination, then move from the source into the destination exactly as many marbles as the destination already holds, thereby doubling the number of marbles in the destination. This move is allowed only when the source holds at least as many marbles as the destination.

You want to make all three baskets hold the same number of marbles while using the fewest possible moves. Find that minimum number of moves. If it is impossible to make all three baskets equal by any sequence of moves, you must report that instead.

Input

Each line of input describes one instance of the problem: three positive integers separated by single spaces, giving the initial numbers of marbles in the three baskets. The sum of the three integers is at most 60.

A line containing three zeros signals the end of input and is not processed.

Output

For each instance, print on its own line the minimum number of moves needed to make all three baskets equal. If no sequence of moves can make them equal, print -1 instead.