Score : 800 points
There are N positive integers A_1, A_2, ..., A_N. Takahashi can perform the following operation on these integers any number of times:
Notice that he multiplies it by minus two.
He would like to make A_1 \leq A_2 \leq ... \leq A_N holds.
Find the minimum number of operations required. If it is impossible, print -1
.
Input is given from Standard Input in the following format:
N A_1 A_2 ... A_N
Print the answer.
4 3 1 4 1
3
One possible solution is:
5 1 2 3 4 5
0
A_1 \leq A_2 \leq ... \leq A_N holds before any operation is performed.
8 657312726 129662684 181537270 324043958 468214806 916875077 825989291 319670097
7