#include <bits/stdc++.h>
using namespace std;
class CostScalingMinCostFlow {
  static constexpr double alpha = 2;

 public:
  struct Node {
    long long b;
    double p;
    long long in_f, out_f;
    Node() : b(0), p(0), in_f(0), out_f(0) {}
    Node(long long b, double p) : b(b), p(p), in_f(0), out_f(0) {}
  };
  struct Edge {
    long long from, to;
    long long cap, cost;
    long long rev;
    long long f;
    bool isrev;
    Edge() : from(-1), to(-1), cap(0), cost(0), rev(-1), f(0), isrev(false) {}
    Edge(long long from, long long to, long long cap, long long cost,
         long long rev, long long f, bool isrev)
        : from(from),
          to(to),
          cap(cap),
          cost(cost),
          rev(rev),
          f(f),
          isrev(isrev) {}
  };

 private:
  std::vector<Node> nodes;
  std::vector<std::vector<Edge>> G;
  double epsilon;
  std::queue<long long> active_nodes;
  long long residual_cap(const Edge& e) const {
    if (!e.isrev)
      return e.cap - e.f;
    else
      return G[e.to][e.rev].f;
  }
  double reduced_cost(const Edge& e) const {
    return e.cost + nodes[e.from].p - nodes[e.to].p;
  }
  long long excess(long long i) const {
    return nodes[i].b - nodes[i].out_f + nodes[i].in_f;
  }
  bool is_active(long long i) const { return excess(i) > 0; }
  void push(Edge& edge, long long delta) {
    if (!edge.isrev) {
      edge.f += delta;
      nodes[edge.from].out_f += delta;
      nodes[edge.to].in_f += delta;
    } else {
      G[edge.to][edge.rev].f -= delta;
      nodes[edge.to].out_f -= delta;
      nodes[edge.from].in_f -= delta;
    }
  }
  void relabel(long long v) {
    double mx = std::numeric_limits<double>::lowest();
    for (Edge& edge : G[v]) {
      if (residual_cap(edge) > 0) {
        mx = std::max(mx, nodes[edge.to].p - edge.cost - epsilon);
      }
    }
    nodes[v].p = mx;
  }
  void refine() {
    for (auto& edges : G) {
      for (Edge& edge : edges) {
        if (reduced_cost(edge) >= 0) continue;
        if (residual_cap(edge) <= 0) continue;
        push(edge, residual_cap(edge));
      }
    }
    for (long long i = 0; i < nodes.size(); i++) {
      if (is_active(i)) active_nodes.push(i);
    }
    while (!active_nodes.empty()) {
      long long v = active_nodes.front();
      active_nodes.pop();
      if (!is_active(v)) continue;
      bool is_pushed = false;
      for (Edge& edge : G[v]) {
        if (reduced_cost(edge) >= 0) continue;
        if (residual_cap(edge) <= 0) continue;
        push(edge, std::min(residual_cap(edge), excess(v)));
        if (is_active(edge.from)) active_nodes.push(edge.from);
        if (is_active(edge.to)) active_nodes.push(edge.to);
        is_pushed = true;
        break;
      }
      if (!is_pushed) {
        relabel(v);
        if (is_active(v)) active_nodes.push(v);
      }
    }
  }

 public:
  CostScalingMinCostFlow(long long N) : nodes(N), G(N), epsilon(0) {}
  void add_edge(long long from, long long to, long long cap, long long cost) {
    epsilon = std::max(epsilon, (double)abs(cost));
    G[from].emplace_back(from, to, cap, cost, G[to].size(), 0, false);
    G[to].emplace_back(to, from, cap, -cost, G[from].size() - 1, cap, true);
  }
  void set_b(long long i, long long b) { nodes[i].b = b; }
  long long mincostflow() {
    long long N = nodes.size();
    while (epsilon >= 1.0 / N) {
      epsilon /= alpha;
      refine();
    }
    long long ret = 0;
    for (auto& edges : G) {
      for (Edge& edge : edges) {
        if (edge.isrev) continue;
        ret += edge.cost * edge.f;
      }
    }
    return ret;
  }
};
int main() {
  int N;
  cin >> N;
  vector<long long> v;
  for (int i = (0); i < (int)(N); i++) {
    long long a;
    cin >> a;
    v.push_back(a);
  }
  CostScalingMinCostFlow cs(N + N + 2);
  for (int i = (0); i < (int)(N); i++) {
    cs.add_edge(N + N, i, 1, 0);
  }
  for (int i = (0); i < (int)(N); i++) {
    cs.add_edge(N + i, N + N + 1, 1, 0);
  }
  for (int i = (0); i < (int)(N); i++) {
    for (int j = (0); j < (int)(N); j++) {
      long long s = v[i] * abs(i - j);
      cs.add_edge(i, j + N, 1, -s);
    }
  }
  cs.set_b(N + N, N);
  cs.set_b(N + N + 1, -N);
  cout << -cs.mincostflow() << endl;
  return 0;
}
