#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
using ll = long long;
template <class T>
using V = vector<T>;
const ll inf = (1e18);
const ll mod = 1000000007;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }
struct __INIT {
  __INIT() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
  }
} __init;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const int MAX_V = 11000;
struct Flow {
  struct edge {
    ll to, cap, rev;
  };
  V<edge> G[MAX_V];
  bool used[MAX_V];
  void add(ll from, ll to, ll cap) {
    G[from].push_back((edge){to, cap, (ll)G[to].size()});
    G[to].push_back((edge){from, 0, (ll)G[from].size() - 1});
  }
  ll dfs(ll v, ll t, ll f) {
    if (v == t) return f;
    used[v] = true;
    for (int i = 0; i < G[v].size(); i++) {
      edge &e = G[v][i];
      if (!used[e.to] && e.cap > 0) {
        ll d = dfs(e.to, t, min<ll>(f, e.cap));
        if (d > 0) {
          e.cap -= d;
          G[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }
  ll fmax(ll s, ll t) {
    ll flow = 0;
    while (1) {
      for (int i = 0; i < MAX_V; i++) used[i] = false;
      ll f = dfs(s, t, 10e16);
      if (f == 0) return flow;
      flow += f;
    }
  }
};
const int s = 10000, t = 10001;
int main() {
  int n;
  cin >> n;
  Flow mf;
  V<ll> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mf.add(s, i, 1e16);
    mf.add(i + n, t, 1e16);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      mf.add(i, n + j, a[i] * abs(i - j));
    }
  }
  cout << mf.fmax(s, t) << endl;
}
