#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double EPS = 1e-9;
const long long INF = 1e15 + 10;
const long long mod = 1e9 + 7;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
struct edge {
  int to;
  long long cap, cost;
  int rev;
};
int V;
vector<edge> G[5000];
long long h[5000], dist[5000];
int prevv[5000], preve[5000];
void add_edge(int from, int to, long long cap, long long cost) {
  G[from].push_back((edge){to, cap, cost, (int)G[to].size()});
  G[to].push_back((edge){from, 0, -cost, (int)G[from].size() - 1});
}
int min_cost_flow(int s, int t, long long f) {
  long long res = 0;
  fill(h, h + V, 0);
  while (f > 0) {
    priority_queue<pair<long long, long long>,
                   vector<pair<long long, long long> >,
                   greater<pair<long long, long long> > >
        que;
    fill(dist, dist + V, 1000000);
    dist[s] = 0;
    que.push(pair<long long, long long>(0, s));
    while (!que.empty()) {
      pair<long long, long long> p = que.top();
      que.pop();
      int v = p.second;
      if (dist[v] < p.first) 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 + h[v] - h[e.to]) {
          dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];
          prevv[e.to] = v;
          preve[e.to] = i;
          que.push(pair<long long, long long>(dist[e.to], e.to));
        }
      }
    }
    if (dist[t] == 1000000) {
      return -1;
    }
    for (int v = 0; v < V; v++) h[v] += dist[v];
    long long d = f;
    for (int v = t; v != s; v = prevv[v]) {
      d = min(d, G[prevv[v]][preve[v]].cap);
    }
    f -= d;
    res += d * h[t];
    for (int v = t; v != s; v = prevv[v]) {
      edge &e = G[prevv[v]][preve[v]];
      e.cap -= d;
      G[v][e.rev].cap += d;
    }
  }
  return res;
}
int min_cost_flow2(int s, int t, int f) {
  long long res = 0;
  fill(h, h + V, 0);
  for (int i = 0; i < V; i++) {
    int v;
    if (i == 0) {
      v = s;
    } else if (i == V - 1) {
      v = t;
    } else {
      v = i - 1;
    }
    for (int j = 0; j < G[v].size(); j++) {
      edge &e = G[v][j];
      if (e.cap == 0) continue;
      int u = e.to;
      h[u] = min(h[u], h[v] + e.cost);
    }
  }
  while (f > 0) {
    priority_queue<pair<long long, long long>,
                   vector<pair<long long, long long> >,
                   greater<pair<long long, long long> > >
        que;
    fill(dist, dist + V, 1000000);
    dist[s] = 0;
    que.push(pair<long long, long long>(0, s));
    while (!que.empty()) {
      pair<long long, long long> p = que.top();
      que.pop();
      int v = p.second;
      if (dist[v] < p.first) 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 + h[v] - h[e.to]) {
          dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];
          prevv[e.to] = v;
          preve[e.to] = i;
          que.push(pair<long long, long long>(dist[e.to], e.to));
        }
      }
    }
    if (dist[t] == 1000000) return -1;
    for (int v = 0; v < V; v++) h[v] += dist[v];
    long long d = f;
    for (int v = t; v != s; v = prevv[v]) {
      d = min(d, G[prevv[v]][preve[v]].cap);
    }
    f -= d;
    res += d * h[t];
    for (int v = t; v != s; v = prevv[v]) {
      edge &e = G[prevv[v]][preve[v]];
      e.cap -= d;
      G[v][e.rev].cap += d;
    }
  }
  return res;
}
int main() {
  int N;
  cin >> N;
  V = 2 * N + 2;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  int s = N + N;
  int t = s + 1;
  for (int i = 0; i < N; i++) {
    add_edge(s, i, 1, 0);
    add_edge(N + i, t, 1, 0);
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      add_edge(i, N + j, 1, -A[i] * abs(i - j));
    }
  }
  int ans = min_cost_flow(s, t, N);
  cout << -ans;
  return 0;
}
