#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=4000+10,M=7e6+10;
ll maxflow,mincost;
ll last[N],pre[N],dis[N],flow[N],pos=1,head[N];
bool vis[N];
struct Edge{ll next,to,flow,dis;}edge[M<<1];
void init(){pos=1;memset(head,0,sizeof head);mincost=maxflow=0;}

void add(ll from,ll to,ll flow,ll dis) {
    edge[++pos].next=head[from];edge[pos].flow=flow;edge[pos].dis=dis;edge[pos].to=to;head[from]=pos;
    edge[++pos].next=head[to];edge[pos].flow=0;edge[pos].dis=-dis;edge[pos].to=from;head[to]=pos;
}
bool spfa(ll s,ll t) {
    memset(dis,0x3f,sizeof dis);
    memset(flow,0x3f,sizeof flow);
    memset(vis,0,sizeof vis);
    queue <ll> q;
    dis[s]=0; pre[t]=-1; q.push(s); vis[s]=1;
    ll tot=0;
    while (!q.empty()) {
        ll now=q.front(); q.pop(); vis[now]=0;
        for (ll i=head[now]; i; i=edge[i].next) {
            ll to=edge[i].to;
            if  (edge[i].flow>0 && dis[to]>dis[now]+edge[i].dis) {
                dis[to]=edge[i].dis+dis[now];
                flow[to]=min(edge[i].flow,flow[now]);
                last[to]=i;
                pre[to]=now;
                if (!vis[to]) {
                    q.push(to); vis[to]=1;
                }
            }
        }
    }
    return pre[t]!=-1;
}
void MCMF(ll s,ll t) {
    while (spfa(s,t)) {
        ll now=t;
        maxflow+=flow[t];
        mincost+=flow[t]*dis[t];
        while (now!=s) {
            edge[last[now]].flow-=flow[t];
            edge[last[now]^1].flow+=flow[t];
            now=pre[now];
        }
    }
}
ll s,t;
int main() {
    ll n;
    cin>>n;
    s=2*n+1;t=s+1;
    for(ll i=1;i<=n;i++) {
        add(s,i,1,0);
        add(i+n,t,1,0);
        ll x;scanf("%lld",&x);
        for(ll j=1;j<=n;j++) add(i,j+n,1,-(abs(i-j)*x));
    }
    MCMF(s,t);
    printf("%lld\n",-mincost);

}

