#include <bits/stdc++.h>
using namespace std;
template <class T>
void chmin(T &a, const T &b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T &a, const T &b) {
  if (a < b) a = b;
}
template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(long long len, T elem) {
  return vector<T>(len, elem);
}
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.first << ',' << p.second;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.first >> p.second;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (long long i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (long long i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}
const long long MAX_V = 4010;
long long V, E;
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 h[MAX_V], dist[MAX_V], 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;
  fill(h, h + V, 0);
  while (f > 0) {
    priority_queue<pair<long long, long long>,
                   vector<pair<long long, long long>>,
                   greater<pair<long long, long long>>>
        q;
    fill(dist, dist + V, 2000000000000000000ll);
    dist[s] = 0;
    q.push(make_pair(0, s));
    while (!q.empty()) {
      pair<long long, long long> p = q.top();
      q.pop();
      long long v = p.second;
      if (dist[v] < p.first) continue;
      for (long long i = 0; i < 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(make_pair(dist[e.to], e.to));
        }
      }
    }
    if (dist[t] == 2000000000000000000ll) {
      return -1;
    }
    for (long long v = 0; v < V; v++) h[v] += dist[v];
    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 * h[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 solve() {
  long long N;
  cin >> N;
  V = 2 * N + 2;
  long long S = 2 * N;
  long long T = 2 * N + 1;
  vector<long long> A(N);
  cin >> A;
  for (long long i = 0; i < N; i++) {
    add_edge(S, i, 1, 0);
    for (long long j = 0; j < N; j++) {
      add_edge(i, j + N, 1, -abs(i - j) * A[i]);
    }
    add_edge(i + N, T, 1, 0);
  }
  cout << -min_cost_flow(S, T, N) << "\n";
  return;
}
signed main() {
  fastio();
  solve();
  return 0;
}
