#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1 << 17;
using namespace std;
int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
struct aaa {
  aaa() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
} aaaaaaa;
struct edge {
  int to, cap, rev;
};
typedef int FLOW;
typedef int COST;
const int MAX_V = 4 * 100000 + 5;
struct Edge {
  int rev, from, to;
  FLOW cap, icap;
  COST cost;
  Edge(int r, int f, int t, FLOW ca, COST co)
      : rev(r), from(f), to(t), cap(ca), icap(ca), cost(co) {}
};
struct Graph {
  int V;
  vector<Edge> list[MAX_V];
  Graph(int n = 0) : V(n) {
    for (int i = 0; i < MAX_V; ++i) list[i].clear();
  }
  void init(int n = 0) {
    V = n;
    for (int i = 0; i < MAX_V; ++i) list[i].clear();
  }
  void resize(int n = 0) { V = n; }
  void reset() {
    for (int i = 0; i < V; ++i)
      for (int j = 0; j < list[i].size(); ++j) list[i][j].cap = list[i][j].icap;
  }
  inline vector<Edge>& operator[](int i) { return list[i]; }
  Edge& redge(Edge& e) {
    if (e.from != e.to)
      return list[e.to][e.rev];
    else
      return list[e.to][e.rev + 1];
  }
  void addedge(int from, int to, FLOW cap, COST cost) {
    list[from].push_back(Edge((int)list[to].size(), from, to, cap, cost));
    list[to].push_back(Edge((int)list[from].size() - 1, to, from, 0, -cost));
  }
};
COST MinCostFlow(Graph& G, int s, int t, FLOW inif) {
  COST dist[MAX_V];
  int prevv[MAX_V];
  int preve[MAX_V];
  COST res = 0;
  FLOW f = inif;
  while (f > 0) {
    fill(dist, dist + G.V, 1000000000000000007);
    dist[s] = 0;
    while (true) {
      bool update = false;
      for (int v = 0; v < G.V; ++v) {
        if (dist[v] == 1000000000000000007) 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] == 1000000000000000007) return 0;
    FLOW d = f;
    for (int v = t; v != s; v = prevv[v]) {
      d = min(d, G[prevv[v]][preve[v]].cap);
    }
    f -= d;
    res += dist[t] * d;
    for (int v = t; v != s; v = prevv[v]) {
      Edge& e = G[prevv[v]][preve[v]];
      Edge& re = G.redge(e);
      e.cap -= d;
      re.cap += d;
    }
  }
  return res;
}
signed main() {
  int n;
  cin >> n;
  std::vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  Graph out(2 * n + 2);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      out.addedge(i, n + j, 1, -a[i] * abs(i - j));
    }
  }
  for (int i = 0; i < n; i++) {
    out.addedge(n + i, 2 * n + 1, 1, 0);
    out.addedge(2 * n, i, 1, 0);
  }
  cout << -MinCostFlow(out, 2 * n, 2 * n + 1, n) << endl;
  return 0;
}
