#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int a[N];
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  long long money[1000][N];
  for (int m = 0; m < 1000; m++) {
    for (int n = 0; n < N; n++) {
      money[m][n] = -10000000;
    }
  }
  for (int m = 0; m < 1000; m++) {
    if (a[0] * m <= 1000) {
      money[m][0] = 1000 - a[0] * m;
    }
  }
  for (int n = 1; n < N; n++) {
    if (a[n] > a[n - 1]) {
      for (int m = 0; m < 1000; m++) {
        money[m][n] = money[m][n - 1];
        for (int im = m; im < 1000; im++) {
          money[m][n] = max(money[m][n], money[im][n - 1] + (im - m) * a[n]);
        }
      }
    } else {
      for (int m = 0; m < 1000; m++) {
        money[m][n] = money[m][n - 1];
        for (int im = 0; im <= m; im++) {
          long long tmp = money[im][n - 1] - (m - im) * a[n];
          if (tmp >= 0) {
            money[m][n] = max(money[m][n], tmp);
          }
        }
      }
    }
  }
  long long sum = 0;
  for (int i = 0; i < 1000; i++) {
    sum = max(sum, money[i][N - 1] + a[N - 1] * i);
  }
  cout << sum << endl;
}
