#include <bits/stdc++.h>
using namespace std;
string repeat(string second, int n) {
  string s1 = "";
  for (int i = 0; i < n; i++) s1 += second;
  return s1;
}
string getString(char x) {
  string second(1, x);
  return second;
}
void optimizeIO() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
int gcd(int a, int b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
vector<long long> v(10000005, 1);
void solve() {
  long long n;
  cin >> n;
  const long long N = 10000;
  long long money = 1000;
  long long a[n + 1];
  for (int i = 1; i < n + 1; i++) cin >> a[i];
  vector<vector<long long>> dp(n + 1, vector<long long>(N, -1));
  dp[1][0] = money;
  long long mx = money;
  for (int i = 1; i < N; i++) {
    if (dp[1][i - 1] >= a[1]) {
      dp[1][i] = dp[1][i - 1] - a[1];
      mx = max(mx, dp[1][i]);
    }
  }
  for (int i = 2; i < n + 1; i++) {
    for (int j = 0; j < N; j++) {
      for (int k = j; k < N; k++) {
        if (dp[i - 1][k] != -1)
          dp[i][j] = max(dp[i][j], dp[i - 1][k] + a[i] * (k - j));
        mx = max(mx, dp[i][j]);
      }
    }
    for (int k = 1; k < N; k++) {
      if (dp[i][k - 1] >= a[i]) {
        dp[i][k] = max(dp[i][k], dp[i][k - 1] - a[i]);
        mx = max(mx, dp[i][k]);
      }
    }
  }
  cout << mx << endl;
}
int main() {
  optimizeIO();
  { solve(); }
}
