#include <bits/stdc++.h>
using namespace std;
long long int a[100], dp[1000000], pre[1000000], suf[1000000],
    hell = 5 * pow(10, 17);
void solve() {
  long long int n;
  cin >> n;
  for (long long int i = 1; i <= n; i++) cin >> a[i];
  for (long long int j = 0; j < 1000000; j++) dp[j] = (-hell);
  dp[0] = 1000;
  for (long long int i = 1; i <= n; i++) {
    for (long long int j = 0; j < 1000000; j++) {
      pre[j] = dp[j] + j * a[i];
      if (pre[j] < 0) pre[j] = (-hell);
      if (j) pre[j] = max(pre[j], pre[j - 1]);
    }
    for (long long int j = 999999; j >= 0; j--) {
      suf[j] = dp[j] + j * a[i];
      if (suf[j] < 0) suf[j] = (-hell);
      if (j != 999999) suf[j] = max(suf[j], suf[j + 1]);
    }
    for (long long int j = 0; j < 1000000; j++) dp[j] = (-hell);
    for (long long int j = 0; j < 1000000; j++) {
      if (pre[j] >= a[i] * j) dp[j] = max(dp[j], pre[j] - a[i] * j);
      if (suf[j] >= a[i] * j) dp[j] = max(dp[j], suf[j] - a[i] * j);
    }
  }
  long long int res = 0;
  for (long long int i = 0; i < 1000000; i++) res = max(res, dp[i]);
  cout << res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int qc = 1;
  for (long long int i = 1; i <= qc; i++) solve();
}
