#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
}
using P = pair<int, int>;
const long long INF = 1e18;
long long dp[2005][2005];
int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  for (long long i = 0; i < (long long)(n); ++i) cin >> a[i];
  for (long long i = 0; i < (long long)(n + 1); ++i)
    for (long long j = 0; j < (long long)(n + 1); ++j) dp[i][j] = -INF;
  dp[0][0] = 0;
  vector<P> p;
  for (long long i = 0; i < (long long)(n); ++i) p.emplace_back(a[i], i);
  sort(p.rbegin(), p.rend());
  for (long long i = 0; i < (long long)(n); ++i) {
    int pi = p[i].second;
    for (long long l = 0; l < (long long)(i + 1); ++l) {
      int r = i - l;
      chmax(dp[i + 1][l + 1], dp[i][l] + long long(pi - l) * a[pi]);
      chmax(dp[i + 1][l], dp[i][l] + long long((n - r - 1) - pi) * a[pi]);
    }
  }
  long long ans = 0;
  for (long long i = 0; i < (long long)(n + 1); ++i) chmax(ans, dp[n][i]);
  cout << ans << endl;
  return 0;
}
