#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
int main() {
  ll n;
  cin >> n;
  vector<P> a(n);
  for (ll i = 0; i < (n); ++i) {
    cin >> a[i].first;
    a[i].second = i;
  }
  sort(a.rbegin(), a.rend());
  vector<vector<int>> h(2020, vector<int>(2020));
  for (ll i = 0; i < (n); ++i) {
    for (ll j = 0; j < (n); ++j) {
      h[i][j] = a[j].first * max(a[j].second - i, i - a[j].second);
    }
  }
  vector<vector<int>> dp(2020, vector<int>(2020));
  dp[0][0] = 0;
  int fromU = 0, fromR = 0;
  bool fU = false;
  for (ll i = 0; i < (n); ++i) {
    for (ll j = 0; j < (n); ++j) {
      fU = false;
      if (i > 0) {
        fromU = dp[i - 1][j] + h[n - i][i + j - 1];
        fromR = 0;
        fU = true;
      }
      if (j > 0) {
        fromR = dp[i][j - 1] + h[j - 1][i + j - 1];
        if (fU == false) fromU = 0;
      }
      dp[i][j] = max(fromU, fromR);
    }
  }
  int mx = 0;
  for (ll i = 0; i < (n); ++i) {
    for (ll j = 0; j < (n); ++j) {
      if ((i + j) == n) {
        mx = max(mx, dp[i][j]);
      }
    }
  }
  cout << mx << endl;
}
