#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long ll;
typedef pair<ll,int> P;
int n;
vector<P> A;
ll dp[2005][2005];
ll next[2005][2005];
ll ans;
int main() {

  cin >> n;


  
  for(int i = 0; i < n; i++) {
    ll a;
    cin >> a;

    A.push_back(P(a,i));
  }

  sort(A.begin(),A.end(),greater<P> ());

  // for(int i = 0; i < n; i++) cout << A[i].first <<" "<<A[i].second<< endl;

  for(ll i = 0; i < n; i++) {
    for(ll j = 0; j <= i+1; j++) {
      ll k = i - j + 1;
      if(j == 0) {
	next[j][k] = dp[j][k-1]+abs(n-k-A[i].second)*A[i].first;
	continue;
      }
      if(k == 0) {
	next[j][k] = dp[j-1][k]+abs(A[i].second-j+1)*A[i].first;
	continue;
      }
      next[j][k] = max(dp[j-1][k]+abs(A[i].second-j+1)*A[i].first,dp[j][k-1]+abs(n-k-A[i].second)*A[i].first);
    }
    swap(next,dp);
    /* cout << i << endl;
     for(int ii = 0; ii <= i+1; ii++) {
       int j = i - ii + 1;
    cout <<"dp["<<ii<<"]["<<j<<"] = "<< dp[ii][j] << endl;
    }*/
  }
 
  for(int i = 0; i <= n; i++) {
    int j = n - i;
    ans = max(ans,dp[i][j]);
    //cout <<"dp["<<i<<"]["<<j<<"] = "<< dp[i][j] << endl;
  }
  cout << ans << endl;
    
}
  
