#include<bits/stdc++.h>
#define N 2005
#define ll long long
#define pb push_back
#define x first
#define y second
#define all(v) v.begin(),v.end()
using namespace std;
ll n;
vector< pair< ll , ll > > ar;
ll dp[N][N];
ll rec(ll l, ll r){
    if(l>r)return 0;
    if(dp[l][r]!=-1)return dp[l][r];
    int in = l-1 + n - r;
    return dp[l][r] = max(rec(l+1,r)+(ar[in].x*(abs(ar[in].y-l))), rec(l,r-1)+(ar[in].x*(abs(ar[in].y-r))) );
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n;
    ar.resize(n);
    for(int i=0;i<n;i++){
        cin>>ar[i].x;
        ar[i].y = i;
    }
    sort(all(ar));
    reverse(all(ar));
    memset(dp,-1,sizeof(dp));
   cout<< rec(0,n-1);
    
    
    return 0;
}
