#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N; cin >> N;
  vector<pair<ll, int>> v(N);
  for (int i = 0; i < N; i++) {
    cin >> v[i].first;
    v[i].second = i;
  }
  sort(v.rbegin(), v.rend());
  vector<vector<ll>> dp(N+1, vector<ll>(N+1));
  for (int l = 0; l < N; l++) {
    for (int r = 0; l + r < N; r++) {
      ll lp = l;
      ll rp = N - r - 1;
      auto [val, p] = v[l + r];
      dp[l+1][r] = max(dp[l+1][r], dp[l][r] + abs(p - lp) * val);
      dp[l][r+1] = max(dp[l][r+1], dp[l][r] + abs(p - rp) * val);
    }
  }
  ll res = 0;
  for (int i = 0; i <= N; i++) {
    res = max(res, dp[i][N-i]);
  }
  cout << res << endl;
}
  
