#include "bits/stdc++.h" using namespace std; #define REP(i, n) for(int i=0; i<(n); i++) int N; int maxhp(vector D, int hp, int ceilhp) { if (D.empty()) return hp; int mh = 0; REP(i,D.size()) { int h = min(hp + D[i], ceilhp); if (h <= 0) continue; // 死亡 vector tmp; for (int j : D) tmp.push_back(j); tmp.erase(tmp.begin() + i); mh = max(mh, maxhp(tmp, h, ceilhp + ((D[i]<0)?100:0))); } return mh; } signed main() { cin >> N; vector D(N); REP(i,N) cin >> D[i]; cout << maxhp(D, 100, 100) << endl; return 0; }