cswork / OAOpen practice workspace

SalesforceOA #8

Count Minimum Operations to Reduce Dimensions

Estimated MediumJudge-ready

Topics (AI-labelled)Bits & MathGreedy

Each fold is made along a crease parallel to one side and need not be in the middle; it changes only the corresponding dimension, and the target size is not rotated. One fold can turn a length L into any length in [L/2,L). Find the minimum number of folds needed to reach exactly h1,w1.

Input

One line with h w h1 w1. The original text guarantees h1≤h and w1≤w and gives no numeric upper bound; on this site all four are integers in 1..10⁹.

Output

Output the minimum number of folds.

Example 1

Input:

8 4 6 1

Output:

3

Example 2

Input:

5 7 5 7

Output:

0

Example 3

Input:

9 9 1 1

Output:

8

Example notes

The answers are 3, 0, and 8; in the first example, height 8 can be folded to 6 in one fold, so folds must not be restricted to folding exactly in half.

Editorial

Loading solution…