#include <bits/stdc++.h>
using namespace std;
template <class T>
void print(const T& x) {
  cout << x << endl;
}
template <class T, class... A>
void print(const T& first, const A&... rest) {
  cout << first << " ";
  print(rest...);
}
struct PreMain {
  PreMain() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} premain;
struct MinCostFlow {
  struct edge {
    int to, cap, rev;
    long long cost;
  };
  vector<vector<edge>> G;
  int v_num;
  MinCostFlow(int n) : v_num(n), G(n) {}
  void add_edge(int from, int to, int cap, long long cost) {
    G[from].emplace_back((edge){to, cap, (int)G[to].size(), cost});
    G[to].emplace_back((edge){from, 0, (int)G[from].size() - 1, -cost});
  }
  long long min_cost_flow(int s, int t, int f) {
    long long res = 0;
    while (f > 0) {
      vector<long long> dist(v_num, ((long long)1e15));
      vector<int> prev_v(v_num, 0), prev_e(v_num, 0);
      dist[s] = 0;
      bool update = true;
      while (update) {
        update = false;
        for (int(v) = 0; (v) < (int)(v_num); ++(v)) {
          if (dist[v] == ((long long)1e15)) continue;
          for (int(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;
              prev_v[e.to] = v;
              prev_e[e.to] = i;
              update = true;
            }
          }
        }
      }
      if (dist[t] == ((long long)1e15)) {
        return -1;
      }
      int d = f;
      for (int v = t; v != s; v = prev_v[v]) {
        d = min(d, G[prev_v[v]][prev_e[v]].cap);
      }
      f -= d;
      res += d * dist[t];
      for (int v = t; v != s; v = prev_v[v]) {
        edge& e = G[prev_v[v]][prev_e[v]];
        e.cap -= d;
        G[v][e.rev].cap += d;
      }
    }
    return res;
  }
};
int main() {
  int N;
  cin >> N;
  vector<long long> A(N);
  for (int(i) = 0; (i) < (int)(N); ++(i)) cin >> A[i];
  int s = 2 * N, t = s + 1;
  auto g = MinCostFlow(2 * N + 2);
  int ans = 0;
  for (int(i) = 0; (i) < (int)(N); ++(i)) g.add_edge(s, i, 1, 0);
  for (int(i) = 0; (i) < (int)(N); ++(i)) g.add_edge(N + i, t, 1, 0);
  for (int(i) = 0; (i) < (int)(N); ++(i))
    for (int(j) = 0; (j) < (int)(N); ++(j)) {
      g.add_edge(i, N + j, 1, -A[i] * abs(i - j));
    }
  ans += -g.min_cost_flow(s, t, N);
  print(ans);
  return 0;
}
