#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:108777216")
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <utility>
#include <algorithm>
#include <ctime>
using namespace std;

int const MAX_N = 256 * 1024;
long long const LL_INF = 1000000000000000000LL;

int n, s[MAX_N];
long long mn;
int min_pos = 0;
double const TL = 1.8;
unsigned long long ms[MAX_N];

long long solve(unsigned long long * ms, int ms_len, int fast_calc = 0) {
	long long ans = 0;
	if (ms_len <= 0)
		return ans;

	unsigned long long last_dg_2 = 0;
	unsigned long long last_ms = ms[0];

	for (int i = 1; i < ms_len; i++)
		if (last_dg_2 <= 0) {
			if (ms[i] >= last_ms) {
				last_ms = ms[i];
				continue;
			}

			long long ad = 0;
			long long val_save = ms[i];

			while (ms[i] < last_ms) {
				ans += 2;
				ad += 2;
				ms[i] *= 4LL;
			}

			if (ms[i] > 1000000000LL) {
				last_dg_2 = ad;
				last_ms = val_save;
			}
			else {
				last_dg_2 = 0;
				last_ms = ms[i];
			}

			if (fast_calc)
				if (ans >= mn)
					return ans;
		}
		else {
			unsigned long long save_msi = ms[i];

			if (ms[i] >= last_ms) {
				unsigned long long x = last_ms;
				long long rem_2 = last_dg_2;
				while (ms[i] >= x && rem_2 > 0) {
					x *= 2;
					rem_2--;
				}
				if (ms[i] >= x) {
					last_dg_2 = 0;
					last_ms = ms[i];
					continue;
				}
			}

			// ms[i] < last_ms * 2^last_dg_2
			long long at_least = last_dg_2 - 36;
			at_least = max(at_least, 0LL);

			ans += at_least;
			long long new_dg_2 = at_least;

			long long rem_2 = last_dg_2 - at_least;   // <= 36

			unsigned long long x = last_ms;
			unsigned long long y = ms[i];

			if (y >= x) {
				long long ee = 0;
				while (y >= x) {
					ee++;
					x *= 2;
				}
				new_dg_2 += max(0LL, rem_2 - ee + 1);
				ans += max(0LL, rem_2 - ee + 1);
			}
			else {
				long long ee = 0;
				while (y < x) {
					ee++;
					y *= 2;
				}
				new_dg_2 += ee + rem_2;
				ans += ee + rem_2;
			}

			if (new_dg_2 & 1) {
				new_dg_2++;
				ans++;
			}

			last_dg_2 = new_dg_2;
			last_ms = save_msi;


			/*long double x = last_ms;
			while (rem_2 > 0) { x *= 2; rem_2--; }

			long double y = ms[i];
			while (y < x) {
				ans += 2;
				new_dg_2 += 2;
				y *= 4LL;
			}

			last_dg_2 = new_dg_2;
			last_ms = save_msi;*/

			if (fast_calc)
				if (ans >= mn)
					return ans;
		}

	return ans;
}

map<int, long long> solve_rev, solve_forw;

long long calc(int x, int fast_calc = 0) {
	if (x < 0) x = 0;
	if (x > n) x = n;

	// >= for indexes [0...x-1]   + rotate
	int ms_len = 0;
	for (int i = x - 1; i >= 0; i--)
		ms[ms_len++] = s[i];
	long long ans = 0;
	if (solve_rev.find(x) != solve_rev.end())
		ans = solve_rev[x];
	else {
		ans = solve(ms, ms_len, fast_calc);
		solve_rev[x] = ans;
	}
	ans += x; // rotate

	if (fast_calc)
		if (ans >= mn)
			return ans;

	// <= for indexes [x...n)
	ms_len = 0;
	for (int i = x; i < n; i++)
		ms[ms_len++] = s[i];
	if (solve_forw.find(x) != solve_forw.end())
		ans += solve_forw[x];
	else {
		solve_forw[x] = solve(ms, ms_len, fast_calc);
		ans += solve_forw[x];
	}

	return ans;
}

