#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
const long long somod = 1e9 + 7;
const long long maxn = 1e4 + 7;
long long n, m, a[maxn];
vector<long long> vt[maxn];
struct Edge {
  long long u, v, cap, cost;
};
struct MCMF {
  long long trace[maxn], inq[maxn], s, t, dist[maxn], ans;
  vector<Edge> e;
  vector<long long> vt[maxn];
  void AddEdge(long long u, long long v, long long cap, long long cost) {
    vt[u].push_back(e.size());
    e.push_back({u, v, cap, cost});
    vt[v].push_back(e.size());
    e.push_back({v, u, 0, -cost});
  }
  bool SPFA() {
    for (long long i = s; i <= t; i++) trace[i] = -1, dist[i] = 1e9, inq[i] = 0;
    queue<long long> q;
    q.push(s);
    dist[s] = 0;
    while (!q.empty()) {
      long long gau = q.front();
      q.pop();
      inq[gau] = false;
      for (auto i : vt[gau]) {
        if (e[i].cap > 0 && dist[e[i].v] > dist[gau] + e[i].cost) {
          dist[e[i].v] = dist[gau] + e[i].cost;
          trace[e[i].v] = i;
          if (!inq[e[i].v]) {
            inq[e[i].v] = 1;
            q.push(e[i].v);
          }
        }
      }
    }
    return (trace[t] != -1);
  }
  void Update() {
    long long Min = 1e9, cc = t;
    while (cc != s) {
      long long x = trace[cc];
      Min = min(Min, e[x].cap);
      cc = e[x].u;
    }
    cc = t;
    while (cc != s) {
      long long x = trace[cc];
      e[x].cap -= Min;
      e[x ^ 1].cap += Min;
      ans += Min * e[x].cost;
      cc = e[x].u;
    }
  }
  long long FindMCMF() {
    while (SPFA()) {
      Update();
    }
    return ans;
  }
} flow;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  if (fopen("test.inp", "r")) freopen("test.inp", "r", stdin);
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
  }
  flow.s = 0;
  flow.t = n + n + 1;
  for (long long i = 1; i <= n; i++) {
    flow.AddEdge(0, i, 1, 0);
    flow.AddEdge(n + i, n + n + 1, 1, 0);
    for (long long j = 1; j <= n; j++) {
      flow.AddEdge(i, n + j, 1, -a[i] * abs(i - j));
    }
  }
  cout << -flow.FindMCMF();
}
