#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
pair<ll,ll> a[2005];
ll d[2005][2005];
int main(){
    ll n,ans=0;
    cin>>n;
    for(ll i=1;i<=n;i++){
        cin>>a[i].first;
        a[i].second=i;
    }
    sort(a+1,a+1+n);
    reverse(a+1,a+1+n);
    for(ll i=1;i<=n;i++){
        for(ll j=0;j<=i;j++){
            ll x=n+1-(i-j),p=a[i].second,v=a[i].first;
            if(j==0&&x<n+1) d[j][x]=d[j][x+1]+abs(x-p)*v;
            else if(x==n+1&&j>0) d[j][x]=d[j-1][x]+abs(j-p)*v;
            else d[j][x]=max(d[j][x+1]+abs(x-p)*v,d[j-1][x]+abs(j-p)*v);
            ans=max(ans,d[j][x]);
        }
    }
    cout<<ans<<endl;
}   