#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vpii = vector<pii>;
struct yo {
  ll g;
  int a, n;
  bool operator<(const yo& rhs) const { return a < rhs.a; }
};
void max_u(ll& m, ll v) {
  if (m < v) m = v;
}
void dump(vvll& dp) {
  for (auto& mdp : dp) {
    for (auto& mmdp : mdp) printf("%2lld ", mmdp);
    printf("\n");
  }
}
int main(void) {
  int n;
  while (scanf("%d", &n) == 1) {
    vector<yo> yoji(n);
    for (int i = 0; i < n; i++) {
      scanf("%d", &yoji[i].a);
      yoji[i].n = i;
    }
    sort(yoji.rbegin(), yoji.rend());
    vvll dp(n + 1);
    for (int i = 0; i <= n; i++) {
      dp[i].resize(n - i + 1);
    }
    for (int i = 0; i < n; i++) {
      auto& x = yoji[i];
      for (int s = 0; s <= i; s++) {
        int t = i - s;
        int l = n - 1 - t;
        max_u(dp[s + 1][t], dp[s][t] + abs(x.n - s) * x.a);
        max_u(dp[s][t + 1], dp[s][t] + abs(x.n - l) * x.a);
      }
    }
    ll ans = 0;
    for (int i = 0; i <= n; i++) {
      max_u(ans, dp[i][n - i]);
    }
    printf("%lld\n", ans);
  }
  return 0;
}
