#include<bits/stdc++.h>
using namespace std;
#define  ll  long long
#define  pi  pair<ll,ll>
#define  F   first
#define  S   second
const int N=2e3+3;
pi a[N];
ll n,d[N][N];
ll go(ll l,ll r,ll i)
{
    if(l>r) return 0ll;
    else if(d[l][r]!=-1) return d[l][r];
    ll lv=abs(a[i].S-l)*a[i].F+go(l+1ll,r,i+1);
    ll rv=abs(a[i].S-r)*a[i].F+go(l,r-1ll,i+1);
    return d[l][r]=max(lv,rv);
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n;
    for(ll m,i=0ll;i<n;i++){
        cin>>m;
        a[i]={m,i};
    }
    sort(a,a+n,greater<pi>());
    memset(d,-1,sizeof(d));
    cout<<go(0ll,n-1ll,0ll)<<"\n";
    return 0;
}