#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("mmx,sse,sse2")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

template<class T>
using ordered_set = tree <T, null_type ,  less<T> ,  rb_tree_tag ,  tree_order_statistics_node_update>;

template<class T>
using ordered_multiset = tree <T, null_type ,  less_equal<T> ,  rb_tree_tag ,  tree_order_statistics_node_update>;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using vi = vector<int>;
using ii = pair<int, int>;
using vii = vector<ii>;
using vvi = vector<vi>;
using vvii = vector<vii>;
const int maxn = 81, maxe = 5120;
int dp[maxe + 1][maxn];
bool vis[maxe + 1][maxn];
int main() {
	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n, a[maxn];
	cin >> n;
	for(int i = 1; i <= n; ++i) 
		cin >> a[i];
	for(int i = 0; i <= maxe; ++i) {
		for(int k = 0; k <= n; ++k) {
			dp[i][k] = 0;
			vis[i][k] = false;
		}
	}
	dp[0][0] = 1000;
	vis[0][0] = true;
	for(int i = 1; i <= n; ++i) {
		for(int k = 0; k <= maxe; ++k) {
			dp[k][i] = dp[k][i - 1];
			vis[k][i] = vis[k][i - 1];
		}
		for(int k = maxe; k; --k) {
			if(vis[k][i]) {
				vis[k - 1][i] = true;
				dp[k - 1][i] = max(dp[k - 1][i], dp[k][i] + a[i]);
			}	
		}
		for(int k = 0; k < maxe; ++k) {
			if(vis[k][i] && dp[k][i] - a[i] >= 0) {
				vis[k + 1][i] = true;
				dp[k + 1][i] = max(dp[k + 1][i], dp[k][i] - a[i]);
			}
		}
	}
	int res = 0;
	for(int i = 0; i <= maxe; ++i) {
		if(vis[i][n])
			res = max(res, dp[i][n]);
	}
	cout << res << '\n';
	return 0;
}