#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define pb push_back
#define vi vector<int >
#define vii vector < pair<int ,int > >
#define IO ios::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define IOfiles freopen("input.txt","r+",stdin) ; freopen("output.txt","w+",stdout)
#define PI 3.14159265
const long long mod = 1e9 + 7LL;
typedef long long ll;
typedef pair<int, int> ii;
typedef double db;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;}
ll pwr(ll x , ll n) { ll ans = 1; while (n) {ans *= x; n--;} return ans;}

void solve(){
    
}

int main()
{
    IO;
    ll n;
    cin>>n;
    ll dp[n][n];
    memset(dp,-1,sizeof dp);
    vector<pair<ll , ll > > v;
    for(int i=0;i<n;i++){
        ll val;
        cin>>val;
        v.pb(make_pair(val,i));
    }
    sort(all(v));
    dp[0][n-1]=0;
    ll ans=0;
    
    for(int i=0;i<n;i++){
        for(int j=n-1;j>=i;j--){
            int p=j-i;
            if(p==0){
                dp[i][j]+=v[0].fi*abs(v[0].se-i);
                ans=max(ans,dp[i][j]);
                continue;
            }
            /*cout<<i<<" "<<j<<" ";
            cout<<p<<endl;*/
            dp[i+1][j]=max(dp[i+1][j],dp[i][j]+v[p].fi*abs(v[p].se-i));
            dp[i][j-1]=max(dp[i][j-1],dp[i][j]+v[p].fi*abs(v[p].se-j));
        }
    }
    cout<<ans<<endl;
}   