#include <bits/stdc++.h>
using namespace std;
const int MAX_V = 4444;
struct edge {
  int to, cap;
  long long cost;
  int rev;
};
int V;
vector<edge> G[MAX_V];
long long h[MAX_V];
long long dist[MAX_V];
int prevv[MAX_V], preve[MAX_V];
const long long inf = 1ll << 50;
void add_edge(int f, int t, int cap, long long cost) {
  G[f].push_back((edge){t, cap, cost, (int)G[t].size()});
  G[t].push_back((edge){f, 0, -cost, (int)G[f].size() - 1});
}
long long min_cost_flow(int s, int t, int f) {
  long long res = 0;
  fill(h, h + V, 0);
  while (f > 0) {
    priority_queue<pair<long long, int>, vector<pair<long long, int> >,
                   greater<pair<long long, int> > >
        q;
    fill(dist, dist + V, inf);
    dist[s] = 0;
    q.push(pair<long long, int>(0, s));
    while (!q.empty()) {
      pair<long long, int> p = q.top();
      q.pop();
      int v = p.second;
      if (dist[v] < p.first) continue;
      for (int i = 0; i < int(G[v].size()); i++) {
        edge& e = G[v][i];
        if (e.cap > 0 && dist[e.to] > dist[v] + e.cost + h[v] - h[e.to]) {
          dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];
          prevv[e.to] = v;
          preve[e.to] = i;
          q.push(pair<long long, int>(dist[e.to], e.to));
        }
      }
    }
    if (dist[t] == inf) {
      return -1;
    }
    for (int v = 0; v < V; v++) h[v] += dist[v];
    int d = f;
    for (int v = t; v != s; v = prevv[v]) {
      d = min(d, G[prevv[v]][preve[v]].cap);
    }
    f -= d;
    res += d * h[t];
    for (int v = t; v != s; v = prevv[v]) {
      edge& e = G[prevv[v]][preve[v]];
      e.cap -= d;
      G[v][e.rev].cap += d;
    }
  }
  return res;
}
int n;
int a[4444];
int main(void) {
  scanf("%d", &n);
  V = n * 2 + 2;
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
  }
  for (int i = 0; i < n; i++) {
    add_edge(0, i + 1, 1, 0);
    add_edge(n + i + 1, n * 2 + 1, 1, 0);
    for (int j = 0; j < n; j++) {
      add_edge(i + 1, n + j + 1, 1, -a[i] * abs(i - j));
    }
  }
  printf("%lld\n", -min_cost_flow(0, n * 2 + 1, n));
  return 0;
}
