#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n;
  cin >> n;
  vector<P> a(n);
  for (int i = 0; i < (int)(n); ++i) {
    int x;
    cin >> x;
    a[i] = P(x, i);
  }
  sort(a.rbegin(), a.rend());
  vector<vector<ll>> dp(n + 1, vector<ll>(n + 1));
  for (int i = 0; i < (int)(n); ++i) {
    for (int j = 0; j < (int)(i + 1); ++j) {
      int k = i - j;
      dp[j + 1][k] =
          max(dp[j + 1][k], dp[j][k] + a[i].first * (a[i].second - j));
      dp[j][k + 1] =
          max(dp[j][k + 1], dp[j][k] + a[i].first * (n - k - 1 - a[i].second));
    }
  }
  ll ans = 0;
  for (int i = 0; i < (int)(n + 1); ++i) {
    ans = max(ans, dp[i][n - i]);
  }
  cout << ans << endl;
  return (0);
}
