#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include #include using std::cout; using namespace std; using ll=long long; using ld=long double; using P=array; #define rep(i,n) for (ll i=0,siz=(n);i=siz;i--) #define popcount __builtin_popcountll #define cin(a) ll a; cin >> a; #define cin2(a,b) ll a,b; cin >> a >> b; #define cin3(a,b,c) ll a,b,c; cin >> a >> b >> c; #define cinvec(v) vector v(N); rep(i,N) cin >> v[i]; #define cinvec2(v,n) vector v(n); rep(i,n) cin >> v[i]; #define cins(s) string s; cin >> s; #define cinc(c) char c; cin >> c; #define seg_RaRmax atcoder::lazy_segtree #define seg_RaRsum atcoder::lazy_segtree, [&](array a, array b){ return array{a[0]+b[0],a[1]+b[1]};},[&](){return array{0,0};},ll,[&](ll m, array n){ return array{m[0]+n*m[1],m[1]};}, [&](ll a, ll b){return a+b;},[&](){return 0;}> vector dx = {0,-1,0,1},dy = {1,0,-1,0}, ddx = {0,-1,-1,-1,0,1,1,1}, ddy = {1,1,0,-1,-1,-1,0,1}; void yesno(bool b) {cout << (b?"Yes":"No") << endl;} template void sortunique(vector &V) {sort(V.begin(), V.end()); V.erase(unique(V.begin(), V.end()), V.end());} template void outvec(const std::initializer_list& list) { bool first = true; for (const auto& elem : list) { if (!first) std::cout << " "; std::cout << elem; first = false; } std::cout << std::endl; } template void outvec(const std::vector& vec) { bool first = true; for (const auto& elem : vec) { if (!first) std::cout << " "; std::cout << elem; first = false; } std::cout << std::endl; } template void outvecp(const std::vector>& vec) { bool first = true; for (const auto& elem : vec) { if (!first) std::cout << " "; for (int i = 0; i < N; i++) std::cout << elem[i] << " "; first = false; } std::cout << std::endl; } vector compress(vector &A){vector B = A; sortunique(B); rep(i,A.size()) A[i] = lower_bound(B.begin(),B.end(),A[i]) - B.begin(); return B;} ll bs(ll l, ll r, function f) { while (r-l > 1) { ll m = (l+r)/2; if (f(m)) r = m; else l = m; } return r; } ll msb(ll N) { assert(N>0); return 63 - __builtin_clzll(N); } int main() { cin(N); cinvec(A); vector> dp(N+1,vector(10001,0)); dp[0][0] = 1; rep(i,N){ rep(j,10001){ if (j >= A[i]) dp[i+1][j] = dp[i][j]+dp[i][j-A[i]]; else dp[i+1][j] = dp[i][j]; } } ll ans = 1e18; rep2(i,1,5001){ if (dp[N][i] > 1) ans = min(ans,i); } if (ans == 1e18) cout << -1 << endl; else cout << accumulate(A.begin(),A.end(),0ll)-ans*2 << endl; return 0; }