#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e3+5;
vector<pair<ll,int>> V;
int n;
ll dp[maxn][maxn];
int main() {
    cin>>n;
    for(int i=1;i<=n;i++){ll a;cin>>a;V.push_back({a,i});}
    sort(V.begin(),V.end(),greater<pair<ll,int>>());
    for(int i=0;i<n;i++){
        dp[0][i+1]=dp[0][i]+abs(n-i-V[i].second)*V[i].first;
        dp[i+1][0]=dp[i][0]+abs(i+1-V[i].second)*V[i].first;
        for(int j=1;j<=i;j++){
            dp[j][i+1-j]=max(dp[j-1][i+1-j]+abs(j-V[i].second)*V[i].first,
                            dp[j][i-j]+abs(n-(i-j)-V[i].second)*V[i].first);
        }
    }
    ll mx=0;
    for(int i=0;i<=n;i++) mx=max(mx,dp[i][n-i]);
    cout<<mx<<endl;
    return 0;
}