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

//g++ -g -o yourexe yourfile.cpp
//./yourexe < yourinput.in > youroutput.out

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define M 1000000007

#define ll long long
#define ld long double
#define vi vector<ll>
#define pi pair<ll, ll>
#define vii vector<pi>
#define vvi vector<vi>
#define pb push_back
#define endl "\n"

#define REP(i, s, e) for (ll i = s; i < e; i++)
#define RREP(i, s, e) for (ll i = s; i > e; i--)

#define all(v) v.begin(), v.end()
#define part(v, s, e) v.begin() + s, v.begin() + e
#define print(v) for (auto i: v) cout << i << " ";

struct ind {
    ll v, i, j;

    bool operator<(ind& a) {
        return this->v >= a.v;
    }
};

int main() {
    fast;
    ll n;
    cin >> n;
    vi arr(n);
    REP(i, 0, n)
        cin >> arr[i];
    vi vis1(n, 0), vis2(n, 0);
    vector<ind> tmp;
    REP(i, 0, n)
        REP(j, 0, n)
            tmp.pb({arr[i]*abs(j-i), i, j});
    sort(all(tmp));
    ll sum = 0;
    REP(i, 0, tmp.size()) {
        if (!vis1[tmp[i].i] && !vis2[tmp[i].j]) {
            sum += tmp[i].v;
            vis1[tmp[i].i] = 1;
            vis2[tmp[i].j] = 1;
        }
    }
    cout << sum << endl;
}
