#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define mp make_pair
#define pb(x) push_back(x)
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pcc pair<char, char>
#define pdd pair<double, double>
#define mll map<long long, long long>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define flsh fflush(stdout)
#define gcd __gcd
#define clr(x) memset(x, 0, sizeof(x))
#define mod 1000000007LL
#define mod2 998244353LL
#define INF 1000000000007
 

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> o_tree;


void solve()
{
  ll n;
  cin>>n;
  ll i,j;
  ll a[n];
  ll dp[n][22];
  clr(dp);

  for(i=0;i<n;i++)
  {
      cin>>a[i];
  }
  for(i=0;i<n;i++)
  {
      for(j=0;j<21;j++)
      {
          dp[i][j]=-1e18;
      }
  }
  for(i=0;i<21;i++)
  {
      ll no = a[0]*i;
      if(no>1000)
      {
          continue;
      }  
      dp[0][i]=(1000-no);
  }

  for(i=1;i<n;i++)
  {
      for(j=0;j<21;j++)
      {
          for(ll k=0;k<21;k++)
          {
              if(j>k)
              {
                  ll no = dp[i-1][k]+(k-j)*a[i];
                  if(no<0)continue;
                  dp[i][j]=max(dp[i][j],dp[i-1][k]+(k-j)*a[i]);
              }
              else{
                  ll no = dp[i-1][k]+(k-j)*a[i];
                  if(no<0)continue;
                  dp[i][j]=max(dp[i][j],dp[i-1][k]+(k-j)*a[i]);
              }
          }
      }
  }
  ll res=1000;
  for(i=0;i<n;i++)
  {
      for(j=0;j<21;j++)
      {
        //   cout<<dp[i][j]<<" ";
          res=max(res,dp[i][j]);
      }
    //   cout<<"\n";
  }
  cout<<res<<"\n";



}


int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);


if (fopen("input.txt","r" ))
  {
     freopen("input.txt", "r", stdin);
     freopen("output.txt", "w", stdout);
  }
cout<<setprecision(20);


ll t=1;


// cin>>t;


while(t--)
{
solve();
} 


return 0;
}