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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define tr(ds, it) for(auto it=ds.begin(); it!=ds.end(); it++)
#define rtr(ds, it) for(auto it=ds.rbegin(); it!=ds.rend(); it--)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef priority_queue <int> pq;
typedef vector< long long > vi;
typedef pair<long long, long long> ii;
#define o_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define graph vector<vi>

const ll MAX = 2001;
const ll mod = 1000000007;
const ll INF = 100000000000001;
ll po(ll x, ll n ){ 
	ll ans=1;
     while(n>0){
     	if(n&1) ans=(ans*x)%mod;
     	x=(x*x)%mod;
     	n/=2;
     }
     return ans;
}

ll dp[MAX][MAX];
ll n;
vi v(MAX);
vi placed(MAX,-1);

ll solve(ll i,ll j){
		ll ans=abs(i-j)*v[j],total=0;
		placed[j]=i;
		
		rep_a(idx,1,n+1){
			if(placed[idx]==-1){
				total=max(total,solve(i+1,idx));
				placed[idx]=-1;
			}
		}
		placed[j]=-1;
		return total+ans;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r" , stdin);
	//freopen("output.txt", "w" , stdout);
	#endif

	rep(i,MAX)
		rep(j,MAX)
			dp[i][j]=-INF;
	ll ans=0;
	cin>>n;
	
	rep(i,n)	
		cin>>v[i+1];
	
	rep_a(i,1,n+1){
		ans=max(ans,solve(1,i));
	}
	
	cout<<ans<<el;

	return 0;
}
