#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5+100;
const ll mod = 1e9+7;
pair<ll,ll> p[maxn];
ll dp[2100][2100];
int main() {
    int n;
    cin>>n;
    for(int i=1,x;i<=n;i++)
    cin>>x,p[i]={x,i};
    sort(p+1,p+1+n);
    for(int i=1;i<=n;i++)
        dp[i][i]=p[1].first*abs(p[1].second-i);
    for(int L = 2;L<=n;L++){
        for(int i=1;i+L-1<=n;i++){
            int j = i+L-1;
            dp[i][j]=max(dp[i+1][j]+p[L].first*abs(p[L].second-i),dp[i][j-1]+p[L].first*abs(p[L].second-j));
        }
    }
    cout<<dp[1][n]<<endl;
}
