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