#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false), cin.tie(0)
#define debug(a) cout << #a ": " << a << endl
using namespace std;
typedef long long ll;
const int N = 2010;
const int M = 4e6 + 4e3 + 7;
const ll INF = 1e18;
const int inf = 0x3f3f3f3f;
int n, a[N];
int s, t;
struct edge{
    int v, cap;
    ll cost;
    int nxt;
}e[M<<1];
int tot, head[N<<1];
int q[N<<2], top, tail, p[N<<1], f[N<<1];
ll d[N];
bool inq[N<<1];
void init(void){
    tot = 0; memset(head, -1, sizeof head);
}
void addedge(int u, int v, int cap, ll cost){
    e[tot] = (edge){v, cap, cost, head[u]}; head[u] = tot++;
    e[tot] = (edge){u, 0, -cost, head[v]}; head[v] = tot++;
}

bool BellmanFord(int s, int t, int& flow, ll& cost){
    for (int i = 0; i <= 2*n+1; ++i){
        inq[i] = false; d[i] = INF;
        f[i] = 0;
    }
    top = tail = 0;
    q[tail++] = s;
    d[s] = 0, inq[s] = true, f[s] = inf;
    while (top != tail){
        int u = q[top++];
        inq[u] = false;
        for (int i = head[u]; i != -1; i = e[i].nxt){
            int v = e[i].v, cap = e[i].cap;
            ll cost = e[i].cost;
            if (cap && d[v] > d[u]+cost){
                d[v] = d[u] + cost;
                p[v] = i;
                f[v] = min(cap, f[u]);
                if (!inq[v]){
                    inq[v] = true;
                    q[tail++] = v;
                }
            }
        }
    }
    if (f[t] == 0) return false;
    cost += 1ll*d[t]*f[t], flow += f[t];
    for (int i = t; i != s; i = e[p[i]^1].v){
        e[p[i]].cap -= f[t];
        e[p[i]^1].cap += f[t];
    }
    return true;
}

ll mcmf(int s, int t){
    ll mincost = 0;
    int flow = 0;
    while (BellmanFord(s, t, flow, mincost));
    return mincost;
}

int main(void){
    IOS;
    init();
    cin >> n;
    s = 0, t = 2*n+1;
    for (int i = 1; i <= n; ++i){
        cin >> a[i];
        addedge(s, i, 1, 0);
        addedge(n+i, t, 1, 0);
    }
    for (int i = 1; i <= n; ++i){
        for (int j = 1; j <= n; ++j){
            ll tmp = 1ll*abs(i-j)*a[i];
            addedge(i, n+j, 1, -tmp);
        }
    }
    cout << -mcmf(s, t) << endl;
    return 0;
}