Under construction

Still being built. Things may change

Red button, blue button

Interview

Time limit2sMemory limit512 MB

Summary
Given (a,b), reach (c,d) using +1 on both coordinates or doubling both, with the fewest presses, or report -1.
Level

Medium6 of 10

Topics
Math, Greedy, Binary search, Implementation
Solved
No attempts yet

Problem

Yeongseon has two integers aa and bb. Hyobin has a red button and a blue button.

Pressing the red button increases each of Yeongseon's two integers by 1. Pressing the blue button multiplies each of them by 2.

Hyobin wants to press buttons until (a,b)(a, b) becomes (c,d)(c, d). Write a program that finds the smallest number of button presses.

Input

The first line contains four integers aa, bb, cc, dd. (1≤a,b,c,d≤1091 \le a, b, c, d \le 10^9)

Output

Print the smallest number of button presses that turns (a,b)(a, b) into (c,d)(c, d). If that is impossible, print -1.

Examples3

  1. Example 1

    Input
    100 1000 101 1001
    
    Expected output
    1
    
  2. Example 2

    Input
    100 1000 202 2002
    
    Expected output
    2
    
  3. Example 3

    Input
    2 2 1 1
    
    Expected output
    -1