N,*A=`dd`.split.map &:to_i
x,y=[A,A.reverse].map{|_|
	t=[]
	r=[c=0]
	_.each_with_index{|a,i|
		b=a
		q=1
		while !t.empty?&&t[-1][0]<b
			x,d,n=t.pop
			(c+=n*2;x*=4;d*=4)while x<b
			b=d
			q+=n
		end
		t<<t.empty? ? [a,0,q] : [a,b,q]
		r<<c
	}
	r
}
p (0..N).map{|i|x[i]+i+y[-1-i]}.min