#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define INF 10000000000000000ll
const int exp3[] = {1, 3, 9, 27, 81, 243, 729, 2187, 6561, 19683, 59049, 177147, 531441};
ll a[24], y[531441], bit[531442];
int bit_size;
inline void bit_init(int n){
bit_size = n;
for(int i=0; i<=bit_size; i++){
bit[i] = -INF;
}
}
inline ll bit_max(int i){
ll r = -INF;
for(; i; i-=i&-i){
r = max(r, bit[i]);
}
return r;
}
inline void bit_update(int i, ll x){
for(; i<=bit_size && bit[i]<x; i+=i&-i){
bit[i] = x;
}
}
struct jiken{
bool query;
ll x, y;
jiken(bool q=false, ll x=0, ll y=0): query(q), x(x), y(y){}
bool operator <(const jiken &b) const{
if(x == b.x){
return !query && b.query;
}
return x < b.x;
}
}sl[1062882];
int main(){
int n;
scanf("%d", &n);
for(int i=0; i<=n-1; i++) scanf("%lld", a+i);
ll s = 0;
for(int i=0; i<=n-1; i++) s += a[i];
int m=0, ysz=0;
for(int i=0; i<exp3[n/2]; i++){
ll p=0, q=0;
for(int j=0, t=i; j<=n/2; j++, t/=3){
if(t%3 == 1){
p += a[j];
}else if(t%3 == 2){
q += a[j];
}
}
sl[m++] = jiken(false, p-q, p+2*q);
y[ysz++] = p+2*q;
}
sort(y, y+ysz);
ysz = unique(y, y+ysz)-y;
for(int i=0; i<exp3[(n+1)/2]; i++){
ll p=0, q=0;
for(int j=0, t=i; j<=(n+1)/2-1; j++, t/=3){
if(t%3 == 1){
p += a[n/2+j];
}else if(t%3 == 2){
q += a[n/2+j];
}
}
sl[m++] = jiken(true, -p+q, s-p-2*q);
}
sort(sl, sl+m);
ll ans = INF;
bit_init(ysz);
for(int i=0; i<=m-1; i++){
int j = upper_bound(y, y+ysz, sl[i].y)-y;
if(sl[i].query){
ans = min(ans, sl[i].x+sl[i].y-bit_max(j));
}else{
bit_update(j, sl[i].x+sl[i].y);
}
}
printf("%lld\n", ans);
return 0;
}
I2luY2x1ZGU8Y3N0ZGlvPgojaW5jbHVkZT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aW50IG1haW4oKXsKICAgIGludCBuOwogICAgc2NhbmYoIiVkIiwgJm4pOwogICAgZm9yKGludCBpPTA7IGk8PW4tMTsgaSsrKSBzY2FuZigiJWxsZCIsIGEraSk7CiAgICBsbCBzID0gMDsKICAgIGZvcihpbnQgaT0wOyBpPD1uLTE7IGkrKykgcyArPSBhW2ldOwogICAgaW50IG09MCwgeXN6PTA7CiAgICBmb3IoaW50IGk9MDsgaTxleHAzW24vMl07IGkrKyl7CiAgICAgICAgbGwgcD0wLCBxPTA7CiAgICAgICAgZm9yKGludCBqPTAsIHQ9aTsgajw9bi8yOyBqKyssIHQvPTMpewogICAgICAgICAgICBpZih0JTMgPT0gMSl7CiAgICAgICAgICAgICAgICBwICs9IGFbal07CiAgICAgICAgICAgIH1lbHNlIGlmKHQlMyA9PSAyKXsKICAgICAgICAgICAgICAgIHEgKz0gYVtqXTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBzbFttKytdID0gamlrZW4oZmFsc2UsIHAtcSwgcCsyKnEpOwogICAgICAgIHlbeXN6KytdID0gcCsyKnE7CiAgICB9CiAgICBzb3J0KHksIHkreXN6KTsKICAgIHlzeiA9IHVuaXF1ZSh5LCB5K3lzeikteTsKICAgIGZvcihpbnQgaT0wOyBpPGV4cDNbKG4rMSkvMl07IGkrKyl7CiAgICAgICAgbGwgcD0wLCBxPTA7CiAgICAgICAgZm9yKGludCBqPTAsIHQ9aTsgajw9KG4rMSkvMi0xOyBqKyssIHQvPTMpewogICAgICAgICAgICBpZih0JTMgPT0gMSl7CiAgICAgICAgICAgICAgICBwICs9IGFbbi8yK2pdOwogICAgICAgICAgICB9ZWxzZSBpZih0JTMgPT0gMil7CiAgICAgICAgICAgICAgICBxICs9IGFbbi8yK2pdOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHNsW20rK10gPSBqaWtlbih0cnVlLCAtcCtxLCBzLXAtMipxKTsKICAgIH0KICAgIHNvcnQoc2wsIHNsK20pOwogICAgbGwgYW5zID0gSU5GOwogICAgYml0X2luaXQoeXN6KTsKICAgIGZvcihpbnQgaT0wOyBpPD1tLTE7IGkrKyl7CiAgICAgICAgaW50IGogPSB1cHBlcl9ib3VuZCh5LCB5K3lzeiwgc2xbaV0ueSkteTsKICAgICAgICBpZihzbFtpXS5xdWVyeSl7CiAgICAgICAgICAgIGFucyA9IG1pbihhbnMsIHNsW2ldLngrc2xbaV0ueS1iaXRfbWF4KGopKTsKICAgICAgICB9ZWxzZXsKICAgICAgICAgICAgYml0X3VwZGF0ZShqLCBzbFtpXS54K3NsW2ldLnkpOwogICAgICAgIH0KICAgIH0KICAgIHByaW50ZigiJWxsZFxuIiwgYW5zKTsKICAgIHJldHVybiAwOwp9Cg==