#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
#define MOD 1000000007 
#define INF LONG_LONG_MAX
#define MINF LONG_LONG_MIN


ll po(ll x,ll n){
    if(n==0) return 1;
    else if(n%2 == 0) return po((x*x)%MOD,n/2);
    else return (x*po((x*x)%MOD,(n-1)/2))%MOD;
}



void init(){
    
}

void solve( ll  tst ){
    ll n;
    cin>>n;
    ll a[n];
    for( ll i=0;i<n;i++ ) cin>>a[i];
    bool v[n] = {false};
    ll le = 0;
    ll ri = n-1;
    ll ans = 0;
    for( ll j=0;j<n;j++ ){
        ll tmx = 0;
        ll in = -1;
        for( ll i=0;i<n;i++ ){
            if( v[i] ) continue;
            ll tm = a[i]*max(abs(i-le), abs(i-ri));
            if( tmx < tm ){
                tmx = tm;
                in = i;
            }
        }
        if( abs(in - le) > abs( in - ri ) ){
            ans += tmx;
            v[in] = true;
            le++;
        }
        else{
            v[in] = true;
            ri--;
            ans += tmx;
        }
    }
    cout<<ans<<endl;
}

int main(){
    FAST;
    init();
    //cout<<"init"<<endl;
    ll t = 1;
    //cin>>t;
    for (ll i=1;i<=t;i++ ) solve(i);
    return 0;
} 