You have an array of length . In one operation, you can choose a number in the array and flip one of its bits, as long as the resultant number is non-negative and strictly less than . What is the minimum number of operations required to turn the array into a non-decreasing sequence?
Constraints
For all subtasks:
Input Specification
The first line contains a single integer .
The second line contains integers .
Output Specification
Output the minimum number of operations required to turn the array into a non-decreasing sequence.
Sample Input
5
10 7 8 3 4
Sample Output
3
Explanation for Sample Output
A possible final array could be , which takes moves to transition to.
Comments