#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const long long t = 1e14;
const int maxd = int(1e5) + 11;
const int maxe = int(1e5) + 11;
int tot = 0;
int head[maxd];
int S, T;
struct Edge {
  int from, to, cap;
  long long cost;
  int next;
  Edge() {}
  Edge(int x, int y, int a, long long b, int c)
      : from(x), to(y), cap(a), cost(b), next(c) {}
} eage[maxe * 2];
void add(int x, int y, int a, long long b) {
  eage[tot] = Edge(x, y, a, b, head[x]), head[x] = tot++;
  eage[tot] = Edge(y, x, 0, -b, head[y]), head[y] = tot++;
  return;
}
bool used[maxd], vis[maxd];
long long dis[maxd];
queue<int> que;
long long ans = 0;
bool spfa() {
  for (int i = 0; i < T + 100; i++)
    used[i] = false, dis[i] = INF, vis[i] = false;
  while (que.size()) que.pop();
  que.push(S);
  used[S] = true;
  dis[S] = 0;
  while (que.size()) {
    int u = que.front();
    que.pop();
    used[u] = false;
    for (int i = head[u]; ~i; i = eage[i].next)
      if (eage[i].cap && dis[eage[i].to] > dis[u] + eage[i].cost) {
        int v = eage[i].to;
        dis[v] = dis[u] + eage[i].cost;
        if (!used[v]) {
          used[v] = true;
          que.push(v);
        }
      }
  }
  return (dis[T] < INF);
}
int dfs(int u, int flow) {
  if (u == T) {
    ans += dis[u] * flow;
    return flow;
  }
  vis[u] = true;
  int ret = 0;
  for (int i = head[u]; ~i; i = eage[i].next)
    if (!vis[eage[i].to] && eage[i].cap &&
        dis[eage[i].to] == dis[u] + eage[i].cost) {
      int v = eage[i].to;
      int newf = dfs(v, min(flow, eage[i].cap));
      eage[i].cap -= newf;
      eage[i ^ 1].cap += newf;
      ret += newf;
      flow -= newf;
      if (!flow) break;
    }
  if (!ret) dis[u] = -1;
  return ret;
}
long long MCMF() {
  ans = 0;
  while (spfa()) dfs(S, 1e9);
  return ans;
}
int n;
int main() {
  memset(head, -1, sizeof head);
  scanf("%d", &n);
  S = 2 * n + 1;
  T = 2 * n + 2;
  for (int i = 1; i <= n; i++) add(S, i, 1, 0), add(n + i, T, 1, 0);
  for (int i = 1; i <= n; i++) {
    long long x;
    scanf("%lld", &x);
    for (int j = 1; j <= n; j++) {
      long long now = x * abs(i - j);
      add(i, n + j, 1, -now + t);
    }
  }
  printf("%lld\n", -(MCMF() - 1ll * n * t));
  return 0;
}
