#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
using i64 = int64_t;
using u64 = uint64_t;

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

constexpr int64_t MOD = 1'000'000'007LL;

#define INT(NAME) int NAME; cin>>NAME;
#define INT64(NAME) int64_t NAME; cin>>NAME;
#define VECTOR(NAME, TYPE, SIZE) std::vector<TYPE> NAME((SIZE));\
    for(int xxxx_i=0; xxxx_i<SIZE; xxxx_i++) cin>>NAME[xxxx_i];
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)    


void solve() {
    INT(N)
    VECTOR(A,int,N)

    priority_queue<tuple<int,int,int>> pq;
    REP(x, N) {
        REP(y, N) {
            pq.emplace(A[x]*abs(x-y), -x, -y);
            int val = A[x]*abs(x-y);
            // cout << "\t" << val;
        }
        // cout << endl;
    }
    unordered_set<int> usedy;
    unordered_set<int> usedx;
    int ans = 0;
    while (usedx.size()<N) {
        auto [val, x, y] = pq.top(); pq.pop();
        if (usedx.count(x)==0 && usedy.count(y)==0) {
            // cout << -x << " " << -y << " " << val << endl;
            usedx.insert(x);
            usedy.insert(y);
            ans += val;
        }
    }
    cout<<ans<<endl;
}

int main() {
    solve();

    return 0;
}