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?
For all subtasks:
The first line contains a single integer .
The second line contains integers .
Output the minimum number of operations required to turn the array into a non-decreasing sequence.
5 10 7 8 3 4
Explanation for Sample Output
A possible final array could be , which takes moves to transition to.