#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=2e3+5;
ll dp[N][N],n,k;
vector<pair<ll,ll> >v;

ll solve(ll l,ll r){
    if(r<l) return 0;
    if(dp[l][r]!=-1) return dp[l][r];
    ll i=l+n-r-1;
    return dp[l][r]=max(v[i].first*abs(v[i].second-l)+solve(l+1,r),v[i].first*abs(v[i].second-r)+solve(l,r-1));
}

int main(){
    cin>>n;
    for(ll i=0;i<n;i++){
        cin>>k;
        v.push_back({k,i});
    }
    sort(v.rbegin(),v.rend());
    memset(dp,-1,sizeof(dp));
    cout<<solve(0,n-1);
    return 0;
}

