#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int N=2020;
int n;
int a[N],p[N];
ll dp[N][N];

ll f(int l,int r)
{
    int dep=l+r+1;
    if (dep>n) {
        return 0;
    }
    if (dp[l][r]!=-1) return dp[l][r];
    if (dep==n) {
        return dp[l][r]=1LL*a[p[n]]*abs(l+1-p[n]);
    }
    ll res=max(1LL*a[p[dep]]*abs(l+1-p[dep])+f(l+1,r), 1LL*a[p[dep]]*abs(n-r-p[dep])+f(l,r+1));
    return dp[l][r]=res;
}

int main()
{
    scanf("%d",&n);
    for (int i=1;i<=n;i++) {
        scanf("%d",&a[i]);
        p[i]=i;
    }
    sort(p+1,p+n+1,[&](const int &i,const int &j){ return a[i]>a[j]; });
    memset(dp,-1,sizeof(dp));
    printf("%lld\n",f(0,0));
    return 0;
}