#include<bits/stdc++.h>
using namespace std;
int main(){
  long long i,j,N,M;
  cin>>N;
  vector<pair<long long,long long>> v(N);
  vector<vector<long long>> dp(N+1,vector<long long>(N+1,0));
  for(i=0;i<N;++i){
    cin>>v[i].first;
    v[i].second=i;
  }
  //降順ソート
  sort(v.rbegin(),v.rend());
  //(配る)dp
  for(i=0;i<N;++i){
    for(j=0;j<=i;++j){
      dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+v[i].first*abs(v[i].second-j));
      dp[i+1][j]=max(dp[i+1][j],dp[i][j]+v[i].first*abs(N-1-i+j-v[i].second));
    }
  }
  //答えはN番目まで見たときの最大値
  cout<<*max_element(dp[N].begin(),dp[N].end())<<endl;
}