#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cout << *it << " = " << a << '\n';
  err(++it, args...);
}
const long long inf = 1e18;
const long long mod = 1e9 + 7;
const long long N = 2e4 + 1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long n, q, sink;
struct edge {
  long long x, y, cap, cost;
};
vector<edge> e;
void createEdge(long long x, long long y, long long cap, long long cost = 0) {
  e.push_back({x, y, cap, cost});
  e.push_back({y, x, 0, -cost});
}
void createGraph(vector<long long>& a) {
  for (long long i = (1); i <= (n); i++) createEdge(1, i + 1, 1, 0);
  for (long long i = (1); i <= (n); i++)
    for (long long j = (1); j <= (n); j++)
      createEdge(i + 1, j + n + 1, 1, -a[i] * abs(i - j));
  for (long long i = (1); i <= (n); i++) createEdge(i + n + 1, sink, 1, 0);
}
void shortest_path(vector<long long>& d, vector<long long>& p) {
  d.assign(sink + 1, inf);
  p.assign(sink + 1, -1);
  d[1] = 0;
  while (true) {
    bool done = 1;
    for (long long j = (0); j <= ((long long)(e.size()) - 1); j++) {
      auto q = e[j];
      if (d[q.x] < inf && q.cap > 0 && d[q.y] > d[q.x] + q.cost) {
        d[q.y] = d[q.x] + q.cost;
        p[q.y] = j;
        done = 0;
      }
    }
    if (done) break;
  }
}
long long max_flow() {
  vector<long long> d, p;
  long long cost = 0;
  while (true) {
    shortest_path(d, p);
    if (d[sink] >= inf) break;
    long long cur = sink;
    cost += d[sink];
    while (cur != 1) {
      e[p[cur]].cap--;
      e[p[cur] ^ 1].cap++;
      cur = e[p[cur]].x;
    }
  }
  return cost;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  sink = 2 * n + 2;
  vector<long long> a(n + 1);
  for (long long i = (1); i <= (n); i++) cin >> a[i];
  createGraph(a);
  cout << -max_flow();
}
