#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;
inline void yes() {
  cout << "Yes" << endl;
  exit(0);
}
inline void no() {
  cout << "No" << endl;
  exit(0);
}
template <typename T>
class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T>
class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T>
inline void amax(T &x, T y) {
  x = max(x, y);
}
template <typename T>
inline void amin(T &x, T y) {
  x = min(x, y);
}
template <typename T>
inline T exp(T x, i64 n, T e = 1) {
  T r = e;
  while (n > 0) {
    if (n & 1) r *= x;
    x *= x;
    n >>= 1;
  }
  return r;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (auto &x : v) is >> x;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &v) {
  for (int i = 0; i < int(v.size()); i++) {
    if (i) os << ' ';
    os << v[i];
  }
  return os;
}
void solve();
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(16);
  solve();
  return 0;
}
template <typename C, typename D>
struct Graph {
  struct Edge {
    int to, rev;
    C cap;
    D cost;
    Edge(int to, C cap, D cost, int rev)
        : to(to), cap(cap), cost(cost), rev(rev) {}
  };
  vector<vector<Edge>> es;
  int n;
  Graph(int n) : n(n) { es.assign(n, vector<Edge>()); }
  void add_edge(int v, int u, C ca = 1, D co = 0) {
    es[v].emplace_back(u, ca, co, (int)es[u].size());
    es[u].emplace_back(v, 0, -co, (int)es[v].size() - 1);
  }
  vector<Edge> &operator[](int x) { return es[x]; }
};
template <typename C, typename D>
D min_cost_flow(Graph<C, D> &g, int s, int t, C f) {
  const D INF = numeric_limits<D>::max();
  const int n = g.n;
  D ret = 0;
  while (f > 0) {
    vector<D> dist(n, INF);
    vector<int> prevv(n), preve(n);
    dist[s] = 0;
    while (true) {
      bool update = false;
      for (int v = 0; v < int(n); v++)
        for (int i = 0; i < int(g[v].size()); i++) {
          auto &e = g[v][i];
          if (e.cap == 0) continue;
          if (dist[v] == INF || dist[e.to] <= dist[v] + e.cost) continue;
          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 INF;
    C cap = f;
    for (int v = t; v != s; v = prevv[v]) {
      cap = min(cap, g[prevv[v]][preve[v]].cap);
    }
    f -= cap;
    ret += cap * dist[t];
    for (int v = t; v != s; v = prevv[v]) {
      auto &e = g[prevv[v]][preve[v]];
      e.cap -= cap;
      g[v][e.rev].cap += cap;
    }
  }
  return ret;
}
void solve() {
  int n;
  cin >> n;
  vi32 a(n);
  cin >> a;
  Graph<i64, i64> g(n * 2 + 2);
  for (int i = 1; i <= int(n); i++) {
    g.add_edge(0, i, 1, 0);
    g.add_edge(n + i, n * 2 + 1, 1, 0);
    for (int j = 1; j <= int(n); j++) {
      g.add_edge(i, n + j, 1, (i64)-a[i - 1] * abs(i - j));
    }
  }
  auto ans = min_cost_flow<i64, i64>(g, 0, n * 2 + 1, n);
  cout << -ans << endl;
}