long long my_min(long long lst, long long new_val, int pp) {
	if (lst > new_val)
		min_pos = pp;
	return min(lst, new_val);
}

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	clock_t t_BG = clock();

	scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%d", &s[i]);
	
	mn = LL_INF;

	if (n < 8000) {
		for (int i = 0; i <= n; i++)
			mn = min(mn, calc(i));
		cout << mn;
		return 0;
	}

	int down = 0, up = n+1;
	while (up > down + 3) {
		int t1 = down + (up - down) / 3;
		int t2 = up - (up - down) / 3;
		long long ans1 = calc(t1);
		long long ans2 = calc(t2);
		mn = my_min(mn, ans1, t1);
		mn = my_min(mn, ans2, t2);

		if (ans1 < ans2)
			up = t2;
		else
			down = t1;
	}

	
	
	int XXX = 10;





	for (int dx = 0; dx <= XXX; dx++) {
		int i = down + dx;
		if (i >= 0 && i <= n) {
			mn = my_min(mn, calc(i, 1), i);
			if ((((double)(clock() - t_BG)) / (CLOCKS_PER_SEC)) >= TL)
				break;
		}
		i = down - dx;
		if (i >= 0 && i <= n) {
			mn = my_min(mn, calc(i, 1), i);
			if ((((double)(clock() - t_BG)) / (CLOCKS_PER_SEC)) >= TL)
				break;
		}
	}

	int SVV = down;

	down = 0, up = SVV+1;
	while (up > down + 3) {
		int t1 = down + (up - down) / 3;
		int t2 = up - (up - down) / 3;
		long long ans1 = calc(t1);
		long long ans2 = calc(t2);
		mn = my_min(mn, ans1, t1);
		mn = my_min(mn, ans2, t2);

		if (ans1 < ans2)
			up = t2;
		else
			down = t1;
	}
	for (int dx = 0; dx <= XXX; dx++) {
		int i = down + dx;
		if (i >= 0 && i <= n) {
			mn = my_min(mn, calc(i, 1), i);
			if ((((double)(clock() - t_BG)) / (CLOCKS_PER_SEC)) >= TL)
				break;
		}
		i = down - dx;
		if (i >= 0 && i <= n) {
			mn = my_min(mn, calc(i, 1), i);
			if ((((double)(clock() - t_BG)) / (CLOCKS_PER_SEC)) >= TL)
				break;
		}
	}
	int SVV_L = down;

	down = SVV, up = n + 1;
	while (up > down + 3) {
		int t1 = down + (up - down) / 3;
		int t2 = up - (up - down) / 3;
		long long ans1 = calc(t1);
		long long ans2 = calc(t2);
		mn = my_min(mn, ans1, t1);
		mn = my_min(mn, ans2, t2);

		if (ans1 < ans2)
			up = t2;
		else
			down = t1;
	}
	for (int dx = 0; dx <= XXX; dx++) {
		int i = down + dx;
		if (i >= 0 && i <= n) {
			mn = my_min(mn, calc(i, 1), i);
			if ((((double)(clock() - t_BG)) / (CLOCKS_PER_SEC)) >= TL)
				break;
		}
		i = down - dx;
		if (i >= 0 && i <= n) {
			mn = my_min(mn, calc(i, 1), i);
			if ((((double)(clock() - t_BG)) / (CLOCKS_PER_SEC)) >= TL)
				break;
		}
	}
	int SVV_R = down;

	down = 0, up = SVV_L+1;
	while (up > down + 3) {
		int t1 = down + (up - down) / 3;
		int t2 = up - (up - down) / 3;
		long long ans1 = calc(t1);
		long long ans2 = calc(t2);
		mn = my_min(mn, ans1, t1);
		mn = my_min(mn, ans2, t2);

		if (ans1 < ans2)
			up = t2;
		else
			down = t1;
	}
	for (int dx = 0; dx <= XXX; dx++) {
		int i = down + dx;
		if (i >= 0 && i <= n) {
			mn = my_min(mn, calc(i, 1), i);
			if ((((double)(clock() - t_BG)) / (CLOCKS_PER_SEC)) >= TL)
				break;
		}
		i = down - dx;
		if (i >= 0 && i <= n) {
			mn = my_min(mn, calc(i, 1), i);
			if ((((double)(clock() - t_BG)) / (CLOCKS_PER_SEC)) >= TL)
				break;
		}
	}
	int a = down;

	down = SVV_L, up = SVV+1;
	while (up > down + 3) {
		int t1 = down + (up - down) / 3;
		int t2 = up - (up - down) / 3;
		long long ans1 = calc(t1);
		long long ans2 = calc(t2);
		mn = my_min(mn, ans1, t1);
		mn = my_min(mn, ans2, t2);

		if (ans1 < ans2)
			up = t2;
		else
			down = t1;
	}
	for (int dx = 0; dx <= XXX; dx++) {
		int i = down + dx;
		if (i >= 0 && i <= n) {
			mn = my_min(mn, calc(i, 1), i);
			if ((((double)(clock() - t_BG)) / (CLOCKS_PER_SEC)) >= TL)
				break;
		}
		i = down - dx;
		if (i >= 0 && i <= n) {
			mn = my_min(mn, calc(i, 1), i);
			if ((((double)(clock() - t_BG)) / (CLOCKS_PER_SEC)) >= TL)
				break;
		}
	}
	int b = down;

	down = SVV+1, up = SVV_R+1;
	while (up > down + 3) {
		int t1 = down + (up - down) / 3;
		int t2 = up - (up - down) / 3;
		long long ans1 = calc(t1);
		long long ans2 = calc(t2);
		mn = my_min(mn, ans1, t1);
		mn = my_min(mn, ans2, t2);

		if (ans1 < ans2)
			up = t2;
		else
			down = t1;
	}
	for (int dx = 0; dx <= XXX; dx++) {
		int i = down + dx;
		if (i >= 0 && i <= n) {
			mn = my_min(mn, calc(i, 1), i);
			if ((((double)(clock() - t_BG)) / (CLOCKS_PER_SEC)) >= TL)
				break;
		}
		i = down - dx;
		if (i >= 0 && i <= n) {
			mn = my_min(mn, calc(i, 1), i);
			if ((((double)(clock() - t_BG)) / (CLOCKS_PER_SEC)) >= TL)
				break;
		}
	}
	int c = down;

	down = SVV_R+1, up = n + 1;
	while (up > down + 3) {
		int t1 = down + (up - down) / 3;
		int t2 = up - (up - down) / 3;
		long long ans1 = calc(t1);
		long long ans2 = calc(t2);
		mn = my_min(mn, ans1, t1);
		mn = my_min(mn, ans2, t2);

		if (ans1 < ans2)
			up = t2;
		else
			down = t1;
	}
	for (int dx = 0; dx <= XXX; dx++) {
		int i = down + dx;
		if (i >= 0 && i <= n) {
			mn = my_min(mn, calc(i, 1), i);
			if ((((double)(clock() - t_BG)) / (CLOCKS_PER_SEC)) >= TL)
				break;
		}
		i = down - dx;
		if (i >= 0 && i <= n) {
			mn = my_min(mn, calc(i, 1), i);
			if ((((double)(clock() - t_BG)) / (CLOCKS_PER_SEC)) >= TL)
				break;
		}
	}
	int d = down;





	down = 0, up = a + 1;
	while (up > down + 3) {
		int t1 = down + (up - down) / 3;
		int t2 = up - (up - down) / 3;
		long long ans1 = calc(t1);
		long long ans2 = calc(t2);
		mn = my_min(mn, ans1, t1);
		mn = my_min(mn, ans2, t2);

		if (ans1 < ans2)
			up = t2;
		else
			down = t1;
	}
	for (int dx = 0; dx <= XXX; dx++) {
		int i = down + dx;
		if (i >= 0 && i <= n) {
			mn = my_min(mn, calc(i, 1), i);
			if ((((double)(clock() - t_BG)) / (CLOCKS_PER_SEC)) >= TL)
				break;
		}
		i = down - dx;
		if (i >= 0 && i <= n) {
			mn = my_min(mn, calc(i, 1), i);
			if ((((double)(clock() - t_BG)) / (CLOCKS_PER_SEC)) >= TL)
				break;
		}
	}

	down = a + 1, up = SVV_L + 1;
	while (up > down + 3) {
		int t1 = down + (up - down) / 3;
		int t2 = up - (up - down) / 3;
		long long ans1 = calc(t1);
		long long ans2 = calc(t2);
		mn = my_min(mn, ans1, t1);
		mn = my_min(mn, ans2, t2);

		if (ans1 < ans2)
			up = t2;
		else
			down = t1;
	}
	for (int dx = 0; dx <= XXX; dx++) {
		int i = down + dx;
		if (i >= 0 && i <= n) {
			mn = my_min(mn, calc(i, 1), i);
			if ((((double)(clock() - t_BG)) / (CLOCKS_PER_SEC)) >= TL)
				break;
		}
		i = down - dx;
		if (i >= 0 && i <= n) {
			mn = my_min(mn, calc(i, 1), i);
			if ((((double)(clock() - t_BG)) / (CLOCKS_PER_SEC)) >= TL)
				break;
		}
	}

	down = SVV_L + 1, up = b + 1;
	while (up > down + 3) {
		int t1 = down + (up - down) / 3;
		int t2 = up - (up - down) / 3;
		long long ans1 = calc(t1);
		long long ans2 = calc(t2);
		mn = my_min(mn, ans1, t1);
		mn = my_min(mn, ans2, t2);

		if (ans1 < ans2)
			up = t2;
		else
			down = t1;
	}
	for (int dx = 0; dx <= XXX; dx++) {
		int i = down + dx;
		if (i >= 0 && i <= n) {
			mn = my_min(mn, calc(i, 1), i);
			if ((((double)(clock() - t_BG)) / (CLOCKS_PER_SEC)) >= TL)
				break;
		}
		i = down - dx;
		if (i >= 0 && i <= n) {
			mn = my_min(mn, calc(i, 1), i);
			if ((((double)(clock() - t_BG)) / (CLOCKS_PER_SEC)) >= TL)
				break;
		}
	}

	down = b, up = SVV + 1;
	while (up > down + 3) {
		int t1 = down + (up - down) / 3;
		int t2 = up - (up - down) / 3;
		long long ans1 = calc(t1);
		long long ans2 = calc(t2);
		mn = my_min(mn, ans1, t1);
		mn = my_min(mn, ans2, t2);

		if (ans1 < ans2)
			up = t2;
		else
			down = t1;
	}
	for (int dx = 0; dx <= XXX; dx++) {
		int i = down + dx;
		if (i >= 0 && i <= n) {
			mn = my_min(mn, calc(i, 1), i);
			if ((((double)(clock() - t_BG)) / (CLOCKS_PER_SEC)) >= TL)
				break;
		}
		i = down - dx;
		if (i >= 0 && i <= n) {
			mn = my_min(mn, calc(i, 1), i);
			if ((((double)(clock() - t_BG)) / (CLOCKS_PER_SEC)) >= TL)
				break;
		}
	}

	down = SVV + 1, up = c + 1;
	while (up > down + 3) {
		int t1 = down + (up - down) / 3;
		int t2 = up - (up - down) / 3;
		long long ans1 = calc(t1);
		long long ans2 = calc(t2);
		mn = my_min(mn, ans1, t1);
		mn = my_min(mn, ans2, t2);

		if (ans1 < ans2)
			up = t2;
		else
			down = t1;
	}
	for (int dx = 0; dx <= XXX; dx++) {
		int i = down + dx;
		if (i >= 0 && i <= n) {
			mn = my_min(mn, calc(i, 1), i);
			if ((((double)(clock() - t_BG)) / (CLOCKS_PER_SEC)) >= TL)
				break;
		}
		i = down - dx;
		if (i >= 0 && i <= n) {
			mn = my_min(mn, calc(i, 1), i);
			if ((((double)(clock() - t_BG)) / (CLOCKS_PER_SEC)) >= TL)
				break;
		}
	}

	down = c + 1, up = SVV_R + 1;
	while (up > down + 3) {
		int t1 = down + (up - down) / 3;
		int t2 = up - (up - down) / 3;
		long long ans1 = calc(t1);
		long long ans2 = calc(t2);
		mn = my_min(mn, ans1, t1);
		mn = my_min(mn, ans2, t2);

		if (ans1 < ans2)
			up = t2;
		else
			down = t1;
	}
	for (int dx = 0; dx <= XXX; dx++) {
		int i = down + dx;
		if (i >= 0 && i <= n) {
			mn = my_min(mn, calc(i, 1), i);
			if ((((double)(clock() - t_BG)) / (CLOCKS_PER_SEC)) >= TL)
				break;
		}
		i = down - dx;
		if (i >= 0 && i <= n) {
			mn = my_min(mn, calc(i, 1), i);
			if ((((double)(clock() - t_BG)) / (CLOCKS_PER_SEC)) >= TL)
				break;
		}
	}

	down = SVV_R + 1, up = d + 1;
	while (up > down + 3) {
		int t1 = down + (up - down) / 3;
		int t2 = up - (up - down) / 3;
		long long ans1 = calc(t1);
		long long ans2 = calc(t2);
		mn = my_min(mn, ans1, t1);
		mn = my_min(mn, ans2, t2);

		if (ans1 < ans2)
			up = t2;
		else
			down = t1;
	}
	for (int dx = 0; dx <= XXX; dx++) {
		int i = down + dx;
		if (i >= 0 && i <= n) {
			mn = my_min(mn, calc(i, 1), i);
			if ((((double)(clock() - t_BG)) / (CLOCKS_PER_SEC)) >= TL)
				break;
		}
		i = down - dx;
		if (i >= 0 && i <= n) {
			mn = my_min(mn, calc(i, 1), i);
			if ((((double)(clock() - t_BG)) / (CLOCKS_PER_SEC)) >= TL)
				break;
		}
	}

	down = d + 1, up = n + 1;
	while (up > down + 3) {
		int t1 = down + (up - down) / 3;
		int t2 = up - (up - down) / 3;
		long long ans1 = calc(t1);
		long long ans2 = calc(t2);
		mn = my_min(mn, ans1, t1);
		mn = my_min(mn, ans2, t2);

		if (ans1 < ans2)
			up = t2;
		else
			down = t1;
	}
	for (int dx = 0; dx <= XXX; dx++) {
		int i = down + dx;
		if (i >= 0 && i <= n) {
			mn = my_min(mn, calc(i, 1), i);
			if ((((double)(clock() - t_BG)) / (CLOCKS_PER_SEC)) >= TL)
				break;
		}
		i = down - dx;
		if (i >= 0 && i <= n) {
			mn = my_min(mn, calc(i, 1), i);
			if ((((double)(clock() - t_BG)) / (CLOCKS_PER_SEC)) >= TL)
				break;
		}
	}







	for (int i = 0; i < 40; i++) {
		mn = my_min(mn, calc(i, 1), i);
		mn = my_min(mn, calc(n-i, 1), n-i);

		mn = my_min(mn, calc(n / 2 - i, 1), n/2 - i);
		mn = my_min(mn, calc(n / 2 + i, 1), n / 2+ i);

		if ((((double)(clock() - t_BG)) / (CLOCKS_PER_SEC)) >= TL)
			break;
	}

	long long R = calc(0, 1);
	mn = min(mn, R);

	for (int iter = 0; ; iter++) {
		if ((((double)(clock() - t_BG)) / (CLOCKS_PER_SEC)) >= TL)
			break;

		long long x = 0;
		if (iter > 0)
			x = rand() % (n / 3);
		long long dx = 1;
		while (x <= n) {
			x += dx;
			long long new_R = calc(max(0LL, min(0LL+n,x)), 1);
			mn = min(mn, new_R);

			if (new_R >= R)
				dx *= 2;
			else
				dx = 1;

			R = new_R;

			if ((((double)(clock() - t_BG)) / (CLOCKS_PER_SEC)) >= TL)
				break;
		}
	}

	for (int i = 0; i < 40; i++) {
		mn = my_min(mn, calc(n / 4 - i, 1), n / 4 - i);
		mn = my_min(mn, calc(n / 4 + i, 1), n / 4 + i);

		if ((((double)(clock() - t_BG)) / (CLOCKS_PER_SEC)) >= TL)
			break;
	}

	for (int i = 0; i < 40; i++) {
		mn = my_min(mn, calc(3*n / 4 - i, 1), 3*n / 4 - i);
		mn = my_min(mn, calc(3*n / 4 + i, 1), 3*n / 4 + i);

		if ((((double)(clock() - t_BG)) / (CLOCKS_PER_SEC)) >= TL)
			break;
	}

	for (int i = 0; i < 40; i++) {
		mn = my_min(mn, calc(3 * n / 5 - i, 1), 3 * n / 5 - i);
		mn = my_min(mn, calc(3 * n / 5 + i, 1), 3 * n / 5 + i);

		if ((((double)(clock() - t_BG)) / (CLOCKS_PER_SEC)) >= TL)
			break;
	}

	for (int i = 0; i < 40; i++) {
		mn = my_min(mn, calc(2 * n / 5 - i, 1), 2 * n / 5 - i);
		mn = my_min(mn, calc(2 * n / 5 + i, 1), 2 * n / 5 + i);

		if ((((double)(clock() - t_BG)) / (CLOCKS_PER_SEC)) >= TL)
			break;
	}

	int move = 1234;
	while (move > 1) {
		if ((((double)(clock() - t_BG)) / (CLOCKS_PER_SEC)) >= TL)
			break;

		for (int i = min_pos + move; i <= n; i += move) {
			long long val = calc(i, 1);
			if (val < mn) {
				mn = val;
				min_pos = i;
				break;
			}
			if ((((double)(clock() - t_BG)) / (CLOCKS_PER_SEC)) >= TL)
				break;
		}
		for (int i = min_pos - move; i >= 0; i -= move) {
			long long val = calc(i, 1);
			if (val < mn) {
				mn = val;
				min_pos = i;
				break;
			}
			if ((((double)(clock() - t_BG)) / (CLOCKS_PER_SEC)) >= TL)
				break;
		}
		move /= 2;
	}

	for (int i = min_pos - 20; i <= min_pos + 20; i++)
		if (i >= 0 && i <= n) {
			mn = my_min(mn, calc(i, 1), i);
			if ((((double)(clock() - t_BG)) / (CLOCKS_PER_SEC)) >= TL)
				break;
		}

	while (1)
		if ((((double)(clock() - t_BG)) / (CLOCKS_PER_SEC)) < TL) {
			mn = min(mn, calc(rand() % n, 1));
		}
		else
			break;
	cout << mn;
	return 0;
}

Measured memory_bytes: 4736