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

#define MAX_N 2020

vector<vector<ll>> dp;
int main(){
  ll N;
  cin >> N;
  vector<pair<ll, int>> A;

  ll t;
  for(int i=0; i<N; i++){
    cin >> t;
    A.push_back(make_pair(t, i));
  }
  sort(A.begin(), A.end(), greater<pair<ll, int>>());


  dp.assign(MAX_N, vector<ll>(MAX_N, 0));

  ll ans = 0;
  for(int i=0; i<N; i++){
    for(int j=0; j<N; j++){
      if(i+j >= N){
        ans = max(ans, dp[i][j]);
        break;
      }
      dp[i+1][j] = max(dp[i][j]+A[i+j].first * abs(A[i+j].second - i), dp[i+1][j]);
      dp[i][j+1] = max(dp[i][j]+A[i+j].first * abs(A[i+j].second -(N-1-j)), dp[i][j+1]);
    }
  }
  cout << ans << endl;;
}