#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
/* #pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")*/
typedef long long ll;
const ll MAXN = 100 + 2;
const ll MAXK = 10 + 2;
const ll MOD = 1e9 + 9;
const ll MODH = 1e9 + 9;
const long double PI = acos(-1);
const ll p = 41;
const long double EPS = 1e-4;
#define x first
#define y second
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline ll rand(ll a, ll b) {ll c = rng(); return a+((ll)abs(c))%(b-a+1);}
ll binpow(ll a, ll b, ll m) {a %= m;ll res = 1;while (b > 0) {if (b & 1){res = res * a % m;}a = a * a % m;b >>= 1;
}return res;}

map<pair<int,pair<int,int> > , int> dp;
int a[MAXN];
int n;
int solve(int i,int y,int stocks)
{

if(i == n)
      return y;

if(dp.find({i,{y, stocks}}) != dp.end())
     return dp[{i,{y, stocks}}];

  int ret = 0;
  int times = 0;
 
   for(int t = 0 ; t <= stocks ; t++)
        ret = max(ret , solve(i + 1 , y + (t * a[i]), stocks - t));
     

    for(int t = 0 ; t * a[i] <= y ; ++t)
        ret = max(ret , solve(i + 1 , y - (t * a[i]) , stocks + t));


    return ret;
}


int main(){

ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);

cin >> n;
for(int i = 0 ; i < n ;i++)
 cin >> a[i];

cout << solve(0,1000,0) << '\n';


} 