#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll n;
    cin>>n;
    ll a[n+1],vis[n+1]={0};
    for(int i=1;i<=n;i++)
        cin>>a[i];
    ll l=1,r=n,ans=0;
    while(l<=r){
        ll mx=0,mxpos1=0,mxpos2;
        for(ll i=1;i<=n;i++){
            if(vis[i]) continue;
            if(a[i]*abs(i-l)>mx)
                mx=a[i]*abs(i-l),mxpos1=i,mxpos2=l;
            if(a[i]*abs(r-i)>mx)
                mx=a[i]*abs(r-i),mxpos1=i,mxpos2=r;
        }
        ans+=mx;
        //cout<<ans<<endl;
        vis[mxpos1]=1;
        if(mxpos2==l) l++;
        else r--;
    }
    cout<<ans;
    return 0;
}

