/** 
If comrades that you trust gather around you, hope can take physical form and become visible. That’s what I believe.
*/
#include <bits/stdc++.h>
using namespace std;
/**
(▀̿Ĺ̯▀̿ ̿) (ง ͠° ͟ل͜ ͡°)ง
*/
using ll = long long;
using pll = pair<ll, pair<int, int>>;
const int N = 2e3 + 7;
ll a[N];
int vf[N], vt[N];
int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
    int tt = clock();
    int n; cin >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    ll ans = 0LL;
    vector<pll> b;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            b.emplace_back(a[i] * abs(i - j), make_pair(i, j));
        }
    }
    sort(b.begin(), b.end(), [](const auto& lhs, const auto& rhs) {
        return lhs.first > rhs.first;
    });
    for (auto &v : b) {
        if (vf[v.second.first] || vt[v.second.second]) continue;
        ans += v.first;
        vf[v.second.first]++;
        vt[v.second.second]++;
    }
    cout << ans << '\n';


    cerr << "TIME = " << (double) 1.0 * (clock() - tt) / CLOCKS_PER_SEC << " seconds" << endl;
	return 0;
}
