#include using namespace std; #define all(v) (v).begin(),(v).end() #define pb emplace_back #define rep(i, n) for(int i=0;i<(n);i++) #define foa(e, v) for(auto& e : v) #define dout(a) cout< using pqr = priority_queue, greater>; template inline bool chmax(T1 &a, T2 b) { bool compare = a < b; if(compare) a = b; return compare; } template inline bool chmin(T1 &a, T2 b) { bool compare = a > b; if(compare) a = b; return compare; } template inline T back(std::set &s) { return *s.rbegin(); } template inline T back(std::multiset &s) { return *s.rbegin(); } template inline T pop_back(std::set &s) { auto it = prev(s.end()); T val = *it; s.erase(it); return val; } template inline T pop_back(std::multiset &s) { auto it = prev(s.end()); T val = *it; s.erase(it); return val; } const int dy[8] = {-1, 0, 0, 1, 1, -1, 1, -1}; const int dx[8] = {0, -1, 1, 0, -1, -1, 1, 1}; const ll MOD7 = 1000000007, MOD998 = 998244353, INF = (3LL << 59); const int inf = 1 << 30; const char br = '\n'; void solve() { ll n;cin >> n; vector a(n); rep(i, n) cin >> a[i]; ll ans = INF; vector v; int m = n / 2; rep(bit, 1 << m) { ll num = 0; rep(j, m) { if(bit >> j & 1) num += a[j]; else num -= a[j]; } v.pb(num); } sort(all(v)); rep(bit, 1 << (n - m)) { ll num = 0; rep(i, n - m) { if(bit >> i & 1) num += a[i + m]; else num -= a[i + m]; } auto itr = lower_bound(all(v), num); if(itr != v.end()) { chmin(ans, abs(*itr - num)); } if(itr != v.begin()) { itr --; chmin(ans, abs(*itr - num)); } } cout << ans << endl; } int main() { cin.tie(0); ios::sync_with_stdio(false); int testcase = 1; // cin >> testcase; while(testcase --) solve(); return 0; }