	//PseudoName

	#pragma GCC optimize("O3")
	#include <bits/stdc++.h>
	#include <ext/pb_ds/assoc_container.hpp>
	#include <ext/pb_ds/tree_policy.hpp>
	using namespace std;
	using namespace __gnu_pbds;
	template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


	#define FOR(i,n) for(i=0;i<n;i++)
	#define FOR1(i,n) for(i=1;i<=n;i++)
	#define FOR2(I, A, B) for (int I = (A); I <= (B); ++I)
	#define pb push_back
	#define unique_sort(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
	#define print(v) for(auto it:v)cout<<it<<" ";cout<<endl
	#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
	#define endl "\n"
	#define min3(a,b,c) min(a,min(b,c))
	#define forr(n) for(int i=0;i<n;i++)
	#define frr(n) for(int i=1;i<=n;i++)
	#define rep(i,a,b) for(int i=a;i<=b;i++)



	typedef long long ll;
	typedef long li;
	typedef vector<int> vi;
	typedef vector<ll> vli;
	typedef vector<vi> vvi;
	typedef vector<vli> vvli;
	typedef pair<int,int> pi;
	typedef pair<ll,ll> pli;
	typedef vector<pi> vpi;
	typedef vector<pli> vpli;



	//const ll MOD=1e9+7;

	/*
	ll fast_exp(ll base, ll exp) {
	    ll res=1;
	    while(exp>0) {
	       if(exp%2==1) res=(res*base)%MOD;
	       base=(base*base)%MOD;
	       exp/=2;
	    }
	    return res%MOD;
	}
	ll imod(ll a)
	{
		return fast_exp(a, MOD-2);
	}
	*/
	const int MAX=2005;
	ll a[MAX];
	bool done[MAX];
	int dn;

	int main() {
	    fast();
	    int n;
	    cin>>n;

	    frr(n)cin>>a[i];

        ll r=n;
        ll l=1,cost;
        ll ans=0;

        while(dn<n)
        {
            ll mx=0,id=1;
            frr(n)
            {
                if(!done[i])
                {
                    cost=max(a[i]*(i-l),a[i]*(r-i));
                    if(cost>mx)
                    {
                        mx=cost;
                        id=i;
                    }
                    else if(cost==mx)
                    {
                        if(a[i]<a[id])
                        {
                            id=i;
                        }
                    }
                }
            }
            done[id]=1;
            dn++;
            ans+=mx;

            if(mx==a[id]*(id-l))l++;
            else
                r--;
        }

        cout<<ans<<endl;






	}
