#include <bits/stdc++.h>
using namespace std;
const long long N = 100005;
char en = '\n';
long long inf = 1e16;
long long mod = 1e9 + 7;
long long power(long long x, long long n, long long mod) {
  long long res = 1;
  x %= mod;
  while (n) {
    if (n & 1) res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}
long long MAXDIST = 1e17;
struct edge {
  long long to, flow, cap;
  long long cost;
  long long rev;
};
struct MinCostMaxFlow {
  long long nodes;
  vector<long long> curflow, prevedge, prevnode, q;
  vector<long long> pot, prio;
  vector<bool> inqueue;
  vector<vector<edge>> graph;
  MinCostMaxFlow() {}
  MinCostMaxFlow(long long n)
      : nodes(n),
        prio(n, 0),
        curflow(n, 0),
        prevedge(n, 0),
        prevnode(n, 0),
        q(n, 0),
        pot(n, 0),
        inqueue(n, 0),
        graph(n) {}
  void addEdge(long long source, long long to, long long capacity,
               long long cost) {
    edge a = {to, 0, capacity, cost, (long long)graph[to].size()};
    edge b = {source, 0, 0, -cost, (long long)graph[source].size()};
    graph[source].push_back(a);
    graph[to].push_back(b);
  }
  void bellman_ford(long long source, vector<long long> &dist) {
    fill(dist.begin(), dist.end(), MAXDIST);
    dist[source] = 0;
    long long qt = 0;
    q[qt++] = source;
    for (long long qh = 0; (qh - qt) % nodes != 0; qh++) {
      long long u = q[qh % nodes];
      inqueue[u] = false;
      for (auto &e : graph[u]) {
        if (e.flow >= e.cap) continue;
        long long v = e.to;
        long long newDist = dist[u] + e.cost;
        if (dist[v] > newDist) {
          dist[v] = newDist;
          if (!inqueue[v]) {
            inqueue[v] = true;
            q[qt++ % nodes] = v;
          }
        }
      }
    }
  }
  pair<long long, long long> minCostFlow(long long source, long long dest,
                                         long long maxflow) {
    bellman_ford(source, pot);
    long long flow = 0;
    long long flow_cost = 0;
    while (flow < maxflow) {
      priority_queue<pair<long long, long long>,
                     vector<pair<long long, long long>>,
                     greater<pair<long long, long long>>>
          q;
      q.push({0, source});
      fill(prio.begin(), prio.end(), MAXDIST);
      prio[source] = 0;
      curflow[source] = INT_MAX;
      while (!q.empty()) {
        long long d = q.top().first;
        long long u = q.top().second;
        q.pop();
        if (d != prio[u]) continue;
        for (long long i = 0; i < graph[u].size(); i++) {
          edge &e = graph[u][i];
          long long v = e.to;
          if (e.flow >= e.cap) continue;
          long long newPrio = prio[u] + e.cost + pot[u] - pot[v];
          if (prio[v] > newPrio) {
            prio[v] = newPrio;
            q.push({newPrio, v});
            prevnode[v] = u;
            prevedge[v] = i;
            curflow[v] = min(curflow[u], e.cap - e.flow);
          }
        }
      }
      if (prio[dest] == MAXDIST) break;
      for (long long i = 0; i < nodes; i++) pot[i] += prio[i];
      long long df = min(curflow[dest], maxflow - flow);
      flow += df;
      for (long long v = dest; v != source; v = prevnode[v]) {
        edge &e = graph[prevnode[v]][prevedge[v]];
        e.flow += df;
        graph[v][e.rev].flow -= df;
        flow_cost += df * e.cost;
      }
    }
    return {flow, flow_cost};
  }
};
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  long long arr[n + 5];
  for (long long i = 1; i <= n; i++) cin >> arr[i];
  MinCostMaxFlow obj(2 * n + 2);
  long long first1 = 0;
  long long second1 = n;
  long long src = 0;
  long long dest = 2 * n + 1;
  for (long long i = 1; i <= n; i++) {
    obj.addEdge(src, first1 + i, 1, 0);
    obj.addEdge(second1 + i, dest, 1, 0);
    for (long long j = 1; j <= n; j++) {
      obj.addEdge(first1 + i, second1 + j, 1, -abs(i - j) * arr[i]);
    }
  }
  cout << -obj.minCostFlow(src, dest, n + 5).second << en;
  return 0;
}
