#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()


int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    REP(i, n){
        cin >> a.at(i);
    }

    vector<array<ll, 3>> gain;
    REP(i, n){
        REP(j, m){
            gain.push_back({a.at(i) * abs(i - j), i, j});
        }
    }
    sort(gain.rbegin(), gain.rend());

    ll ans = 0;
    vector<bool> flag_child(n, false), flag_pos(n, false);
    for(const auto p : gain){
        if(!flag_child.at(p.at(1)) && !flag_pos.at(p.at(2))){
            ans += p.at(0);
            flag_child.at(p.at(1)) = true;
            flag_pos.at(p.at(2)) = true;
        }
    }
    cout << ans << endl;
    return 0;
}
