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

int main(){
  long long N;
  cin >> N;
  vector<pair<long long,long long>> A(N);
  for(int i=0;i<N;i++){
    long long a;
    cin >> a;
    A[i] = make_pair(a,i);
  }
  sort(A.rbegin(),A.rend());
  
  vector<vector<long long>> dp(N+1,vector<long long>(N+1,0));
  for(int i=0;i<N;i++){
    for(int j=0;j<=i;j++){
      dp[i+1][j+1] = max(dp[i+1][j+1], abs(A[i].second-j)*A[i].first + dp[i][j]);
      dp[i+1][j] = max(dp[i+1][j], abs(A[i].second-(N-(i+1-j)))*A[i].first + dp[i][j]);
    }
  }
  
  long long ans=0;
  for(int i=0;i<=N;i++) ans = max(ans,dp[N][i]);
  cout << ans << endl;
  return 0;
}
