#include<bits/stdc++.h>
#define int long long
#define ff first
#define ss second
#define pii pair<long long,long long>
using namespace std;

int MOD = (1e9)+7;
const int N = 2005;

pii a[N];
int dp[N][N],n;

int rec(int l,int r)
{
    if(l>r)
        return 0;
    if(dp[l][r]!=-1)
        return dp[l][r];
    int id = n-r+l;
    dp[l][r] = max(rec(l+1,r)+(a[id].ff*abs(a[id].ss-l)),rec(l,r-1)+(a[id].ff*abs(a[id].ss-r)));
    return dp[l][r];
}

signed main()
{
    memset(dp,-1,sizeof(dp));
    cin>>n;
    for(int i=1; i<=n; i++)
        cin>>a[i].ff,a[i].ss=i;
    sort(a+1,a+n+1);
    for(int i=1,j=n; i<j; i++,j--)
        swap(a[i],a[j]);
    cout<<rec(1,n)<<endl;
    return 0;
}
