#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
int n;
int a[2002];
pii p[2002];
LL dp[2002][2002];
LL dfs(int s, int e){
    if(s > e) return 0;
    if(dp[s][e] != -1) return dp[s][e];
    int idx = s-1 + n-e + 1;
    return dp[s][e] = max(dfs(s+1, e) + abs(s-p[idx].second)*1ll*p[idx].first, dfs(s, e-1) + abs(e-p[idx].second)*1ll*p[idx].first);
}
int main(){
    scanf("%d", &n);
    for(int i=1;i<=n;i++){
        scanf("%d", &a[i]);
        p[i] = pii(a[i], i);
    }   
    sort(p+1, p+1+n);
    reverse(p+1, p+1+n);
    memset(dp, -1, sizeof(dp));
    printf("%lld\n", dfs(1, n));
}