#include <bits/stdc++.h>
using namespace std;
const int N = 4.8e6 + 2;
const int inf = 1e9 + 9;
int n, a[25], cnt[N][25], dp[N];
template <typename _Tp>
inline void IN(_Tp& x) {
  char ch;
  bool flag = 0;
  x = 0;
  while (ch = getchar(), !isdigit(ch))
    if (ch == '-') flag = 1;
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  if (flag) x = -x;
}
inline int solve(int state) {
  if (!state) return 0;
  if (dp[state] != 2139062143) return dp[state];
  int tot = 0;
  for (int i = 0; i < n; ++i)
    if (state & (1 << i)) cnt[state][tot++] = i;
  if (tot == 2) {
    return a[cnt[state][0]] + a[cnt[state][1]];
  }
  for (int i = 1; i < tot - 1; ++i) {
    int nxts = state;
    nxts ^= (1 << cnt[state][i]);
    a[cnt[state][i - 1]] += a[cnt[state][i]],
        a[cnt[state][i + 1]] += a[cnt[state][i]];
    dp[state] = min(solve(nxts), dp[state]);
    a[cnt[state][i - 1]] -= a[cnt[state][i]],
        a[cnt[state][i + 1]] -= a[cnt[state][i]];
  }
  return dp[state];
}
int main() {
  IN(n);
  memset(dp, 127, sizeof(dp));
  for (int i = 0; i < n; ++i) IN(a[i]);
  int ans = dp[0];
  printf("%d\n", solve((1 << n) - 1));
  return 0;
}
