#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
void d_err() { cerr << endl; }
template <typename H, typename... T>
void d_err(H h, T... t) {
  cerr << h << " ";
  d_err(t...);
}
template <typename T>
void print(T x) {
  cout << x << endl;
}
long long INF = 1e16;
int inf = 1e9;
long long MOD = 1e9 + 7;
const int MAX_V = 1e4;
const int MAX_E = 1e4;
struct Edge {
  int from, to, w;
};
vector<Edge> w(MAX_E);
long long d[MAX_V];
int V, E;
template <typename T>
struct PrimalDual {
  struct Graph {
    int to, rev;
    T cap;
    T cost;
    Graph(int t, int r, const T &cp, const T &cs)
        : to(t), rev(r), cap(cp), cost(cs){};
  };
  vector<T> d;
  vector<vector<Graph>> g;
  vector<int> prevv, preve;
  vector<bool> used;
  int sz;
  PrimalDual(int N) : sz(N) {
    d.resize(N);
    g.resize(N);
    prevv.resize(N);
    preve.resize(N);
    used.resize(N);
  }
  void add_edge(int from, int to, T cap, T cost) {
    g[from].emplace_back(to, (int)g[to].size(), cap, cost);
    g[to].emplace_back(from, (int)g[from].size() - 1, 0, -cost);
  }
  void bellman_ford(int s) {
    d.assign(sz, INF);
    d[s] = 0;
    bool update = true;
    while (update) {
      update = false;
      for (int i = (0); i < (sz); ++i) {
        if (d[i] == INF) continue;
        for (int j = (0); j < (g[i].size()); ++j) {
          auto &e = g[i][j];
          if (e.cap > 0 && d[e.to] > d[i] + e.cost) {
            d[e.to] = d[i] + e.cost;
            prevv[e.to] = i;
            preve[e.to] = j;
            update = true;
          }
        }
      }
    }
  }
  T operator()(int start, int end, T f) {
    T res = 0;
    while (f > 0) {
      bellman_ford(start);
      if (d[end] == INF) return -1;
      T f_cur = f;
      for (int v = end; v != start; v = prevv[v]) {
        f_cur = min(f, g[prevv[v]][preve[v]].cap);
      }
      f -= f_cur;
      res += d[end] * f_cur;
      for (int v = end; v != start; v = prevv[v]) {
        auto &e = g[prevv[v]][preve[v]];
        e.cap -= f_cur;
        g[v][e.rev].cap += f_cur;
      }
    }
    return res;
  }
};
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  int N;
  cin >> N;
  PrimalDual<long long> pd(2 * N + 2);
  for (int i = (0); i < (N); ++i) {
    long long a;
    cin >> a;
    for (int j = (0); j < (N); ++j) {
      pd.add_edge(i, N + j, 1, -a * abs(i - j));
    }
    pd.add_edge(2 * N, i, 1, 0);
    pd.add_edge(N + i, 2 * N + 1, 1, 0);
  }
  print(-pd(2 * N, 2 * N + 1, N));
}
