#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  const int maxn = 2e3;
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto &i : a) cin >> i;
  long long ans = 0;
  vector<vector<long long>> dp(90, vector<long long>(maxn, -1));
  for (int i = 0; a[0] * i <= 1000; i++) dp[0][i] = 1000 - a[0] * i;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < maxn; j++) {
      for (long long k = 0; k < maxn; k++) {
        if (j <= k && dp[i][j] >= a[i + 1] * (k - j)) {
          dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] - a[i + 1] * (k - j));
        }
        if (j >= k && dp[i][j] != -1) {
          dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + a[i + 1] * (j - k));
        }
      }
      ans = max(ans, *max_element(dp[i].begin(), dp[i].end()));
    }
  }
  cout << ans << '\n';
  return 0;
}
