#include <bits/stdc++.h>
using namespace std;
using Vertex = int;
using Flow = long long;
using Cost = long long;
const Flow FLOW_INF = LLONG_MAX;
const Cost COST_INF = LLONG_MAX;
class FlowNetwork {
 public:
  explicit FlowNetwork(int);
  void insert(Vertex, Vertex, Flow, Cost);
  Flow maximum_flow(Vertex, Vertex) const;
  Cost minimum_cost_flow(Vertex, Vertex, Flow) const;

 private:
  struct Edge {
    Vertex from, to;
    Flow capacity;
    Cost cost;
    int rev;
    Edge(Vertex from, Vertex to, Flow capacity, Cost cost, int rev)
        : from(from), to(to), capacity(capacity), cost(cost), rev(rev) {}
  };
  int size_;
  std::vector<std::vector<Edge>> edge_;
};
FlowNetwork::FlowNetwork(int n) : size_(n), edge_(n) {}
void FlowNetwork::insert(Vertex from, Vertex to, Flow capacity = 0,
                         Cost cost = 0) {
  edge_.at(from).emplace_back(from, to, capacity, cost, edge_.at(to).size());
  edge_.at(to).emplace_back(to, from, 0, -cost, edge_.at(from).size() - 1);
}
Flow FlowNetwork::maximum_flow(Vertex source, Vertex sink) const {
  std::vector<int> level;
  std::vector<int> itr;
  auto residue = edge_;
  auto bfs = [&]() {
    level.assign(size_, -1);
    level.at(source) = 0;
    std::queue<int> q;
    q.push(source);
    while (!q.empty()) {
      auto v = q.front();
      q.pop();
      for (const auto& e : residue.at(v))
        if (!~level.at(e.to))
          if (0 < e.capacity) {
            level.at(e.to) = level.at(e.from) + 1;
            q.push(e.to);
          }
    }
    return level.at(sink);
  };
  std::function<Flow(Vertex, Flow)> dfs = [&](Vertex v, Flow cur) {
    if (v == sink) return cur;
    for (auto& i = itr.at(v); i < residue.at(v).size(); ++i) {
      auto& e = residue.at(v).at(i);
      if (level.at(e.from) < level.at(e.to))
        if (0 < e.capacity) {
          auto f = dfs(e.to, std::min(cur, e.capacity));
          if (f == 0) continue;
          e.capacity -= f;
          residue.at(e.to).at(e.rev).capacity += f;
          return f;
        }
    }
    return Flow(0);
  };
  Flow result = 0;
  while (~bfs()) {
    itr.assign(size_, 0);
    while (auto f = dfs(source, FLOW_INF)) result += f;
  }
  return result;
}
Cost FlowNetwork::minimum_cost_flow(Vertex source, Vertex sink, Flow f) const {
  std::vector<Cost> h(size_, 0);
  auto residue = edge_;
  Flow result = 0;
  for (const auto& E : edge_)
    for (const auto& e : E)
      if (0 < e.capacity) h[e.to] = std::min(h[e.to], h[e.from] + e.cost);
  while (0 < f) {
    using Node = std::tuple<Cost, Vertex>;
    std::vector<Cost> dist(size_, COST_INF);
    dist.at(source) = 0;
    std::vector<Edge*> prev(size_, nullptr);
    std::priority_queue<Node, std::vector<Node>, std::greater<Node>> q;
    q.emplace(0, source);
    while (!q.empty()) {
      Cost c;
      Vertex v;
      std::tie(c, v) = q.top();
      q.pop();
      if (dist.at(v) < c) continue;
      for (auto& e : residue.at(v)) {
        if (e.capacity <= 0) continue;
        if (dist.at(e.to) <=
            dist.at(e.from) + e.cost + h.at(e.from) - h.at(e.to))
          continue;
        dist.at(e.to) = dist.at(e.from) + e.cost + h.at(e.from) - h.at(e.to);
        prev.at(e.to) = &e;
        q.emplace(dist.at(e.to), e.to);
      }
    }
    if (dist.at(sink) == COST_INF) return COST_INF;
    for (int v = 0; v < size_; ++v)
      if (dist.at(v) != COST_INF) h.at(v) += dist.at(v);
    Flow add = f;
    for (Vertex v = sink; v != source; v = prev.at(v)->from)
      add = std::min(add, prev.at(v)->capacity);
    f -= add;
    result += add * h.at(sink);
    for (Vertex v = sink; v != source; v = prev.at(v)->from) {
      prev.at(v)->capacity -= add;
      residue.at(prev.at(v)->to).at(prev.at(v)->rev).capacity += add;
    }
  }
  return result;
}
int main() {
  int N;
  cin >> N;
  vector<Cost> A(N);
  for (auto& i : A) cin >> i;
  FlowNetwork G(2 * N + 2);
  const Vertex SOURCE = 2 * N;
  const Vertex SINK = 2 * N + 1;
  for (auto u = 0; u < N; ++u)
    for (auto v = 0; v < N; ++v)
      if (u != v) G.insert(u, N + v, 1, -abs(v - u) * A[u]);
  for (auto v = 0; v < N; ++v) G.insert(SOURCE, v, 1, 0);
  for (auto v = 0; v < N; ++v) G.insert(N + v, SINK, 1, 0);
  cout << -G.minimum_cost_flow(SOURCE, SINK, N) << endl;
}
