/* Author: Rennan Rocha
 * Time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
**/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define F first
#define S second
#define PB push_back
#define MP make_pair

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll, ll>
#define vpi vector<pi>
#define vpll vector<pll>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//*find_by_order(); order_of_key();

ll arr[2000];
ll table[2000][2000];

int n;

ll solve(int i) {
    for(int j = 0; j < n; j++) {

    }
}

bool cmp(pi a, pi b) {
    return table[a.F][a.S] < table[b.F][b.S];
}

int main() {
    ios_base::sync_with_stdio(false);

    cin >> n;

    for(int i = 0; i < n; i++) cin >> arr[i];

    vpi v;

    //cout << "\n";
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            table[i][j] = abs(i-j) * arr[j];
          //  cout << table[i][j] << " ";
            v.PB(MP(i, j));
        }
        //cout << "\n";
    }
    sort(v.rbegin(), v.rend(), cmp);
    bool pos[n];
    bool child[n];
    memset(pos, false, sizeof pos);
    memset(child, false, sizeof child);
    ll ans = 0;
    for(int i = 0; i < v.size(); i++) {
        pi p = v[i];
        if(!pos[p.F] && !child[p.S]) {
            ans += table[p.F][p.S];
            pos[p.F] = true;
            child[p.S] = true;
        }
    }
    cout << ans << "\n";
}
