#include <bits/stdc++.h>
 
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define ll long long
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define VAR(v, i) __typeof( i) v=(i)
#define forit(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
 
using namespace std;
 
const int maxn = (int)2e5 + 10;
const int maxM = (int)1.5e7 + 100;
const int mod = (int)1e9 + 7;
const int P = (int) 1e6 + 7; 
const double pi = acos(-1.0);
 
#define inf mod
 	
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;   
typedef vector<ll> Vll;               
typedef vector<pair<int, int> > vpii;
typedef vector<pair<ll, ll> > vpll;                        
typedef array<int, 3> triple;
 
int n, k, a[maxn];
int dp[82][80 * 210][82];
int calc(int pos, int yen, int stock){
    if(stock > n) return yen;
	if(pos == n + 1) return yen;
	int &res = dp[pos][yen][stock];
	if(res != -1) return res;
	int i = pos;
	forn(step, 0, inf){
	    bool ok = 0;
	    if(yen - step * a[i] >= 0) res = max(res, calc(pos + 1, yen - step * a[i], stock + step)), ok = 1;
	    if(stock >= step) res = max(res, calc(pos + 1, yen + step * a[i], stock - step)), ok = 1;
	    if(!ok) break;
	}
	return res;
}
void solve(){
	cin >> n;
	forn(i, 1, n) cin >> a[i];
	memset(dp, -1, sizeof(dp));
	cout << calc(1, 1000, 0) << endl;
}
 
main () {
	int t = 1;
	//cin >> t;
	while(t--)
		solve(); 
}	 