#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define xx first
#define yy second

pll a[2009];
ll dp[2009][2009],n;

ll solve(ll i,ll j)
{
    if(i==(n+1)) return 0LL;
    if(dp[i][j]!=-1) return dp[i][j];
    ll k = n-(i-j);
    ll ans1 = a[i].xx * (abs(a[i].yy-j)) + solve(i+1,j+1);
    ll ans2 = a[i].xx * (abs(a[i].yy-k)) + solve(i+1,j);
    return dp[i][j]=max(ans1,ans2);
}

int main()
{
    cin >> n;
    for(ll i=1;i<=n;i++)
    {
        cin >> a[i].xx;
        a[i].yy=i;
    }
    sort(a+1,a+n+1,greater<pll>());
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=n;j++) dp[i][j]=-1LL;
    }
    cout << solve(1,1) << endl;

}
