#include<bits/stdc++.h>
using namespace std;
#define ll long long

const int mxn = 2010;

pair<ll,ll> a[mxn];
ll dp[mxn][mxn];

int main(){
  int n;
  cin >> n;
  for(int i = 0;i < n; ++i){
    cin >> a[i].first;
    a[i].second = i;
  }  
  
  // dp[l][r] -> l elements in left and r elements in right
  ll ans = 0;
  sort(a,a+n,greater<pair<ll,ll>>());
  for(int l = 0;l < n; ++l){
    for(int r = 0;r < n; ++r){
      int i = l + r;
      if(i >= n) continue;
      dp[l + 1][r] = max(dp[l + 1][r],dp[l][r] + a[i].first*(abs(l - a[i].second)));
      dp[l][r + 1] = max(dp[l][r + 1],dp[l][r] + a[i].first*(abs(n - 1 - r - a[i].second)));

      ans = max({ans,dp[l + 1][r],dp[l][r + 1]});
    }
  }
  cout << ans;
}