#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
#define arrprint(v,n) rep(i,0,n-1)cout << v[i] << " ";cout << endl;
#define matprint(v,n,m) rep(i,0,n-1){rep(j,0,m-1){cout << v[i][j] << " ";}cout << endl;}
#define SORT(v) sort(v.begin(), v.end())
#define REV(v) reverse(v.begin(), v.end())
using namespace std;
const int mod=1000000007;
const int INF=1001001001;
typedef long long ll;
typedef pair<int,int> P;
template<typename T>
using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>; //小さいものから取り出す

int main(){
    int n;
    cin >> n;
    vector<P> a(n);
    rep(i,0,n-1){
        int b;
        cin >> b;
        a[i] = make_pair(b,i);
    }
    ll mt[n][n];
    priority_queue<tuple<ll,int,int>> pq;
    rep(i,0,n-1){
        rep(j,0,n-1){
            ll k = a[i].first;
            int idx = a[i].second;
            mt[i][j] = k * abs(idx - j);
            pq.push(make_tuple(mt[i][j],i,j));
        }
    }
    ll ans = 0;
    set<int> si,sj;
    while(!pq.empty()){
        auto now = pq.top();pq.pop();
        auto itri = si.find(get<2>(now));
        auto itrj = sj.find(get<3>(now));
        if(itri != si.end())continue;
        if(itrj != sj.end())continue;
        ans += get<1>(now);
        si.insert(get<2>(now));
        sj.insert(get<3>(now));


    }
    // matprint(mt,n,n);

    // cout << ans << endl;
//  printf("%.10f\n",ans);

    return 0;
}