// ${url}
//
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, [ next / $t:tt ]) => {
        {
            let len = read_value!($iter, usize);
            (0..len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! dvec {
    ($t:expr ; $len:expr) => {
        vec![$t; $len]
    };

    ($t:expr ; $len:expr, $($rest:expr),*) => {
        vec![dvec!($t; $($rest),*); $len]
    };
}

#[allow(unused_macros)]
macro_rules! ifv {
    ($t:expr, $a:expr, $b: expr) => {
        if $t { $a } else { $b }
    }
}

#[allow(unused_macros)]
macro_rules! fill {
    ($t:expr, $v:expr) => {
        for i in 0..$t.len() {
            $t[i] = $v;
        }
    };
}

#[allow(unused_macros)]
macro_rules! join {
    ($t:expr, $glue:expr) => {
        $t.into_iter().map(|w| w.to_string()).collect::<Vec<_>>().join($glue)
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn next_permutation(a: &mut Vec<usize>) -> bool {
    let n = a.len();
    let mut x = n - 2;
    while a[x] >= a[x+1] {
        if x == 0 {
            return false;
        }
        x -= 1;
    }

    let mut y = n - 1;
    while y > x && a[y] <= a[x] {
        y -= 1;
    }
    let tmp = a[x];
    a[x] = a[y];
    a[y] = tmp;

    let (ll, rr) = a.split_at_mut(x+1);
    let (md, rr) = rr.split_at_mut(n-x-1);
    md.sort();
    true
}

fn process(a: Vec<usize>, mut d: Vec<Vec<i32>>) {
    let n = d.len();
    let mut done = 0;
    for ai in a {
        if ai == 0 || ai == n-1 {
            continue;
        }
        let mut f = ai-1;
        while done & (1<<f) >= 1 {
            f -= 1;
        }
        for i in 0..n {
            d[f][i] += d[ai][i];
        }
        let mut f = ai+1;
        while done & (1<<f) >= 1 {
            f += 1;
        }
        for i in 0..n {
            d[f][i] += d[ai][i];
        }
        done |= 1<<ai;
    }
    for i in 0..n {
        d[0][i] += d[n-1][i];
    }
    debug!(d[0]);
}

type Memo = Vec<Vec<HashMap<(i64, i64), i64>>>;

const INF: i64 = 1e18 as i64;

fn solve(l: usize, r: usize, ln: i64, rn: i64, a: &Vec<i64>, memo: &mut Memo) -> i64 {
    let w = (ln, rn);
    if let Some(&v) = memo[l][r].get(&w) {
        return v;
    }
    if l+1 == r {
        memo[l][r].insert((ln, rn), 0);
        return 0;
    }
    let mut best = INF;
    for i in l+1..r {
        let w = ln+rn;
        let left = solve(l, i, ln, w, a, memo);
        let right = solve(i, r, w, rn, a, memo);
        best = min(best, a[i]*w + left + right);
    }
    memo[l][r].insert((ln, rn), best);
    best
}

fn main() {
    input! {
        n: usize, a: [i64; n]
    };

    let mut memo = dvec!(HashMap::new(); n, n);
    let ans = solve(0, n-1, 1, 1, &a, &mut memo);

    println!("{}", ans + a[0] + a[n-1]);
}


Measured memory_bytes: 35216