#include <bits/stdc++.h>
using namespace std;
template <class F, class C>
class MinCostFlow {
  struct Edge {
    int rev, from, to;
    F cap, icap;
    C cost;
    Edge(int rev, int from, int to, F cap, C cost)
        : rev(rev), from(from), to(to), cap(cap), icap(cap), cost(cost) {}
  };
  int N;
  vector<vector<Edge>> G;
  const C INF;

 public:
  MinCostFlow(int N) : N(N), G(N), INF(numeric_limits<C>::max()) {}
  void add_edge(int from, int to, F cap, C cost) {
    G[from].emplace_back((int)(G[to].size()), from, to, cap, cost);
    G[to].emplace_back((int)(G[from].size()) - 1, to, from, 0, -cost);
  }
  C solve(int s, int t, F init_f) {
    vector<C> dist(N);
    vector<int> prevv(N);
    vector<int> preve(N);
    C ret = 0;
    F f = init_f;
    while (f > 0) {
      fill(dist.begin(), dist.end(), INF);
      dist[s] = 0;
      while (true) {
        bool update = false;
        for (int v = 0; v < G.size(); v++) {
          if (dist[v] == INF) continue;
          for (int i = 0; i < 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 (!update) break;
      }
      if (dist[t] == INF) return 0;
      F d = f;
      for (int v = t; v != s; v = prevv[v]) {
        d = min(d, G[prevv[v]][preve[v]].cap);
      }
      f -= d;
      ret += dist[t] * d;
      for (int v = t; v != s; v = prevv[v]) {
        Edge& e = G[prevv[v]][preve[v]];
        Edge& re = (e.from != e.to) ? G[e.to][e.rev] : G[e.to][e.rev + 1];
        e.cap -= d;
        re.cap += d;
      }
    }
    return ret;
  }
  vector<int> get_selected_edges(int i) {
    vector<int> ret;
    for (int j = 0; j < G[i].size(); j++) {
      Edge& e = G[i][j];
      if (e.cap == 0 && e.icap == 1) ret.push_back(e.to);
    }
    return ret;
  }
};
class MaximumWeightedMatching {
  int N, M;
  int s, t;
  vector<int> x;
  MinCostFlow<long long, long long> mcf;

 public:
  MaximumWeightedMatching(int N, int M)
      : N(N), M(M), x(N), mcf(N + M + 2), s(N + M), t(N + M + 1) {}
  void set_x(int i, int num) { x[i] = num; }
  void add_edge(int i, int j, long long gain) { mcf.add_edge(i, j, 1, -gain); }
  pair<long long, vector<pair<int, int>>> solve() {
    int sum = 0;
    for (int i = 0; i < N; i++) {
      mcf.add_edge(s, i, x[i], 0);
      sum += x[i];
    }
    for (int i = 0; i < M; i++) {
      mcf.add_edge(N + i, t, 1, 0);
    }
    long long score = -mcf.solve(s, t, sum);
    vector<pair<int, int>> selected_edges;
    for (int i = 0; i < N; i++) {
      vector<int> se = mcf.get_selected_edges(i);
      for (int j = 0; j < se.size(); j++) {
        selected_edges.emplace_back(i, se[j]);
      }
    }
    return make_pair(score, selected_edges);
  }
};
int main() {
  int N;
  cin >> N;
  vector<long long> v;
  for (int i = (0); i < (int)(N); i++) {
    long long a;
    cin >> a;
    v.push_back(a);
  }
  MaximumWeightedMatching mwm(N, N);
  for (int i = (0); i < (int)(N); i++) {
    mwm.set_x(i, 1);
  }
  for (int i = (0); i < (int)(N); i++) {
    for (int j = (0); j < (int)(N); j++) {
      long long s = v[i] * abs(i - j);
      mwm.add_edge(i, j + N, s);
    }
  }
  pair<long long, vector<pair<int, int>>> ret = mwm.solve();
  cout << ret.first << endl;
  return 0;
}
