#include <bits/stdc++.h>
using namespace std;
template <class A>
void pr(A a) {
  cout << a;
  cout << '\n';
}
template <class A, class B>
void pr(A a, B b) {
  cout << a << ' ';
  pr(b);
}
template <class A, class B, class C>
void pr(A a, B b, C c) {
  cout << a << ' ';
  pr(b, c);
}
template <class A, class B, class C, class D>
void pr(A a, B b, C c, D d) {
  cout << a << ' ';
  pr(b, c, d);
}
template <class A>
void PR(A a, long long n) {
  for (long long i = (long long)(0); i < (long long)(n); i++) {
    if (i) cout << ' ';
    cout << a[i];
  }
  cout << '\n';
}
long long check(long long n, long long m, long long x, long long y) {
  return x >= 0 && x < n && y >= 0 && y < m;
}
const long long MAX = 1e9 + 7, MAXL = 1LL << 61, dx[4] = {-1, 0, 1, 0},
                dy[4] = {0, 1, 0, -1};
const long long MAX_V = 4002;
struct edge {
  long long to, cap, cost, rev;
  edge(long long to, long long cap, long long cost, long long rev)
      : to(to), cap(cap), cost(cost), rev(rev) {}
};
vector<edge> G[MAX_V];
long long dist[MAX_V];
long long prevv[MAX_V], preve[MAX_V];
void add_edge(long long from, long long to, long long cap, long long cost) {
  G[from].push_back(edge(to, cap, cost, G[to].size()));
  G[to].push_back(edge(from, 0, -cost, G[from].size() - 1));
}
long long min_cost_flow(long long s, long long t, long long f) {
  long long res = 0;
  while (f > 0) {
    fill(dist, dist + MAX_V, MAXL);
    dist[s] = 0;
    bool update = true;
    while (update) {
      update = false;
      for (long long v = 0; v < MAX_V; v++) {
        if (dist[v] == MAXL) continue;
        for (long long i = 0; i < (int)G[v].size(); i++) {
          edge &e = G[v][i];
          if (e.cap > 0 && dist[e.to] > dist[v] + e.cost) {
            dist[e.to] = dist[v] + e.cost;
            prevv[e.to] = v;
            preve[e.to] = i;
            update = true;
          }
        }
      }
    }
    if (dist[t] == MAXL) return -1;
    long long d = f;
    for (long long v = t; v != s; v = prevv[v]) {
      d = min(d, G[prevv[v]][preve[v]].cap);
    }
    f -= d;
    res += d * dist[t];
    for (long long 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;
}
void Main() {
  long long n;
  cin >> n;
  long long a[n];
  for (long long i = (long long)(0); i < (long long)(n); i++) cin >> a[i];
  for (long long i = (long long)(0); i < (long long)(n); i++) {
    for (long long j = (long long)(0); j < (long long)(n); j++) {
      add_edge(i, j + n, 1, -abs(i - j) * a[i]);
    }
    add_edge(4000, i, 1, 0);
    add_edge(n + i, 4001, 1, 0);
  }
  pr(-min_cost_flow(4000, 4001, n));
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  Main();
  return 0;
}
