#K53767. Minimum Operations to Make Array Beautiful

    ID: 29605 Type: Default 1000ms 256MiB

Minimum Operations to Make Array Beautiful

Minimum Operations to Make Array Beautiful

You are given an array of n integers. An array is defined as beautiful if there exists at least one even number that is greater than or equal to every other element in the array. In other words, an array is beautiful if there exists an even integer \( x \) such that \( x \geq a_i \) for all \( i \) (where \( a_i \) are the elements of the array).

You are allowed to perform a series of operations. In one operation, you can choose any odd number from the array and double it. Note that when an odd number is doubled, it becomes even. Your task is to determine the minimum number of operations needed to make the array beautiful. If the array is already beautiful, the answer is 0.

Example:

  • For the array [3, 5, 7, 8]: The number 8 is even and \(8 \geq 7\) (the maximum element), so the array is already beautiful. The answer is 0.
  • For the array [1, 3, 9, 7, 5]: There is no even number meeting the condition. By doubling 1 (or any odd number), you can get 2 which might be enough if \(2 \geq 9\) – however, you need to double several times. The minimum number of operations required, in this case, is 1.

Formally, if no even element \( x \) exists with \( x \geq \max(a) \), then for each odd element \( v \) you can determine the minimum number of doubling operations (each operation multiplies \( v \) by 2) required so that \( 2^k \times v > \max(a) \) (note that after one doubling, \( 2\times v \) is even), and you need to output the minimum \( k \) among all odd elements.

inputFormat

The input is read from stdin and consists of two lines:

  • The first line contains an integer \( n \) \( (1 \le n \le 10^5) \), the number of elements in the array.
  • The second line contains \( n \) space-separated integers \( a_1, a_2, \dots, a_n \) \( (1 \le a_i \le 10^9) \), representing the array elements.

outputFormat

Output a single integer to stdout — the minimum number of operations required to make the array beautiful.

## sample
4
3 5 7 8
0

</p>