#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:256000000")
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<algorithm>
#include<cmath>
#include<set>
#include<queue>
#include<sstream>
#include<utility>
#include<map>
#include<ctime>
#include<cstdio>
#include<cassert>
#include<functional>
#include<unordered_map>
#include<deque>




using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;
typedef pair<double, double> pdd;

#define show(x) cerr << x
#define debug(x) show(#x << ": " << (x) << endl)

const long double PI = 3.14159265358979323846;
const long double eps = 1e-5;
const ll INF = numeric_limits<int>::max();
const ll LINF = numeric_limits<ll>::max();
const ll mod = 1000 * 1000 * 1000 + 7;

ll res = LINF;
vector<ll> b, rt, lt;


void dfs(int val, int mx) {
    /*int p = 0;
    cout << "pos " << pos << " start " << endl;
    while (p < b.size()) {
        cout << p << ":" << b[p] << " ";
        p = rt[p];
    }
    cout << endl;
    cout << "moves from pos " << pos << " : " << g[pos].size() << endl;*/
    if (mx == 0) {
        ll cur = b[0] + b[rt[0]];
        res = min(res, cur);
        //cerr << "res = " << res << endl;
        return;
    }
    /*vector<int> ids(18);
    ids[0] = 0;
    for (int i = 1; ; ++i) {
        ids[i] = rt[ids[i - 1]];
        //cerr << i << " " << ids[i] << endl;
        if (ids[i] >= rt.size())
            break;
    }*/
    int lx = 0, lid = 0;
    int z = val;
    for (int j = max(1, z - 1); j <= mx; ++j) {
        int x = j;
        int id = lid;
        for (int i = lx; i < x; ++i) {
            id = rt[id];
        }
        lx = x;
        lid = id;
        int i1 = lt[id], i2 = rt[id];
        //cerr << x << " " << i1 << " " << id << " " << i2 << endl;
        int mrt = rt[i1], mlt = lt[i2];
        rt[i1] = i2;
        lt[i2] = i1;
        b[i1] += b[id];
        b[i2] += b[id];
        dfs(x, mx - 1);
        b[i1] -= b[id];
        b[i2] -= b[id];
        rt[i1] = mrt;
        lt[i2] = mlt;
    }
    /* 
    for (int i = 0; i < g[pos].size(); ++i) {
        int to = g[pos][i];
        int x = a[to];
        int id = lid;
        for (int i = lx; i < x; ++i) {
            id = rt[id];
        }
        lx = x;
        lid = id;
        int i1 = lt[id], i2 = rt[id];
        //cerr << x << " " << i1 << " " << id << " " << i2 << endl;
        int mrt = rt[i1], mlt = lt[i2];
        rt[i1] = i2;
        lt[i2] = i1;
        b[i1] += b[id];
        b[i2] += b[id];
        dfs(to, x, mx - 1);
        b[i1] -= b[id];
        b[i2] -= b[id];
        rt[i1] = mrt;
        lt[i2] = mlt;
    }*/

}

void solve() {
    int n;
    cin >> n;
    b.resize(n);
    for (int i = 0; i < n; ++i) 
        cin >> b[i];
    rt.resize(n);
    lt.resize(n);
    for (int i = 0; i < n; ++i) {
        rt[i] = i + 1;
        lt[i] = i - 1;
    }
    /*g.reserve(130000000);
    a.reserve(130000000);
    int lst = 0;
    for (int k = 1; k <= n - 2; ++k) {
        int mx = n - 1 - k;
        int sz = g.size();
        for (int v = lst; v < g.size(); ++v) {
            int z = a[v];
            for (int j = max(1, z - 1); j <= mx; ++j) {
                g[v].push_back(sz);
                a.push_back(j);
                ++sz;
            }
        }
        lst = g.size();
        g.resize(sz);
        for (int i = lst; i < g.size(); ++i) {
            g[i].reserve(mx - 1);
        }
        //cout << k << " " << g.size() << "\n";
    }*/
    //cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    dfs(0, n - 2);
    //cout << g.size() << endl;
    cout << res << endl;

}


//#define LOCAL

int main() {
    ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
#ifdef LOCAL
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    solve();


#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif	
    return 0;
}


Measured memory_bytes: 384