#define ll long long int

#include <bits/stdc++.h>

using namespace std;
const int N = 17000;
int arr[N];

string convert(ll n) {
    string temp = "";
    while (n) {
        if (n % 2) {
            temp += '1';
        } else temp += '0';
        n = n / 2;
    }
    reverse(temp.begin(), temp.end());
    return temp;
}

ll power(ll n) {
    ll res = 1;
    while (n) {
        res = res * 2;
        n--;
    }
    return res;
}

ll binary(string s) {
    ll res = 0;
    ll cnt = 0;
    for (int i = s.size() - 1; i >= 0; --i) {
        if (s[i] == '1') res += power(cnt);
        cnt++;
    }
    return res;
}

int n;
ll dp[81][N][300];

ll go(int i, int have, int candy) {

    if (i == n ) {
        return 1000 ;
    }
    ll &ret = dp[i][have][candy];
    if (~ret)return ret;

    ret = -1e9  ;
    ret =max(ret , go(i + 1, have, candy));

    if (candy > 0) {
        ret = max(ret, go(i, have + arr[i], candy - 1) + arr[i]);
    }
    if (have >= arr[i]) {
        ret = max(ret, go(i, have - arr[i], candy + 1) - arr[i]);
    }
  //  cout << i <<" " << have <<endl;
    return ret;

}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    memset(dp, -1, sizeof(dp));
    cin >> n;
    for (int i = 0; i < n; i++)cin >> arr[i];
    cout<<go(0 , 1000 , 0) <<endl;
    return 0;
}