#include <bits/stdc++.h>
using namespace std;
template <typename T>
class MinCostFlow {
 public:
  MinCostFlow(int n)
      : n(n),
        capacity(n, vector<T>(n)),
        cost(n, vector<T>(n)),
        edge(n),
        prev(n) {}
  void add_edge(int src, int dst, T cap, T cos) {
    capacity[src][dst] = cap;
    capacity[dst][src] = 0;
    cost[src][dst] = cos;
    cost[dst][src] = -cos;
    edge[src].push_back(dst);
    edge[dst].push_back(src);
  }
  T min_cost_flow(int s, int t, T f) {
    T res = 0;
    h.assign(n, 0);
    while (f > 0) {
      if (!dijkstra(s, t)) return -1;
      for (int i = 0; i < n; ++i) h[i] += min_cost[i];
      T d = f;
      for (int v = t; v != s; v = prev[v]) d = min(d, capacity[prev[v]][v]);
      f -= d;
      res += d * h[t];
      for (int v = t; v != s; v = prev[v]) {
        capacity[prev[v]][v] -= d;
        capacity[v][prev[v]] += d;
      }
    }
    return res;
  }

 private:
  int n;
  T inf = numeric_limits<T>::max() / 3;
  vector<vector<T>> capacity, cost;
  vector<vector<int>> edge;
  vector<T> min_cost, h;
  vector<int> prev;
  bool dijkstra(int s, int t) {
    min_cost.assign(n, inf);
    min_cost[s] = 0;
    priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>>
        pq;
    pq.emplace(0, s);
    while (!pq.empty()) {
      int c = pq.top().first;
      int v = pq.top().second;
      pq.pop();
      if (min_cost[v] < c) continue;
      for (int nv : edge[v]) {
        if (capacity[v][nv] > 0 &&
            min_cost[nv] > min_cost[v] + cost[v][nv] + h[v] - h[nv]) {
          min_cost[nv] = min_cost[v] + cost[v][nv] + h[v] - h[nv];
          prev[nv] = v;
          pq.emplace(min_cost[nv], nv);
        }
      }
    }
    return min_cost[t] != inf;
  }
};
long long n, a[2020];
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  MinCostFlow<long long> mcf(4040);
  int s = n * 2;
  int t = n * 2 + 1;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (i == j) continue;
      long long cost = a[i] * abs(i - j);
      mcf.add_edge(i, j + n, 1, -cost);
    }
  }
  for (int i = 0; i < n; ++i) {
    mcf.add_edge(s, i, 1, 0);
    mcf.add_edge(i + n, t, 1, 0);
  }
  cout << -mcf.min_cost_flow(s, t, n) << endl;
  return 0;
}
