#include using namespace std; typedef long long ll; #define REP(i, n) for(int(i)=0;(i)<(n);++(i)) const int MOD = 1000000007; vector P,M; unsigned int up, um; inline void bits(unsigned int &p, int n){ p |= (1< > listM; listM.push_back(make_pair(0,0)); REP(i,M.size()){ if(biti(um, i)) continue; int size = listM.size(); REP(j,size){ auto &v = listM[j]; listM.push_back(make_pair(v.first + M[i], v.second|(1<first < v) return it->second; } return 0; } int dpp(int v){ vector > listP; listP.push_back(make_pair(0,0)); REP(i,P.size()){ if(biti(up, i)) continue; int size = listP.size(); REP(j,size){ auto &v = listP[j]; listP.push_back(make_pair(v.first + P[i], v.second|(1<first < v) return it->second; } return 0; } int D[20]; int main(){ int N; cin >> N; REP(i,N) cin >> D[i]; int pn = 0, mn = 0; REP(i,N){ if(D[i] < 0){ M.push_back(-D[i]); } else { P.push_back(D[i]); } } int mv = 100, v = 100, cnt = 1000; while(cnt--){ int b = dpm(v); if(b){ REP(i,M.size()){ if(biti(b,i)){ bits(um, i); v -= M[i], mv += 100; } } } else { b = dpp(mv-v); if(b){ REP(i,P.size()){ if(biti(b,i)){ bits(up, i); v += P[i]; } } } else { int idx = -1, j = 1<<29; REP(i,P.size()){ if(biti(up,i)) continue; if(j > P[i]){ j = P[i], idx = i; } } if(idx >= 0){ bits(up, idx); v += P[idx]; if(v > mv) v = mv; } } } } if(um != (1<