#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1000000007;
const long long int INF = (long long int)1e15;
long long int A[100];
long long int dp[85][3000005];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long int N;
  cin >> N;
  for (long long int(i) = (0); (i) < (N); ++(i)) {
    cin >> A[i];
  }
  memset(dp, 0, sizeof(dp));
  long long int mx = 0;
  dp[0][0] = 1000;
  for (long long int(i) = (0); (i) < (N); ++(i)) {
    for (long long int(j) = (0); (j) < (mx + 1); ++(j)) {
      dp[i + 1][0] = std::max(dp[i + 1][j], dp[i][j] + j * A[i]);
    }
    for (long long int(j) = (0); (j) < (mx + 1); ++(j)) {
      long long int n = dp[i][j];
      dp[i + 1][j] = std::max(dp[i + 1][j], n);
    }
    long long int nxt = 0;
    while (true) {
      long long int n = dp[i + 1][nxt];
      if (n < A[i]) break;
      dp[i + 1][nxt + 1] = std::max(dp[i + 1][nxt + 1], n - A[i]);
      nxt++;
    }
    mx = std::max(mx, nxt);
  }
  long long int ans = 0;
  for (long long int(i) = (0); (i) < (mx + 1); ++(i)) {
    ans = std::max(ans, dp[N][i] + i * A[N - 1]);
  }
  cout << ans << endl;
  return 0;
}
