#include <bits/stdc++.h>
using namespace std;
struct edge {
  long long int to, rev;
  long long int cap, cost;
  edge(long long int to, long long int cap, long long int rev)
      : to(to), cap(cap), rev(rev) {}
  edge(long long int to, long long int cap, long long int cost,
       long long int rev)
      : to(to), cap(cap), cost(cost), rev(rev) {}
};
struct Flow {
  vector<vector<edge> > g;
  long long int MAXC = 1 << 30;
  long long int n;
  vector<bool> used;
  vector<long long int> prevv, preve, dist;
  Flow() {}
  Flow(long long int _n)
      : g(_n), n(_n), used(_n, false), prevv(_n), preve(_n), dist(_n, MAXC) {}
  void add_edge(long long int from, long long int to, long long int cap) {
    g[from].push_back(edge(to, cap, g[to].size()));
    g[to].push_back(edge(from, 0, g[from].size() - 1));
  }
  void add_edge(long long int from, long long int to, long long int cap,
                long long int 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 int dfs(long long int v, long long int t, long long int f) {
    if (v == t) return f;
    used[v] = true;
    for (int i = 0; i < g[v].size(); i++) {
      edge &e = g[v][i];
      if (!used[e.to] && e.cap > 0) {
        long long int d = dfs(e.to, t, min(f, e.cap));
        if (d > 0) {
          e.cap -= d;
          g[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }
  long long int max_flow(long long int s, long long int t) {
    long long int flow = 0;
    while (1) {
      fill(used.begin(), used.end(), false);
      long long int f = dfs(s, t, 1e9);
      if (f == 0) return flow;
      flow += f;
    }
  }
  long long int mincost_flow(long long int s, long long int t,
                             long long int f) {
    long long int res = 0;
    long long int M = MAXC;
    while (f > 0) {
      fill(dist.begin(), dist.end(), M);
      dist[s] = 0;
      bool update = true;
      while (update) {
        update = false;
        for (long long int i = 0; i < n; i++) {
          if (dist[i] == M) continue;
          for (long long int j = 0; j < g[i].size(); j++) {
            edge &e = g[i][j];
            if (e.cap > 0 && dist[e.to] > dist[i] + e.cost) {
              dist[e.to] = dist[i] + e.cost;
              prevv[e.to] = i;
              preve[e.to] = j;
              update = true;
            }
          }
        }
      }
      if (dist[t] == M) return -1;
      long long int d = f;
      for (long long int i = t; i != s; i = prevv[i])
        d = min(d, g[prevv[i]][preve[i]].cap);
      f -= d;
      res += d * dist[t];
      for (long long int i = t; i != s; i = prevv[i]) {
        edge &e = g[prevv[i]][preve[i]];
        e.cap -= d;
        g[i][e.rev].cap += d;
      }
    }
    return res;
  }
  long long int fast_mincost_flow(long long int s, long long int t,
                                  long long int f) {
    long long int res = 0, M = MAXC;
    vector<long long int> pot(n);
    while (f > 0) {
      priority_queue<pair<long long int, long long int>,
                     vector<pair<long long int, long long int> >,
                     greater<pair<long long int, long long int> > >
          q;
      fill(dist.begin(), dist.end(), M);
      dist[s] = 0;
      q.push(pair<long long int, long long int>(0, s));
      while (!q.empty()) {
        pair<long long int, long long int> now = q.top();
        q.pop();
        long long int v = now.second;
        long long int cost = now.first;
        if (dist[v] < cost) continue;
        for (long long int i = 0; i < g[v].size(); i++) {
          edge &e = g[v][i];
          if (e.cap > 0 && dist[e.to] > dist[v] + e.cost + pot[v] - pot[e.to]) {
            dist[e.to] = dist[v] + e.cost + pot[v] - pot[e.to];
            prevv[e.to] = v;
            preve[e.to] = i;
            q.push(pair<long long int, long long int>(dist[e.to], e.to));
          }
        }
      }
      if (dist[t] == M) return -1;
      for (long long int i = 0; i < n; i++) pot[i] += dist[i];
      long long int d = f;
      for (long long int i = t; i != s; i = prevv[i])
        d = min(d, g[prevv[i]][preve[i]].cap);
      f -= d;
      res += d * pot[t];
      for (long long int i = t; i != s; i = prevv[i]) {
        edge &e = g[prevv[i]][preve[i]];
        e.cap -= d;
        g[i][e.rev].cap += d;
      }
    }
    return res;
  }
};
int main() {
  long long int n;
  cin >> n;
  Flow f(2 * n + 2);
  long long int S = 2 * n;
  long long int T = S + 1;
  vector<long long int> a(n);
  for (long long int i = 0; i < n; i++) cin >> a[i];
  for (long long int i = 0; i < n; i++) f.add_edge(S, i, 1, 0);
  for (long long int i = 0; i < n; i++) f.add_edge(i + n, T, 1, 0);
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < n; j++) {
      f.add_edge(i, j + n, 1, -abs(i - j) * a[i]);
    }
  }
  cout << -f.fast_mincost_flow(S, T, n) << endl;
  return 0;
}
