#include<iostream>
#include<unordered_map>
#include<bitset>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<ctype.h>
#include<unordered_set>
#include<string>
#include<iomanip>
#include<queue>
#include<limits>
#include<map>
#include<stack>
#include<iterator>
#include<cstring>
 
#include<deque>
#define pi 3.141592653589793238
#include<chrono>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define MOD 1000000007
#define INF 999999999999999999 
#define pb push_back
#define ff first
#define ss second
 
#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
 
 
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    ll T = 1, i, j;
    
    //cin >> T;
    while (T--) {
        ll n;
        cin >> n;
        vector<ll> v(n);
        for(i = 0; i < n; i++){
            cin >> v[i];
        }
        //dp[i][j]  is max money left if he has j stocks on the ith day
        vector<vector<ll>> dp(n + 1, vector<ll>(1001, -INF));
        for(i = 0; i < 1001; i++){
            dp[1][i] = 1000 - v[0] * (i);
            if(dp[1][i] < 0){
                dp[1][i] = -INF;
            }
        }
        for(i = 1; i < n; i++){
            for(j = 0; j < 1001; j++){
                for(ll it = 0; it <= 1000; it++){
                    if(dp[i][it] < 0){
                        continue;
                    }
                    
                    dp[i + 1][j] = max(dp[i + 1][j], dp[i][it] - (j - it) * v[i]); 
                }
            }
        }
        cout << dp[n][0];
    }
    return 0;
}