#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pll = pair<ll, ll>;
const ll INF = 1e18;
const ll mod = 1e9 + 7;
const double pie = acos(-1);
vll dx4 = {-1, 0, 1, 0};
vll dy4 = {0, -1, 0, 1};
vll dx8 = {-1, 0, 1, 1, 1, 0, -1, -1};
vll dy8 = {-1, -1, -1, 0, 1, 1, 1, 0};
void fix_cout() { cout << fixed << setprecision(20); }
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
void chmax(ll &a, ll b) {
  if (a < b) a = b;
}
void chmin(ll &a, ll b) {
  if (a > b) a = b;
}
int main() {
  ll n;
  cin >> n;
  vll a(n);
  for (auto &i : a) cin >> i;
  vvll dp(n + 1, vll(1000, -1));
  dp.at(0).at(0) = 1000;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < 1000; j++) {
      ll mx = -1;
      for (int k = 0; k < 1000; k++) {
        if (dp.at(i - 1).at(k) == -1) continue;
        if (j <= k) {
          chmax(mx, (k - j) * a.at(i - 1) + dp.at(i - 1).at(k));
        } else {
          chmax(mx, dp.at(i - 1).at(k) - (j - k) * a.at(i - 1));
        }
      }
      dp.at(i).at(j) = mx;
    }
  }
  ll ans = 0;
  for (int i = 0; i < 1000; i++) chmax(ans, dp.at(n).at(i));
  cout << ans << endl;
}
