#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;
using P = pair<ll,int>;
const ll INF = 1e17;

int main(){
  int n;
  cin >> n;
  P c[n];
  rep(i,n) {
    cin >> c[i].first;
    c[i].second = i;
  }
  sort(c,c+n,greater<P>());
  vector<vector<ll>> dp(n+1,vector<ll>(n+1,-INF));
  dp[0][0] = 0;
  rep(i,n) {
    rep(j,n) {
      dp[i+1][j+1] = max(dp[i+1][j+1],dp[i][j]+c[i].first*abs(c[i].second-j));
      dp[i+1][j] = max(dp[i+1][j],dp[i][j]+c[i].first*abs(c[i].second-(n-1-i+j)));
    }
  }
  ll ans = 0;
  rep(i,n+1) ans = max(ans,dp[n][i]);
  cout << ans << endl;
  return 0;
}
