#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 1000000007;
#define lcm(x, y) ((x) * (y) / __gcd((x), (y)))
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define debug(x) cout << #x << " : " << x << endl
#define part cout << "----------------------------------\n";
#include <iostream>

int dx[] = {1, 1, 0, -1, -1, -1, 0, 1}; // trick to explore an implicit 2D grid
int dy[] = {0, 1, 1, 1, 0, -1, -1, -1}; // S,SE,E,NE,N,NW,W,SW neighbors  //GO FOR EVEN FOR 4 moves

#define fastinput                     \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

LL POW(LL x, LL y)
{
    LL ans = 1;
    LL base = x;
    while (y)
    {
        if (y & 1)
        {
            ans *= base;
        }
        base = base * base;
        y = y >> 1;
    }
    return ans;
}

int main()
{
    fastinput;
    LL n, i, j, k, t, temp, tc;
    cin >> n;
    //dp[i][j]->ith day, j stocks
    const LL M = 22;
    LL dp[n + 1][M + 1] = {0};
    const LL INF = 10000000000000000;
    for (i = 0; i <= n; i++)
    {
        for (j = 0; j <= M; j++)
        {
            dp[i][j] = -INF;
        }
    }
    dp[0][0] = 1000;
    LL cost[n + 1];
    for (i = 1; i <= n; i++)
    {
        cin >> cost[i];
    }

    for (i = 1; i <= n; i++)
    {
       // debug(i);
        for (j = 0; j <= M; j++)
        {
            LL curr_maxima = -INF;
            for (k = 0; k <= M; k++)
            {
                //debug(k);
                LL consider = -INF;
                if (j == k)
                {
                    consider = dp[i - 1][k];
                }
                else if (k < j)
                {
                    //prev had lesser-> now have more -> buy ->money loss
                    LL extra = j - k;
                    if (dp[i - 1][k] >= 0)
                    {
                        if (dp[i - 1][k] - cost[i] * extra >= 0)
                        {
                            consider = dp[i - 1][k] - cost[i] * extra;
                        }
                    }
                }
                else
                {
                    //prev->has more -> sell
                    LL extra = k - j;
                    if (dp[i - 1][k] >= 0 - INF)
                    {
                        consider = dp[i - 1][k] + cost[i] * extra;
                    }
                }
                //debug(consider);
                dp[i][j] = max(dp[i][j], consider);
                // part;
            }
            // cout << "at " << j << " "
            //      << " max is " << dp[i][j] << endl;
            //cout << "======================" << endl;
            // if (j ==2)
            //     return 0;
        }
       // part;
    }

    LL ans = -1;
    for (i = 0; i <= M; i++)
    {
        ans = max(ans, dp[n][i]);
    }
    cout << ans << endl;

    return 0;
}
