output_description: Print the answer.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
      A_1 A_2 ... A_N
attempt: #include <bits/stdc++.h>
  using namespace std;
  #define int long long   // aaaaaaaaaaaaaaaaaa
  #define rep(i,a,n) for (int i=a;i<n;i++)
  #define per(i,a,n) for (int i=n-1;i>=a;i--)
  #define pb push_back
  #define mp make_pair
  #define all(x) (x).begin(),(x).end()
  #define allr(x) (x).rbegin(),(x).rend()
  #define fi first
  #define se second
  #define SZ(x) ((int)(x).size())
  #define SIZE(buff) (sizeof(buff)/sizeof(buff[0]))
  typedef vector<int> VI;
  typedef vector<vector<int> > VVI;
  typedef long long ll;
  typedef pair<int,int> PII;
  const ll mod=1000000007;
  ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
  ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
  template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
  {o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
  template<typename T, typename U>ostream& operator << (ostream& os, pair<T, U>& pair_var)
  {os << "(" << pair_var.first << ", " << pair_var.second << ")";return os;}
  // head
  
  int t,q,m,n,k,res,tmp,tmp2;
  int a[200010] = {};
  int b[200010] = {};
  //vector<PII> g[500010];
  queue<int> que2;
  int dp[200010][18]={};
  int dp2[200010][18]={};
  //string s;
  
  signed main() {
  	cin.tie(0);
      ios::sync_with_stdio(false);
  	std::cin >>n;
  	rep(i,0,n) {
  		cin>> a[i];
  		b[i] = a[i]*(-2);
  	}
  	rep(i,0,16) dp[n][i] = i;
  	per(i,1,n){
  		rep(j,0,16){
  			tmp = 1LL<<60;
  			rep(x,0,16){
  				tmp2 = 0;
  				k = a[i];
  				while(a[i-1] > k){
  					k*=4;
  					tmp2 += 1;
  				}
  				k = a[i-1];
  				while(a[i] > k){
  					k*= 4;
  					tmp2-=1;
  				}
  				tmp = min(tmp,dp[i+1][x]+max(0LL,tmp2+j-x)*(n-i)+j);
  			}
  			dp[i][j] = tmp;
  		}
  	}
  	rep(i,0,16) dp2[1][i] = i;
  	rep(i,2,n+1){
  		rep(j,0,16){
  			tmp = 1LL<<60;
  			rep(x,0,16){
  				tmp2 = 0;
  				k = b[i-2];
  				while(b[i-1] < k){
  					k*=4;
  					tmp2 += 1;
  				}
  				k = b[i-1];
  				while(b[i-2] < k){
  					k*=4;
  					tmp2 -= 1;
  				}
  				tmp = min(tmp,dp2[i-1][x]+max(0LL,tmp2+j-x)*(i-1)+j);
  			}
  			dp2[i][j] = tmp;
  		}
  	}
  	res = 1LL<<60;
  	rep(i,1,n+1){
  		res = min(res,dp[i][0]*2+dp2[i-1][0]*2+i-1);
  	}
      cout<<res<<endl;
  }
problem_description: Statement
  
  There are N positive integers A_1, A_2, ..., A_N. Takahashi can perform the
  following operation on these integers any number of times:
  
    * Choose 1 \leq i \leq N and multiply the value of A_i by -2.
  
  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`.
samples: [{"input": "4\n    3 1 4 1", "output": "3\n    \n\nOne possible solution is:\n\n  * Choose i=4 and multiply the value of A_4 by -2. A_1, A_2, A_3, A_4 are now 3, 1, 4, -2.\n  * Choose i=1 and multiply the value of A_1 by -2. A_1, A_2, A_3, A_4 are now -6, 1, 4, -2.\n  * Choose i=4 and multiply the value of A_4 by -2. A_1, A_2, A_3, A_4 are now -6, 1, 4, 4.\n\n* * *"}, {"input": "5\n    1 2 3 4 5", "output": "0\n    \n\nA_1 \\leq A_2 \\leq ... \\leq A_N holds before any operation is performed.\n\n* * *"}, {"input": "8\n    657312726 129662684 181537270 324043958 468214806 916875077 825989291 319670097", "output": "7"}]