#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;
const ll inf = (1e18);
const ll mod = 1000000007;
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll c, ll d) { return c / GCD(c, d) * d; }
struct __INIT {
  __INIT() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
  }
} __init;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
ll dp[2005][2005];
int main() {
  int n;
  cin >> n;
  V<P> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i].first;
    a[i].second = i;
  }
  sort((a).begin(), (a).end(), greater<P>());
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= i; j++) {
      chmax(dp[j + 1][n - (i - j)],
            dp[j][n - (i - j)] + a[i].first * abs(j - a[i].second));
      chmax(
          dp[j][n - (i - j) - 1],
          dp[j][n - (i - j)] + a[i].first * abs(n - (i - j) - a[i].second - 1));
    }
  }
  ll ans = 0;
  for (int i = 0; i <= n; i++) chmax(ans, dp[i][n - i]);
  cout << ans << "\n";
}
