import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //
const long infty = 1_000_000_000_000_000_100;
void solve(){
	int n = read.to!int;
	
	long[] as;
	foreach(i; 0 .. n) as ~= read.to!long;
	
	long[long[4]] memo;
	long calc(long x, long y, int l, int r){
		if(l + 1 == r) return 0;
//		else if([x, y, l, r] !in memo){
			long res = infty;
			foreach(i; l + 1 .. r){
				long temp = calc(x, x + y, l, i) + (x + y) * as[i] + calc(x + y, y, i, r);
				log("l:", l, "r:", r, "i:", i, "temp:", temp);
				res = min(res, temp);
//			}
//			memo[[x, y, l, r]] = res;
		}
//		else log("Found in memo.");
//		log("x:", x, "y:", y, "l:", l, "r:", r, "res:", memo[[x, y, l, r]]);
//		return memo[[x, y, l, r]];
	return res;
	}
	
	
	long ans = as[0] + calc(1, 1, 0, n - 1) + as[n - 1];
	
	ans.writeln;
}

