#include<bits/stdc++.h>
using namespace std;
typedef  long long  ll;
ll inf=1000000000000000000,mod=1000000007;
ll power(ll a,ll b){
    ll res=1;
    while(b){
        if(b&1)
        res=(res*a)%mod;
        a=(a*a)%mod;
        b/=2;
    }
    return res;
}
int main(){
    ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        
        ll n;cin>>n; ll arr[n],vis[n];
        for(ll i=0;i<n;i++)cin>>arr[i],vis[i]=0;ll num,id,ma,sum=0,curr,currl,curr1l;
        currl=0;curr1l=n-1;
        for(ll i=0;i<n;i++){
            if(i%2==0){curr=currl++;}
            else {curr=curr1l--;}
            for(ll j=0;j<n;j++){
                if(curr==j||vis[j])continue;
                num=abs(curr-j)*arr[j];
                if(num>ma){ma=num,id=j;}
            }
        	// cout<<id<<" "<<ma<<endl;
            vis[id]=1;sum+=ma;
            ma=0;
        }
        // cout<<"y";
        cout<<sum;
}
