#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
random_device rnd;
mt19937 mt(rnd());
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7;
int main() {
  int n;
  cin >> n;
  vector<PII> p(n);
  for (int i = (0); i < (n); ++i) {
    cin >> p[i].first;
    p[i].second = i;
  }
  sort(p.begin(), p.end(), greater<PII>());
  VVL dp(n + 1, VL(n + 1, -1));
  dp[0][0] = 0;
  for (int i = (0); i < (n); ++i) {
    dp[i + 1][0] = dp[i][0] + abs(p[i].second - i) * p[i].first;
    dp[0][i + 1] = dp[0][i] + abs(n - 1 - i - p[i].second) * p[i].first;
  }
  cerr << dp[n][0] << endl;
  for (int i = (1); i < (n); ++i) {
    for (int j = (1); j < (n); ++j) {
      if (i + j > n) {
        continue;
      }
      assert(dp[i][j - 1] != -1);
      assert(dp[i - 1][j] != -1);
      dp[i][j] = max(dp[i - 1][j] + abs(p[i + j - 1].second - (i - 1)) *
                                        p[i + j - 1].first,
                     dp[i][j - 1] + abs(n - 1 - (j - 1) - p[i + j - 1].second) *
                                        p[i + j - 1].first);
    }
  }
  ll ans = 0;
  for (int i = (0); i < (n + 1); ++i) {
    ans = max(ans, dp[i][n - i]);
  }
  cout << ans << endl;
  return 0;
}
