
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 1000000007
#define all(v)  v.begin(),v.end()
#define pb push_back
#define size(v)  (int) v.size()
#define fast ios_base:: sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
ll power_mod(ll a,ll x){if(x==0) return 1;ll y=power_mod(a,x/2);ll ans=(y*y)%mod; if(x%2) ans=(ans*a)%mod;return ans;}
ll inv(ll a){return power_mod(a,mod-2);}    
ll power(ll a, ll x){ if(x==0) return 1; ll y= power(a,x/2); ll ans=(y*y); if(x%2) ans*=a; return ans;}

struct compare { 
    bool operator()(pair<ll,pair<ll,ll>> const& p1, pair<ll,pair<ll,ll>> const& p2) 
    { 
        if(p1.first != p2.first){
        	return p1.first < p2.first;
        }
        else{
        	return abs(p1.second.first-p1.second.second) < (p2.second.first-p2.second.second);
        }
    } 
}; 

int main(){
		ll n;
		cin>>n;
        ll a[n+1];
       
        for(ll i = 1;i<=n;i++) cin>>a[i];
        priority_queue < pair<ll,pair<ll,ll>> ,vector<pair<ll,pair<ll,ll>>>,compare> pq;

    	for( ll i = 1; i<= n; i++){
    		for(ll j = 1 ;j <= n; j++){
    			pq.push({a[i]*abs(i-j),{i,j}});
    		}
    	}
    	ll a_new[n+1] = {};
    	ll ct = 0;
    	ll sum = 0;
    	int done[n+1]={};    	
    	while( ct != n ){
    		auto  top = pq.top();
    		pq.pop();
    		ll num = top.first;
    		ll old = top.second.first;
    		ll nw = top.second.second;

    		if( a_new[nw] == 0 and (done[old] == 0)){
    	
	    		a_new[nw] = a[old];
	    		sum += num;
	    		done[old] = 1;
	    		ct++;
	    		// for(ll i = 1; i <=n;i++) cout<<a_new[i]<< " ";
	    		// cout<<endl;
   			 }	
    	}


    	// for(ll i = 1; i <=n;i++) cout<<a_new[i]<< " ";
    	// cout<<endl;
    	cout<<sum<<endl;


       
}

//1 4 3 5 6 2
