#include using namespace std; typedef long long ll; #define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++) #define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++) #define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--) #define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) ((ll)(x).size()) #define len(x) ((ll)(x).length()) #define endl "\n" ll n, ans = 0; vector d; void dfs(ll bit, ll chp, ll mhp) { if (chp <= 0) return; if (bit == ((1 << n) - 1)) { ans = max(ans, chp); return; } ll br = 0; rep(i, n) { if (bit & (1 << i)) continue; br += d[i]; } if (!br) return; rep(i, n) { if (bit & (1 << i)) continue; ll nmhp = mhp + ((d[i] < 0) ? 100 : 0); ll nchp = min(nmhp, chp + d[i]); dfs(bit | (1 << i), nchp, nmhp); } } int main() { cin.tie(0); ios::sync_with_stdio(false); // ifstream in("input.txt"); // cin.rdbuf(in.rdbuf()); cin >> n; d.resize(n); rep(i, n) cin >> d[i]; dfs(0, 100, 100); cout << ans << endl; return 0; }