#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
class CompareFirst {
 public:
  bool operator()(P n1, P n2) { return n1.first < n2.first; }
};
void Main() {
  int N;
  cin >> N;
  priority_queue<P, vector<P>, CompareFirst> q;
  for (ll i = 0; i < (ll)(N); i++) {
    ll a;
    cin >> a;
    q.push(make_pair(a, i));
  }
  ll dp[N + 1][N + 1];
  for (ll i = 0; i < (ll)(N + 1); i++) {
    for (ll j = 0; j < (ll)(N + 1); j++) {
      dp[i][j] = 0;
    }
  }
  for (ll i = 1; i < (ll)(N + 1); i++) {
    auto p = q.top();
    q.pop();
    ll score = p.first;
    ll ind = p.second;
    for (ll j = 0; j < (ll)(i + 1); j++) {
      ll k = i - j;
      cout << j << " " << k << endl;
      if (k - 1 >= 0) {
        dp[j][k] = max(dp[j][k],
                       dp[j][k - 1] + score * abs(((N - 1) - (k - 1)) - ind));
      }
      if (j - 1 >= 0) {
        dp[j][k] = max(dp[j][k], dp[j - 1][k] + score * abs(ind - (j - 1)));
      }
    }
  }
  ll ans = 0;
  for (ll i = 0; i < (ll)(N + 1); i++) {
    if (dp[i][N - i] > ans) {
      ans = dp[i][N - i];
    }
  }
  cout << ans << endl;
}
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
  return 0;
}
