#include<bits/stdc++.h>

using namespace std;

#define int long long
int a[81];
int dp[81][400005];
int inf = 1e9;

main() {
#ifdef HOME
    freopen("input.txt", "r", stdin);
#endif // HOME
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j <= 400000; ++j) dp[i][j] = -inf;
    }
    dp[0][0] = 1000;
    for (int i = 1; i <= n; ++i) {
        int oks = -inf;
        for (int j = 0; j <= 400000; ++j) {
            /*for (int lst = 0; lst <= 1000; ++lst) {
                if (dp[i - 1][lst] >= 0) dp[i][j] = max(dp[i][j], dp[i - 1][lst] - (j - lst) * a[i]);
            }*/
            oks = max(oks - a[i], dp[i - 1][j]);
            if (oks >= 0) dp[i][j] = oks;
        }
        oks = -inf;
        for (int j = 400000; j >= 0; --j) {
            oks = max(oks + a[i], dp[i - 1][j]);
            if (oks >= 0) dp[i][j] = oks;
        }
        if (dp[i][400000] >= 0) {
            cout << 1 / 0 << endl;
            exit(0);
        }
    }
    cout << dp[n][0];
    return 0;
}

