fun main(args: Array<String>) {
    val N = nextInt()
    val A = listOfLong().toLongArray()
    fun dfs(nest: Int, left: Int, right: Int, c_l: Int, c_r: Int): Long {
        var ans = if (left + 1 < right) Long.MAX_VALUE else 0L
        for (m in left + 1 until right) {
            val c_m = c_l + c_r
            ans = Math.min(ans, dfs(nest+1, left, m, c_l, c_m) + dfs(nest+1, m, right, c_m, c_r) + c_m * A[m])
        }
        return ans
    }
    val ans = A[0] + dfs(0,0, N - 1, 1, 1) + A[N - 1]
    println(ans)
}
fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun listOfString() = next().split(" ")
fun listOfLong() = listOfString().map { it.toLong() }

