#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll, ll, ll>>;
using vb = vector<bool>;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const ll INF = 1e15;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
ll dp[2005][2005];
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  vpll v(n);
  for (long long i = (long long)(0); i < (long long)(n); ++i) {
    cin >> v[i].first;
    v[i].second = i;
  }
  sort(v.begin(), v.end());
  ;
  for (ll l = 0; l <= n; l++) {
    for (ll r = n; r >= l; r--) {
      ll idx = r - l;
      if (l > 0) {
        ll tmp = dp[l - 1][r];
        tmp += abs((l - 1) - v[idx].second) * v[idx].first;
        chmax(dp[l][r], tmp);
      }
      if (r < n) {
        ll tmp = dp[l][r + 1];
        tmp += abs(r - v[idx].second) * v[idx].first;
        chmax(dp[l][r], tmp);
      }
      cerr << l << " " << r << " " << idx << " " << dp[l][r] << endl;
    }
  }
  ll ans = 0;
  for (ll i = 0; i <= n; i++) {
    chmax(ans, dp[i][i]);
  }
  cout << ans << endl;
}
