//Patwari26
#include<bits/stdc++.h>
using namespace std;

#define ll          long long
#define pb          push_back
#define endl        '\n'
#define mii         map<ll,ll>
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define INF         (1ll<<60)
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N=100005;
void solve(){
    ll n;
    cin>>n;
    vi val(n+1);
    vector<pair<ll,pii>> temp;
    rep(i,1,n) {
        cin>>val[i];
        rep(j,1,n)
        temp.pb({val[i]*abs(i-j),{j,i}});
    }
    sort(all(temp));
    ll ans=0;
    ll vis[n+1]={0};
    ll vis2[n+1]={0};
    rrep(i,sz(temp)-1,0){
        if(vis[temp[i].S.F]==0 && vis2[temp[i].S.S]==0){
            ans+=temp[i].F;
            // cout<<temp[i].F<<" "<<temp[i].S<<endl;
            vis[temp[i].S.F]=1;
            vis2[temp[i].S.S]=1;
        }
    }
    cout<<ans<<endl;
}
signed main()
{
    ios
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        solve();
    }
    time
    return 0;
}